o
    5‘ði&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   úS/root/parts/websockify/install/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 )@ÚConfigDiscoveryz…Fill-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 )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)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 )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è   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 )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']
    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

	
"