o
    wi&S                     @  sp  d Z ddlmZ ddlZddl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 ddlmZmZ ddlZd	d
lmZ ddlmZ ddlmZ erRddlmZ ejjZd<ddZG dd dZG dd dZ G dd de Z!G dd de!Z"G dd de Z#G dd de"Z$G d d! d!e#Z%d=d&d'Z&G d(d) d)Z'd>d+d,Z(d>d-d.Z)d?d3d4Z*d@d6d7Z+dAd:d;Z,dS )Bu_  Automatic discovery of Python modules and packages (for inclusion in the
distribution) and other config values.

For the purposes of this module, the following nomenclature is used:

- "src-layout": a directory representing a Python project that contains a "src"
  folder. Everything under the "src" folder is meant to be included in the
  distribution when packaging the project. Example::

    .
    ├── tox.ini
    ├── pyproject.toml
    └── src/
        └── mypkg/
            ├── __init__.py
            ├── mymodule.py
            └── my_data_file.txt

- "flat-layout": a Python project that does not use "src-layout" but instead
  have a directory under the project root for each package::

    .
    ├── tox.ini
    ├── pyproject.toml
    └── mypkg/
        ├── __init__.py
        ├── mymodule.py
        └── my_data_file.txt

- "single-module": a project that contains a single Python script direct under
  the project root (no directory used)::

    .
    ├── tox.ini
    ├── pyproject.toml
    └── mymodule.py

    )annotationsN)IterableIteratorMappingfnmatchcase)glob)Path)TYPE_CHECKINGClassVar   )StrPath)log)convert_path)Distributionpathr   returnboolc                 C  s   t j|  S N)osr   basenameisidentifier)r    r   Q/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/setuptools/discovery.py_valid_name?   s   r   c                   @  s.   e Zd ZdZdddZdd
dZdddZdS )_Filterz
    Given a list of patterns, create a callable that will be true only if
    the input matches at least one of the patterns.
    patternsstrr   Nonec                 G  s   t || _d S r   )dictfromkeys	_patterns)selfr   r   r   r   __init__J   s   z_Filter.__init__itemr   c                   s   t  fdd| jD S )Nc                 3  s    | ]}t  |V  qd S r   r   ).0patr$   r   r   	<genexpr>N   s    z#_Filter.__call__.<locals>.<genexpr>)anyr!   r"   r$   r   r'   r   __call__M   s   z_Filter.__call__c                 C  s
   || j v S r   )r!   r*   r   r   r   __contains__P   s   
z_Filter.__contains__N)r   r   r   r   )r$   r   r   r   )__name__
__module____qualname____doc__r#   r+   r,   r   r   r   r   r   D   s
    

r   c                   @  sN   e Zd ZU dZdZded< dZded< e			ddddZedddZ	dS )_Finderz@Base class that exposes functionality for module/package findersr   zClassVar[tuple[str, ...]]ALWAYS_EXCLUDEDEFAULT_EXCLUDE.*wherer   excludeIterable[str]includer   	list[str]c                 C  s8   |p| j }t| tt|tg | j|R  t| S )aZ  Return a list of all Python items (packages or modules, depending on
        the finder implementation) found within directory ``where``.

        ``where`` is the root directory which will be searched.
        It should be supplied as a "cross-platform" (i.e. URL-style) path;
        it will be converted to the appropriate local path syntax.

        ``exclude`` is a sequence of names to exclude; ``*`` can be used
        as a wildcard in the names.
        When finding packages, ``foo.*`` will exclude all subpackages of ``foo``
        (but not ``foo`` itself).

        ``include`` is a sequence of names to include.
        If it's specified, only the named items will be included.
        If it's not specified, all found items will be included.
        ``include`` can contain shell style wildcard patterns just like
        ``exclude``.
        )r3   list
_find_iterr   r   r   r2   clsr7   r8   r:   r   r   r   findZ   s   

z_Finder.findr   Iterator[str]c                 C  s   t r   )NotImplementedErrorr>   r   r   r   r=   }   s   z_Finder._find_iterN)r4   r   r5   )r7   r   r8   r9   r:   r9   r   r;   r7   r   r8   r   r:   r   r   rA   )
r-   r.   r/   r0   r2   __annotations__r3   classmethodr@   r=   r   r   r   r   r1   T   s   
 "r1   c                   @  s0   e Zd ZdZdZedd
dZedddZdS )PackageFinderzI
    Generate a list of all Python packages found within a directory
    )ez_setupz*__pycache__r7   r   r8   r   r:   r   rA   c                 c  s    t jt|ddD ]V\}}}|dd }g |dd< |D ]B}t j||}	t j|	|}
|
t jjd}d|v s?| |	|s@q||rK||sK|V  | d|v sY| d|v rZq|	| qq
dS )zy
        All the packages found in 'where' that pass the 'include' filter, but
        not the 'exclude' filter.
        T)followlinksNr4   r6   .*)
r   walkr   r   joinrelpathreplacesep_looks_like_packageappend)r?   r7   r8   r:   rootdirsfilesall_dirsdir	full_pathrel_pathpackager   r   r   r=      s"   zPackageFinder._find_iterr   _package_namer   r   c                 C  s   t jt j| dS )z%Does a directory look like a package?__init__.py)r   r   isfilerK   )r   rY   r   r   r   rO      s   z!PackageFinder._looks_like_packageNrC   )r   r   rY   r   r   r   )	r-   r.   r/   r0   r2   rE   r=   staticmethodrO   r   r   r   r   rF      s    !rF   c                   @  s   e Zd Zed
ddZd	S )PEP420PackageFinder_pathr   rY   r   r   r   c                 C  s   dS )NTr   )r^   rY   r   r   r   rO      s   z'PEP420PackageFinder._looks_like_packageN)r^   r   rY   r   r   r   )r-   r.   r/   r\   rO   r   r   r   r   r]      s    r]   c                   @  s&   e Zd ZdZedd	d
ZeeZdS )ModuleFinderzYFind isolated Python modules.
    This function will **not** recurse subdirectories.
    r7   r   r8   r   r:   r   rA   c                 c  sX    t tj|dD ]}tjtj|\}}| |sq
||r)||s)|V  q
d S )Nz*.py)r   r   r   rK   splitextr   _looks_like_module)r?   r7   r8   r:   filemodule_extr   r   r   r=      s   
zModuleFinder._find_iterNrC   )	r-   r.   r/   r0   rE   r=   r\   r   ra   r   r   r   r   r_      s
    r_   c                   @  s6   e Zd ZdZeedd eD Z	 edd
dZdS )FlatLayoutPackageFinder)#cibindebiandocdocsdocumentationmanpagesnewsnewsfragments	changelogtesttests	unit_test
unit_testsexampleexamplesscriptstoolsutilutilspythonbuilddistvenvenvrequirementstasksfabfile
site_scons	benchmark
benchmarksexercise	exerciseshtmlcov[._]*c                 c  s    | ]
}|| d fV  qdS )rI   Nr   )r%   pr   r   r   r(      s    z!FlatLayoutPackageFinder.<genexpr>r^   r   package_namer   r   r   c                 C  sB   | d}|d  p|d d}|o tdd |dd  D S )Nr4   r   -stubsc                 s  s    | ]}|  V  qd S r   )r   )r%   namer   r   r   r(     s    z>FlatLayoutPackageFinder._looks_like_package.<locals>.<genexpr>r   )splitr   endswithall)r^   r   namesroot_pkg_is_validr   r   r   rO      s   
z+FlatLayoutPackageFinder._looks_like_packageN)r^   r   r   r   r   r   )	r-   r.   r/   _EXCLUDEtuple
chain_iterr3   r\   rO   r   r   r   r   re      s    )re   c                   @  s   e Zd ZdZdS )FlatLayoutModuleFinder)setupconftestrp   rq   rt   ru   r{   toxfilenoxfilepavementdodor   r   z[Ss][Cc]onstruct	conanfilemanager   r   r   r   r   N)r-   r.   r/   r3   r   r   r   r   r     s    r   root_pkgr   pkg_dirr;   c                   s"   t |} g fdd|D  S )Nc                   s   g | ]	}d   |fqS )r4   )rK   r%   nr   r   r   
<listcomp>'  s    z)_find_packages_within.<locals>.<listcomp>)r]   r@   )r   r   nestedr   r   r   _find_packages_within%  s   
r   c                   @  s   e Zd ZdZd6ddZdd	 Zd
d Zed7ddZed8ddZ		d9d:ddZ
d;ddZd;ddZd<ddZd<d d!Zd<d"d#Zd<d$d%Zd<d&d'Zd=d,d-Zd>d.d/Zd?d1d2Zd?d3d4Zd5S )@ConfigDiscoveryzFill-in metadata and options that can be automatically derived
    (from other metadata/options, the file system or conventions)
    distributionr   r   r   c                 C  s   || _ d| _d| _d| _d S )NF)r|   _called	_disabled_skip_ext_modules)r"   r   r   r   r   r#   /  s   
zConfigDiscovery.__init__c                 C  
   d| _ dS )z+Internal API to disable automatic discoveryTN)r   r"   r   r   r   _disable5  s   
zConfigDiscovery._disablec                 C  r   )a  Internal API to disregard ext_modules.

        Normally auto-discovery would not be triggered if ``ext_modules`` are set
        (this is done for backward compatibility with existing packages relying on
        ``setup.py`` or ``setup.cfg``). However, ``setuptools`` can call this function
        to ignore given ``ext_modules`` and proceed with the auto-discovery if
        ``packages`` and ``py_modules`` are not given (e.g. when using pyproject.toml
        metadata).
        TN)r   r   r   r   r   _ignore_ext_modules9  s   

z#ConfigDiscovery._ignore_ext_modulesr   c                 C  s   | j jptjS r   )r|   src_rootr   curdirr   r   r   r   	_root_dirE  s   zConfigDiscovery._root_dirdict[str, str]c                 C  s   | j jd u ri S | j jS r   )r|   package_dirr   r   r   r   _package_dirJ  s   zConfigDiscovery._package_dirFTforcer   r   ignore_ext_modulesc                 C  s8   |du r| j s
| jrdS | | |r|   d| _ dS )a  Automatically discover missing configuration fields
        and modifies the given ``distribution`` object in-place.

        Note that by default this will only have an effect the first time the
        ``ConfigDiscovery`` object is called.

        To repeatedly invoke automatic discovery (e.g. when the project
        directory changes), please use ``force=True`` (or create a new
        ``ConfigDiscovery`` instance).
        FNT)r   r   _analyse_package_layoutanalyse_name)r"   r   r   r   r   r   r   r+   P  s   

zConfigDiscovery.__call__c                 C  sL   |p| j }| jjdu p| }| jjdup%| jjdup%|p%t| jdo%| jjS )zF``True`` if the user has specified some form of package/module listingNconfiguration)r   r|   ext_modulespackages
py_moduleshasattrr   )r"   r   r   r   r   r   _explicitly_specifiedg  s   

z%ConfigDiscovery._explicitly_specifiedc                 C  s0   |  |rdS td |  p|  p|  S )NTzLNo `packages` or `py_modules` configuration, performing automatic discovery.)r   r   debug_analyse_explicit_layout_analyse_src_layout_analyse_flat_layout)r"   r   r   r   r   r   t  s   
z'ConfigDiscovery._analyse_package_layoutc                   sr   | j  }|dd | j |sdS td|  t fdd| D }t|| j	_
td| j	j
  dS )	zAThe user can explicitly give a package layout via ``package_dir`` NFz(`explicit-layout` detected -- analysing c                 3  s(    | ]\}}t |tj |V  qd S r   )r   r   r   rK   )r%   pkg
parent_dirroot_dirr   r   r(     s
    
z;ConfigDiscovery._analyse_explicit_layout.<locals>.<genexpr>discovered packages -- T)r   copypopr   r   r   r   itemsr<   r|   r   )r"   r   pkgsr   r   r   r     s   
z(ConfigDiscovery._analyse_explicit_layoutc                 C  s   | j }tj| j|dd}tj|sdS td|  |	dtj
| || j_t|| j_t|| j_td| jj  td| jj  dS )a  Try to find all packages or modules under the ``src`` directory
        (or anything pointed by ``package_dir[""]``).

        The "src-layout" is relatively safe for automatic discovery.
        We assume that everything within is meant to be included in the
        distribution.

        If ``package_dir[""]`` is not given, but the ``src`` directory exists,
        this function will set ``package_dir[""] = "src"``.
        r   srcFz#`src-layout` detected -- analysing r   discovered py_modules -- T)r   r   r   rK   r   getisdirr   r   
setdefaultr   r|   r   r]   r@   r   r_   r   )r"   r   src_dirr   r   r   r     s   z#ConfigDiscovery._analyse_src_layoutc                 C  s"   t d| j  |  p|  S )a  Try to find all packages and modules under the project root.

        Since the ``flat-layout`` is more dangerous in terms of accidentally including
        extra files/directories, this function is more conservative and will raise an
        error if multiple packages or modules are found.

        This assumes that multi-package dists are uncommon and refuse to support that
        use case in order to be able to prevent unintended errors.
        z$`flat-layout` detected -- analysing )r   r   r   _analyse_flat_packages_analyse_flat_modulesr   r   r   r   r     s   
z$ConfigDiscovery._analyse_flat_layoutc                 C  sH   t | j| j_tt| jj}td| jj  | 	|d t
|S )Nr   r   )re   r@   r   r|   r   remove_nested_packagesremove_stubsr   r   _ensure_no_accidental_inclusionr   )r"   	top_levelr   r   r   r     s
   z&ConfigDiscovery._analyse_flat_packagesc                 C  s@   t | j| j_td| jj  | | jjd t| jjS )Nr   modules)	r   r@   r   r|   r   r   r   r   r   r   r   r   r   r     s   z%ConfigDiscovery._analyse_flat_modulesdetectedr;   kindr   c                 C  sL   t |dkr$ddlm} ddlm} d| d| d| d}|||d S )	Nr   r   )cleandoc)PackageDiscoveryErrorzMultiple top-level z discovered in a flat-layout: z.

            To avoid accidental inclusion of unwanted files or directories,
            setuptools will not proceed with this build.

            If you are trying to create a single distribution with multiple a  
            on purpose, you should not rely on automatic discovery.
            Instead, consider the following options:

            1. set up custom discovery (`find` directive with `include` or `exclude`)
            2. use a `src-layout`
            3. explicitly set `py_modules` or `packages` with a list of names

            To find more information, look for "package discovery" on setuptools docs.
            )leninspectr   setuptools.errorsr   )r"   r   r   r   r   msgr   r   r   r     s   z/ConfigDiscovery._ensure_no_accidental_inclusionc                 C  sF   | j jjs	| j jrdS td |  p|  }|r!|| j j_dS dS )zThe packages/modules are the essential contribution of the author.
        Therefore the name of the distribution can be derived from them.
        Nz7No `name` configuration, performing automatic discovery)r|   metadatar   r   r   #_find_name_single_package_or_module_find_name_from_packages)r"   r   r   r   r   r     s   
zConfigDiscovery.analyse_name
str | Nonec                 C  sP   dD ]#}t | j|dpg }|r%t|dkr%td|d   |d   S qdS )zExactly one module or package)r   r   Nr   z&Single module/package detected, name: r   )getattrr|   r   r   r   )r"   fieldr   r   r   r   r     s   z3ConfigDiscovery._find_name_single_package_or_modulec                 C  s`   | j jsdS tt| j jtd}| j jpi }t||| j}|r)t	d|  |S t
d dS )z<Try to find the root package that is not a PEP 420 namespaceNkeyz&Common parent package detected, name: z7No parent package detected, impossible to derive `name`)r|   r   r   sortedr   r   find_parent_packager   r   r   warn)r"   r   r   
parent_pkgr   r   r   r     s   
z(ConfigDiscovery._find_name_from_packagesN)r   r   r   r   )r   r   )r   r   )FTF)r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   )r   r;   r   r   )r   r   )r   r   )r-   r.   r/   r0   r#   r   r   propertyr   r   r+   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   *  s,    











r   r   c                   sb   t | td}|dd }t|}tt|D ]\} t fdd|D r.||| d  q|S )zRemove nested packages from a list of packages.

    >>> remove_nested_packages(["a", "a.b1", "a.b2", "a.b1.c1"])
    ['a']
    >>> remove_nested_packages(["a", "b", "c.d", "c.d.e.f", "g.h", "a.a1"])
    ['a', 'b', 'c.d', 'g.h']
    r   Nc                 3  s     | ]}  | d V  qdS r4   N
startswith)r%   otherr   r   r   r(         z)remove_nested_packages.<locals>.<genexpr>r   )r   r   	enumeratereversedr)   r   )r   r   r   sizeir   r   r   r     s   r   c                 C  s   dd | D S )zRemove type stubs (:pep:`561`) from a list of packages.

    >>> remove_stubs(["a", "a.b", "a-stubs", "a-stubs.b.c", "b", "c-stubs"])
    ['a', 'a.b', 'b']
    c                 S  s$   g | ]}| d d ds|qS )r4   r   r   )r   r   r%   r   r   r   r   r   &  s   $ z remove_stubs.<locals>.<listcomp>r   )r   r   r   r   r      s   r   r   Mapping[str, str]r   r   c                   s   t | td} g }t| D ]\} t fdd| |d d D s# n|  q|D ] t ||}tj|d}tj	|rD   S q+dS )z0Find the parent package that is not a namespace.r   c                 3  s     | ]}|   d V  qdS r   r   r   r   r   r   r(   0  r   z&find_parent_package.<locals>.<genexpr>r   NrZ   )
r   r   r   r   rP   find_package_pathr   r   rK   r[   )r   r   r   common_ancestorsr   pkg_pathinitr   r   r   r   )  s   "r   r   c                 C  s   |  d}tt|ddD ]$}d|d| }||v r1|| }tjj||g||d R    S q|dp8d}tjj|g| d|R  S )a  Given a package name, return the path where it should be found on
    disk, considering the ``package_dir`` option.

    >>> path = find_package_path("my.pkg", {"": "root/is/nested"}, ".")
    >>> path.replace(os.sep, "/")
    './root/is/nested/my/pkg'

    >>> path = find_package_path("my.pkg", {"my": "root/is/nested"}, ".")
    >>> path.replace(os.sep, "/")
    './root/is/nested/pkg'

    >>> path = find_package_path("my.pkg", {"my.pkg": "root/is/nested"}, ".")
    >>> path.replace(os.sep, "/")
    './root/is/nested'

    >>> path = find_package_path("other.pkg", {"my.pkg": "root/is/nested"}, ".")
    >>> path.replace(os.sep, "/")
    './other/pkg'
    r4   r   Nr   /)r   ranger   rK   r   r   r   )r   r   r   partsr   partial_nameparentr   r   r   r   A  s   
"r   package_pathr   c                   s$   t | }t|j  fdd|D S )Nc              	     s&   i | ]}|d  g  |dqS )r   r4   )rK   r   r   prefixr   r   
<dictcomp>f  s   & z)construct_package_dir.<locals>.<dictcomp>)r   r	   r  )r   r  parent_pkgsr   r  r   construct_package_dirc  s   
r
  )r   r   r   r   )r   r   r   r   r   r;   )r   r;   r   r;   )r   r;   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r;   r  r   r   r   )-r0   
__future__r   	itertoolsr   collections.abcr   r   r   fnmatchr   r   pathlibr	   typingr
   r   _distutils_hack.override_distutils_hackr^   r   	distutilsr   distutils.utilr   
setuptoolsr   chainfrom_iterabler   r   r   r1   rF   r]   r_   re   r   r   r   r   r   r   r   r
  r   r   r   r   <module>   s@    '
0/5
 
e

	
"