o
    Thu                     @   s   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 dZG dd deZdS )    N)
ModuleSpec)module_from_specspec_from_file_location)Path)
ModuleType)AnyOptionalTuple   )Config)CollectionNotFound)debugc                   @   s^   e Zd ZdZdded ddfddZdedee fd	d
Zddee de	e
ef fddZdS )Loaderzo
    Abstract class defining how to find/import a session's base `.Collection`.

    .. versionadded:: 1.0
    Nconfigr   returnc                 C   s   |du r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    r   @/var/www/html/venv/lib/python3.10/site-packages/invoke/loader.py__init__   s   	
zLoader.__init__namec                 C   s   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   r   r   r   find"   s   zLoader.findc           	      C   s   |du r	| j jj}| |}|rL|jrL|jrLt|j}|j}|}|jr&|j}t|}|t	j
vr6t	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msgr   r   r   load1   s&   



zLoader.loadN)__name__
__module____qualname____doc__r   r   r   r   r   r	   r   r,   r   r   r   r   r      s
    $r   c                       s\   e Zd ZdZddee deddf fddZedefdd	Z	d
edee
 fddZ  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                    s.   t  jdi | |d u r| jjj}|| _d S )Nr   )superr   r   r   search_root_start)r   r3   r4   	__class__r   r   r   p   s   

zFilesystemLoader.__init__c                 C   s   | j pt S r-   )r7   osgetcwd)r   r   r   r   r3   v   s   zFilesystemLoader.startr   c           	   	   C   s$  t d| j d }d|}| jtj}zbttt|d D ]H}tj	|d| }|t
|v r@t|tj	||} n*|t
|v ritjtj	||dritj	||}t|tj	|d|gd} nq!|rvt d| |W S W d S  ttfy   d}t || t|| jd	w )
Nz&FilesystemLoader find starting at {!r}z{}.pyr
   r   z__init__.py)submodule_search_locationszFound module: {!r}z4ImportError loading {!r}, raising CollectionNotFound)r   r3   )r   r#   r3   splitr:   sepreversedrangelenjoinlistdirr   r   existsFileNotFoundErrorModuleNotFoundErrorr   )	r   r   r%   r*   pathsxr   basepathr+   r   r   r   r   {   sB   
zFilesystemLoader.findr-   )r.   r/   r0   r1   r   r   r   r   propertyr3   r   r   __classcell__r   r   r8   r   r2   c   s     r2   )r:   r   importlib.machineryr   importlib.utilr   r   pathlibr   typesr   typingr   r   r	    r   
exceptionsr   utilr   r   r2   r   r   r   r   <module>   s    U