HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/setuptools/__pycache__/discovery.cpython-310.pyc
o

;j&S�@spdZddlmZddlZddlZddlmZmZmZddl	m
Z
ddlmZddlm
Z
ddlmZmZddlZd	d
lmZddlmZddlmZerRdd
lmZejjZd<dd�ZGdd�d�ZGdd�d�Z Gdd�de �Z!Gdd�de!�Z"Gdd�de �Z#Gdd�de"�Z$Gd d!�d!e#�Z%d=d&d'�Z&Gd(d)�d)�Z'd>d+d,�Z(d>d-d.�Z)d?d3d4�Z*d@d6d7�Z+dAd:d;�Z,dS)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�boolcCstj�|���S�N)�osr�basename�isidentifier)r�r�H/opt/saltstack/salt/lib/python3.10/site-packages/setuptools/discovery.py�_valid_name?src@s.eZdZdZddd�Zdd
d�Zddd
�ZdS)�_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�NonecGst�|�|_dSr)�dict�fromkeys�	_patterns)�selfrrrr�__init__Jsz_Filter.__init__�itemrcst�fdd�|jD��S)Nc3s�|]}t�|�VqdSrr)�.0�pat�r$rr�	<genexpr>Ns�z#_Filter.__call__.<locals>.<genexpr>)�anyr!�r"r$rr'r�__call__Msz_Filter.__call__cCs
||jvSr)r!r*rrr�__contains__Ps
z_Filter.__contains__N)rrrr)r$rrr)�__name__�
__module__�__qualname__�__doc__r#r+r,rrrrrDs


rc@sNeZdZUdZdZded<dZded<e			dddd��Zeddd��Z	dS)�_Finderz@Base class that exposes functionality for module/package findersrzClassVar[tuple[str, ...]]�ALWAYS_EXCLUDE�DEFAULT_EXCLUDE�.��*�wherer
�exclude�
Iterable[str]�includer�	list[str]cCs8|p|j}t|�tt|��tg|j�|�R�t|���S)aZReturn 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_iterrrrr2��clsr7r8r:rrr�findZs

��z_Finder.findr�
Iterator[str]cCst�r)�NotImplementedErrorr>rrrr=}sz_Finder._find_iterN)r4rr5)r7r
r8r9r:r9rr;�r7r
r8rr:rrrA)
r-r.r/r0r2�__annotations__r3�classmethodr@r=rrrrr1Ts
�"r1c@s0eZdZdZdZedd
d��Zeddd��ZdS)�
PackageFinderzI
    Generate a list of all Python packages found within a directory
    )Zez_setupz*__pycache__r7r
r8rr:rrAccs��tjt|�dd�D]V\}}}|dd�}g|dd�<|D]B}tj�||�}	tj�|	|�}
|
�tjjd�}d|vs?|�|	|�s@q||�rK||�sK|V|�d�|vsY|�d�|vrZq|�	|�qq
dS)zy
        All the packages found in 'where' that pass the 'include' filter, but
        not the 'exclude' filter.
        T)�followlinksNr4r6�.*)
r�walkrr�join�relpath�replace�sep�_looks_like_package�append)r?r7r8r:�root�dirs�filesZall_dirs�dir�	full_path�rel_path�packagerrrr=�s"���zPackageFinder._find_iterr�
_package_namerrcCstj�tj�|d��S)z%Does a directory look like a package?�__init__.py)rr�isfilerJ)rrWrrrrN�sz!PackageFinder._looks_like_packageNrC)rr
rWrrr)	r-r.r/r0r2rEr=�staticmethodrNrrrrrF�s!rFc@seZdZed
dd��Zd	S)�PEP420PackageFinder�_pathr
rWrrrcCsdS)NTr)r\rWrrrrN�sz'PEP420PackageFinder._looks_like_packageN)r\r
rWrrr)r-r.r/rZrNrrrrr[�sr[c@s&eZdZdZedd	d
��Zee�ZdS)
�ModuleFinderzYFind isolated Python modules.
    This function will **not** recurse subdirectories.
    r7r
r8rr:rrAccsX�ttj�|d��D]}tj�tj�|��\}}|�|�sq
||�r)||�s)|Vq
dS)Nz*.py)rrrrJ�splitextr�_looks_like_module)r?r7r8r:�file�moduleZ_extrrrr=�s�
��zModuleFinder._find_iterNrC)	r-r.r/r0rEr=rZrr_rrrrr]�s
r]c@s6eZdZdZeedd�eD���Z	ed
d
d��ZdS)�FlatLayoutPackageFinder)#Zci�binZdebian�docZdocsZ
documentationZmanpages�newsZ
newsfragmentsZ	changelog�test�testsZ	unit_testZ
unit_tests�example�examples�scriptsZtools�util�utils�python�build�dist�venv�envZrequirements�tasks�fabfileZ
site_scons�	benchmark�
benchmarks�exercise�	exercisesZhtmlcov�[._]*ccs�|]
}||�d�fVqdS)rHNr)r%�prrrr(�s�z!FlatLayoutPackageFinder.<genexpr>r\r
�package_namerrrcCsB|�d�}|d��p|d�d�}|o tdd�|dd�D��S)Nr4r�-stubscss�|]}|��VqdSr)r)r%�namerrrr(s�z>FlatLayoutPackageFinder._looks_like_package.<locals>.<genexpr>r)�splitr�endswith�all)r\rz�namesZroot_pkg_is_validrrrrN�s
z+FlatLayoutPackageFinder._looks_like_packageN)r\r
rzrrr)	r-r.r/Z_EXCLUDE�tuple�
chain_iterr3rZrNrrrrrb�s)rbc@seZdZdZdS)�FlatLayoutModuleFinder)�setupZconftestrfrgrhrirnZtoxfileZnoxfileZpavementZdodorrrsz[Ss][Cc]onstructZ	conanfileZmanagertrurvrwrxN)r-r.r/r3rrrrr�sr��root_pkgr�pkg_dirr;cs"t�|�}�g�fdd�|D�S)Ncsg|]	}d��|f��qS)r4)rJ�r%�n�r�rr�
<listcomp>'sz)_find_packages_within.<locals>.<listcomp>)r[r@)r�r��nestedrr�r�_find_packages_within%s
r�c@s�eZdZdZd6dd�Zdd	�Zd
d�Zed7d
d��Zed8dd��Z		d9d:dd�Z
d;dd�Zd;dd�Zd<dd�Z
d<d d!�Zd<d"d#�Zd<d$d%�Zd<d&d'�Zd=d,d-�Zd>d.d/�Zd?d1d2�Zd?d3d4�Zd5S)@�ConfigDiscoveryz�Fill-in metadata and options that can be automatically derived
    (from other metadata/options, the file system or conventions)
    �distributionrrrcCs||_d|_d|_d|_dS)NF)ro�_called�	_disabled�_skip_ext_modules)r"r�rrrr#/s
zConfigDiscovery.__init__cC�
d|_dS)z+Internal API to disable automatic discoveryTN)r��r"rrr�_disable5s
zConfigDiscovery._disablecCr�)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�rrr�_ignore_ext_modules9s

z#ConfigDiscovery._ignore_ext_modulesr
cCs|jjptjSr)roZsrc_rootr�curdirr�rrr�	_root_dirEszConfigDiscovery._root_dir�dict[str, str]cCs|jjduriS|jjSr)ro�package_dirr�rrr�_package_dirJszConfigDiscovery._package_dirFT�forcerr|�ignore_ext_modulescCs8|dur|js
|jrdS|�|�|r|��d|_dS)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�rrrr+Ps


zConfigDiscovery.__call__cCsL|p|j}|jjdup|}|jjdup%|jjdup%|p%t|jd�o%|jjS)zF``True`` if the user has specified some form of package/module listingN�
configuration)r�ro�ext_modules�packages�
py_modules�hasattrr�)r"r�r�rrr�_explicitly_specifiedgs

���z%ConfigDiscovery._explicitly_specifiedcCs0|�|�rdSt�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�rrrr�ts
���z'ConfigDiscovery._analyse_package_layoutcsr|j��}|�dd�|j�|sdSt�d|���t�fdd�|��D��}t|�|j	_
t�d|j	j
���dS)	zAThe user can explicitly give a package layout via ``package_dir``�NFz(`explicit-layout` detected -- analysing c3s(�|]\}}t|tj��|��VqdSr)r�rrrJ)r%�pkgZ
parent_dir��root_dirrrr(�s
��
�z;ConfigDiscovery._analyse_explicit_layout.<locals>.<genexpr>�discovered packages -- T)r��copy�popr�rr�r��itemsr<ror�)r"r��pkgsrr�rr��s
�z(ConfigDiscovery._analyse_explicit_layoutcCs�|j}tj�|j|�dd��}tj�|�sdSt�d|���|�	dtj�
|��||j_t
�|�|j_t�|�|j_t�d|jj���t�d|jj���dS)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�rrrJr��get�isdirrr��
setdefaultrror�r[r@r�r]r�)r"r�Zsrc_dirrrrr��sz#ConfigDiscovery._analyse_src_layoutcCs"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 )rr�r��_analyse_flat_packages�_analyse_flat_modulesr�rrrr��s
z$ConfigDiscovery._analyse_flat_layoutcCsHt�|j�|j_tt|jj��}t�d|jj���|�	|d�t
|�S)Nr�r�)rbr@r�ror��remove_nested_packages�remove_stubsrr��_ensure_no_accidental_inclusionr)r"�	top_levelrrrr��s
z&ConfigDiscovery._analyse_flat_packagescCs@t�|j�|j_t�d|jj���|�|jjd�t|jj�S)Nr��modules)	r�r@r�ror�rr�r�rr�rrrr��sz%ConfigDiscovery._analyse_flat_modules�detectedr;�kindrcCsLt|�dkr$ddlm}ddlm}d|�d|�d|�d�}|||���dS)	Nrr)�cleandoc)�PackageDiscoveryErrorzMultiple 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�Zsetuptools.errorsr�)r"r�r�r�r��msgrrrr��s��z/ConfigDiscovery._ensure_no_accidental_inclusioncCsF|jjjs	|jjrdSt�d�|��p|��}|r!||jj_dSdS)z�The 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)ro�metadatar|rr��#_find_name_single_package_or_module�_find_name_from_packages)r"r|rrrr��s
��zConfigDiscovery.analyse_name�
str | NonecCsPdD]#}t|j|d�pg}|r%t|�dkr%t�d|d���|dSqdS)zExactly one module or package)r�r�Nrz&Single module/package detected, name: r)�getattrror�rr�)r"�fieldr�rrrr��s�z3ConfigDiscovery._find_name_single_package_or_modulecCs`|jjsdStt|jjtd��}|jjpi}t|||j�}|r)t�	d|���|St�
d�dS)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`)ror�r��sortedr�r��find_parent_packager�rr��warn)r"r�r�Z
parent_pkgrrrr��s
z(ConfigDiscovery._find_name_from_packagesN)r�rrr)rr
)rr�)FTF)r�rr|rr�rrr)r�rrr)rr)r�r;r�r)rr)rr�)r-r.r/r0r#r�r��propertyr�r�r+r�r�r�r�r�r�r�r�r�r�r�rrrrr�*s,
�










r�r�csbt|td�}|dd�}t|�}tt|��D]\}�t�fdd�|D��r.|�||d�q|S)z�Remove 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�Nc3s �|]}��|�d��VqdS�r4N��
startswith)r%�other�r|rrr(��z)remove_nested_packages.<locals>.<genexpr>r)r�r��	enumerate�reversedr)r�)r�r�r��size�irr�rr�s�r�cCsdd�|D�S)z�Remove 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']
    cSs$g|]}|�d�d�d�s|�qS)r4rr{)r}r~�r%r�rrrr�&s$z remove_stubs.<locals>.<listcomp>r)r�rrrr� sr�r��Mapping[str, str]r�r�cs�t|td�}g}t|�D]\}�t�fdd�||dd�D��s#n|���q|D]�t�||�}tj�|d�}tj�	|�rD�Sq+dS)z0Find the parent package that is not a namespace.r�c3s �|]}|���d��VqdSr�r�r�r�rrr(0r�z&find_parent_package.<locals>.<genexpr>rNrX)
r�r�r�rrO�find_package_pathrrrJrY)r�r�r�Zcommon_ancestorsr�Zpkg_path�initrr�rr�)s"�r�r|cCs�|�d�}tt|�dd�D]$}d�|d|��}||vr1||}tjj||g||d��R�Sq
|�d�p8d}tjj|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'
    r4r���Nr��/)r}�ranger�rJrrr�)r|r�r��partsr�Zpartial_name�parentrrrr�As
"�r��package_pathr�cs$t|�}t|�j��fdd�|D�S)Nc	s&i|]}|d�g��|�d����qS)r�r4)rJr}r���prefixrr�
<dictcomp>fs&z)construct_package_dir.<locals>.<dictcomp>)r�r	r�)r�r�Zparent_pkgsrr�r�construct_package_dircs
r�)rr
rr)r�rr�r
rr;)r�r;rr;)r�r;r�r�r�r
rr�)r|rr�r�r�r
rr)r�r;r�r
rr�)-r0�
__future__r�	itertoolsr�collections.abcrrr�fnmatchrr�pathlibr	�typingr
rZ_distutils_hack.override�_distutils_hackr\r
�	distutilsrZdistutils.utilrZ
setuptoolsr�chain�
from_iterabler�rrr1rFr[r]rbr�r�r�r�r�r�r�r�rrrr�<module>s@'
0/5

e

	
"