
    Mh"                         d dl mZmZmZmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZ erddlmZ ddlmZ dd	l
mZ  G d
 d      Zy)    )TYPE_CHECKINGAnyDictListOptionalTupleUnion   )Config)ParserContext)debug)CallTask)
Collection)Result)ParseResultc            	           e Zd ZdZ	 	 dddded   ded   d	dfd
Zdeeeee	ee
f   f   ef   d	e	d   fdZdeeeeee	ee
f   f   ef   df   d	ed   fdZded   d	ed   fdZded   d	ed   fdZy)Executorz
    An execution strategy for Task objects.

    Subclasses may override various extension points to change, add or remove
    behavior.

    .. versionadded:: 1.0
    N
collectionr   configr   corer   returnc                 F    || _         ||n	t               | _        || _        y)a  
        Initialize executor with handles to necessary data structures.

        :param collection:
            A `.Collection` used to look up requested tasks (and their default
            config data, if any) by name during execution.

        :param config:
            An optional `.Config` holding configuration state. Defaults to an
            empty `.Config` if not given.

        :param core:
            An optional `.ParseResult` holding parsed core program arguments.
            Defaults to ``None``.
        N)r   r   r   r   )selfr   r   r   s       g/var/www/pru.catia.catastroantioquia-mas.com/valormasv2/lib/python3.12/site-packages/invoke/executor.py__init__zExecutor.__init__   s"    * % & 2f	    tasks)r   r   c                 T   t        dj                  |D cg c]  }| c}             | j                  |      }t        dj                  |             t        |      }| j	                  |      }	 | j
                  j                  j                  }|r| j                  |      n|}i }|D ]  }||v xr |j                  }	t        dj                  |             | j
                  }
| j                  j                  |j                        }|
j                  |       |
j                          t        d       |j                  |
      }|g|j                   } |j"                  |i |j$                  }|	rt'        |       |||j"                  <    |S c c}w # t        $ r d}Y w xY w)a  
        Execute one or more ``tasks`` in sequence.

        :param tasks:
            An all-purpose iterable of "tasks to execute", each member of which
            may take one of the following forms:

            **A string** naming a task from the Executor's `.Collection`. This
            name may contain dotted syntax appropriate for calling namespaced
            tasks, e.g. ``subcollection.taskname``. Such tasks are executed
            without arguments.

            **A two-tuple** whose first element is a task name string (as
            above) and whose second element is a dict suitable for use as
            ``**kwargs`` when calling the named task. E.g.::

                [
                    ('task1', {}),
                    ('task2', {'arg1': 'val1'}),
                    ...
                ]

            is equivalent, roughly, to::

                task1()
                task2(arg1='val1')

            **A `.ParserContext`** instance, whose ``.name`` attribute is used
            as the task name and whose ``.as_kwargs`` attribute is used as the
            task kwargs (again following the above specifications).

            .. note::
                When called without any arguments at all (i.e. when ``*tasks``
                is empty), the default task from ``self.collection`` is used
                instead, if defined.

        :returns:
            A dict mapping task objects to their return values.

            This dict may include pre- and post-tasks if any were executed. For
            example, in a collection with a ``build`` task depending on another
            task named ``setup``, executing ``build`` will result in a dict
            with two keys, one for ``build`` and one for ``setup``.

        .. versionadded:: 1.0
        zExamining top level tasks {!r}z#Tasks (now Calls) with kwargs: {!r}TzExecuting {!r}z/Finished loading collection & shell env configs)r   format	normalizelistexpand_callsr   r   dedupeAttributeError	autoprintr   configuration	called_asload_collectionload_shell_envmake_contextargstaskkwargsprint)r   r   xcallsdirectexpandedr$   resultscallr&   r   collection_configcontextr,   results                  r   executezExecutor.execute1   s   d 	.55%6HQq6HIJu%3::5AB e $$U+	[[&&--F *0H%X  	(D94>>I"))$/0 [[F
 !% = =dnn M""#45!!#CD ''/G(dii(DTYY44Ff "(GDII1	(2 _ 7I  	F	s   	F1 F F'&F'.r   c                    g }|D ]q  }t        |t              r|}i }n.t        |t              r|j                  }|j                  }n|\  }}t        | j                  |   ||      }|j                  |       s |sC| j                  j                  -t        | j                  | j                  j                           g}|S )z
        Transform arbitrary task list w/ various types, into `.Call` objects.

        See docstring for `~.Executor.execute` for details.

        .. versionadded:: 1.0
        )r.   r(   )	
isinstancestrr   name	as_kwargsr   r   appenddefault)r   r   r1   r-   r=   r.   cs          r   r!   zExecutor.normalize   s      	D$$D-0yy#fT__T*6TJALLO	 00<$//$//*A*ABCDEr   r1   c                     g }t        d       |D ]L  }||vr,t        dj                  |             |j                  |       3t        dj                  |             N |S )z
        Deduplicate a list of `tasks <.Call>`.

        :param calls: An iterable of `.Call` objects representing tasks.

        :returns: A list of `.Call` objects.

        .. versionadded:: 1.0
        zDeduplicating tasks...z{!r}: no duplicates found, okz%{!r}: found in list already, skipping)r   r    r?   )r   r1   dedupedr5   s       r   r$   zExecutor.dedupe   sf     &' 	LD7"5<<TBCt$=DDTJK	L r   c                 L   g }|D ]  }t        |t              rt        |      }t        dj	                  |             |j                  | j                  |j                               |j                  |       |j                  | j                  |j                                |S )a  
        Expand a list of `.Call` objects into a near-final list of same.

        The default implementation of this method simply adds a task's
        pre/post-task list before/after the task itself, as necessary.

        Subclasses may wish to do other things in addition (or instead of) the
        above, such as multiplying the `calls <.Call>` by argument vectors or
        similar.

        .. versionadded:: 1.0
        zExpanding task-call {!r})
r;   r   r   r   r    extendr#   prer?   post)r   r1   retr5   s       r   r#   zExecutor.expand_calls   s      	5D $%Dz,33D9: JJt((23JJtJJt((34!	5" 
r   )NN)__name__
__module____qualname____doc__r   r   r	   r<   r   r   r   r   r9   r   r!   r$   r#    r   r   r   r      s     &*(,	  " }%	
 
2aCsDcN':!;]JKa		aF#uS$sCx.01=@A3F

 
f<DL T&\ ($v, 4< r   r   N)typingr   r   r   r   r   r   r	   r   r   parserr   utilr   r   r   r   r   r   runnersr   r   r   rM   r   r   <module>rR      s2    I I I  !  &#W Wr   