
    Riu                         d dl Z d dlZd dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZmZ ddlmZ dd	lmZ dd
lmZ  G d d          Z G d de          ZdS )    N)
ModuleSpec)module_from_specspec_from_file_location)Path)
ModuleType)AnyOptionalTuple   )Config)CollectionNotFound)debugc                   z    e Zd ZdZd
ded         ddfdZdedee         fdZd
dee         de	e
ef         fd	ZdS )Loaderzo
    Abstract class defining how to find/import a session's base `.Collection`.

    .. versionadded:: 1.0
    Nconfigr   returnc                 4    |t                      }|| _        dS )a  
        Set up a new loader with some `.Config`.

        :param config:
            An explicit `.Config` to use; it is referenced for loading-related
            config options. Defaults to an anonymous ``Config()`` if none is
            given.
        N)r   r   )selfr   s     E/srv/django_bis/venv311/lib/python3.11/site-packages/invoke/loader.py__init__zLoader.__init__   s     >XXF    namec                     t           )a  
        Implementation-specific finder method seeking collection ``name``.

        Must return a ModuleSpec valid for use by `importlib`, which is
        typically a name string followed by the contents of the 3-tuple
        returned by `importlib.module_from_spec` (``name``, ``loader``,
        ``origin``.)

        For a sample implementation, see `.FilesystemLoader`.

        .. versionadded:: 1.0
        )NotImplementedError)r   r   s     r   findzLoader.find"   s
     "!r   c                 4   || j         j        j        }|                     |          }|r|j        r|j        rt          |j                  }|j        }|}|j        r|j        }t          |          }|t          j
        vr t          j
                            d|           t          |          }|t          j        |j        <   |j                            |           |t          |          fS d}t!          |                    |                     t$          )a  
        Load and return collection module identified by ``name``.

        This method requires a working implementation of `.find` in order to
        function.

        In addition to importing the named module, it will add the module's
        parent directory to the front of `sys.path` to provide normal Python
        import behavior (i.e. so the loaded module may load local-to-it modules
        or packages.)

        :returns:
            Two-tuple of ``(module, directory)`` where ``module`` is the
            collection-containing Python module object, and ``directory`` is
            the string path to the directory the module was found in.

        .. versionadded:: 1.0
        Nr   z-ImportError loading {!r}, raising ImportError)r   taskscollection_namer   loaderoriginr   parentstrsyspathinsertr   modulesr   exec_moduler   formatImportError)	r   r   specsource_fileenclosing_dirmodule_parentenclosing_strmodulemsgs	            r   loadzLoader.load1   s
   & <;$4Dyy 	.DK 	.DK 	.t{++K (.M
 *M{ 5 - 4..MCH,,=111%d++F%+CK	"K##F+++3}----=cjjr   N)__name__
__module____qualname____doc__r	   r   r"   r   r   r
   r   r1    r   r   r   r      s          x1 T    " "*!5 " " " "/ /# /%
C2H / / / / / /r   r   c                   v     e Zd ZdZd
dee         deddf fdZedefd            Z	dedee
         fd	Z xZS )FilesystemLoaderz
    Loads Python files from the filesystem (e.g. ``tasks.py``.)

    Searches recursively towards filesystem root from a given start point.

    .. versionadded:: 1.0
    Nstartkwargsr   c                 n     t                      j        di | || j        j        j        }|| _        d S )Nr7   )superr   r   r   search_root_start)r   r:   r;   	__class__s      r   r   zFilesystemLoader.__init__p   s=    ""6"""=K%1Er   c                 6    | j         pt          j                    S r2   )r?   osgetcwd)r   s    r   r:   zFilesystemLoader.startv   s     {)bikk)r   r   c                 B   t          d                    | j                             d }d                    |          }| j                            t          j                  }	 t          t          t          |          dz                       D ]}t          j        	                    |d|                   }|t	          j
        |          v r0t          |t          j        	                    ||                    } n|t	          j
        |          v rt          j                            t          j        	                    ||d                    rSt          j        	                    ||          }t          |t          j        	                    |d          |g          } n|r$t          d                    |                     |S nO# t          t          f$ r; d}t          |                    |                     t!          || j        	          w xY wd S )
Nz&FilesystemLoader find starting at {!r}z{}.pyr   r   z__init__.py)submodule_search_locationszFound module: {!r}z4ImportError loading {!r}, raising CollectionNotFound)r   r:   )r   r(   r:   splitrB   sepreversedrangelenjoinlistdirr   r$   existsFileNotFoundErrorModuleNotFoundErrorr   )	r   r   r*   r/   pathsxr$   basepathr0   s	            r   r   zFilesystemLoader.find{   s   6==djIIJJJ%%
  ((	BeCJJN3344  v{{51:..RZ----2bgll488 D ERZ----"'..GLLt];;3 3-  "w||D$77H2X}==4<:  D
 E *11$77888 "#67 	B 	B 	BHC#**T""###$$djAAAA	B ts   $E*G AHr2   )r3   r4   r5   r6   r	   r"   r   r   propertyr:   r   r   __classcell__)r@   s   @r   r9   r9   c   s          hsm c d       *s * * * X* *!5        r   r9   )rB   r#   importlib.machineryr   importlib.utilr   r   pathlibr   typesr   typingr   r	   r
    r   
exceptionsr   utilr   r   r9   r7   r   r   <module>r]      s   				 



 * * * * * * D D D D D D D D             ' ' ' ' ' ' ' ' ' '       * * * * * *      R R R R R R R Rj7 7 7 7 7v 7 7 7 7 7r   