
    Ri"                         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dS )    )TYPE_CHECKINGAnyDictListOptionalTupleUnion   )Config)ParserContext)debug)CallTask)
Collection)Result)ParseResultc            	       D   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dS )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                 P    || _         ||nt                      | _        || _        dS )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/srv/django_bis/venv311/lib/python3.11/site-packages/invoke/executor.py__init__zExecutor.__init__   s*    * % & 2ff			    tasks)r   r   c                 N   t          d                    d |D                                  |                     |          }t          d                    |                     t          |          }|                     |          }	 | j        j        j        }n# t          $ r d}Y nw xY w|r|                     |          n|}i }|D ]}||v o|j	        }t          d                    |                     | j        }	| j
                            |j                  }
|	                    |
           |	                                 t          d           |                    |	          }|g|j        R } |j        |i |j        }|rt'          |           |||j        <   |S )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}c                     g | ]}|S  r!   ).0xs     r   
<listcomp>z$Executor.execute.<locals>.<listcomp>c   s    6H6H6HQq6H6H6Hr   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   callsdirectexpandedr)   resultscallr+   r   collection_configcontextr1   results                 r   executezExecutor.execute1   s   d 	.556H6H%6H6H6HIIJJJu%%3::5AABBB e $$U++	[&-FF 	 	 	FFF	 *0=H%%%X  	( 	(D94>I"))$//000 [F
 !% = =dn M M""#4555!!###CDDD ''//G(di((DTY444F f "(GDIs   	B B*)B*.r   c                 d   g }|D ]w}t          |t                    r|}i }n)t          |t                    r|j        }|j        }n|\  }}t          | j        |         ||          }|                    |           x|s1| 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
        )r3   r-   )	
isinstancestrr   name	as_kwargsr   r   appenddefault)r   r   r5   r2   rA   r3   cs          r   r&   zExecutor.normalize   s      	 	D$$$ $D-00 $y#fT_T*6TJJJALLOOOO 	E0<$/$/*ABCCDEr   r5   c                     g }t          d           |D ]`}||vr8t          d                    |                     |                    |           >t          d                    |                     a|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%   rC   )r   r5   dedupedr9   s       r   r)   zExecutor.dedupe   s     &''' 	L 	LD7""5<<TBBCCCt$$$$=DDTJJKKKKr   c                 ~   g }|D ]}t          |t                    rt          |          }t          d                    |                     |                    |                     |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(   prerC   post)r   r5   retr9   s       r   r(   zExecutor.expand_calls   s      	5 	5D $%% "Dzz,33D99::: JJt((22333JJtJJt((334444
r   )NN)__name__
__module____qualname____doc__r   r   r	   r@   r   r   r   r   r=   r   r&   r)   r(   r!   r   r   r   r      sg         &*(,	   " }%	
 
   2aCsDcN':!;]JKa		a a 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   r!   r   r   <module>rU      s   I I I I I I I I I I I I I I I I I I       ! ! ! ! ! !               $&&&&&&######W W W W W W W W W Wr   