o
    EeR                  	   @   s  d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZmZmZmZmZ ddlZddlmZ ddlmZ eeejf Zee ZejjZe	rYdd	lm Z  d
ede!f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ededee fddZ*G d d! d!Z+d"ee dee fd#d$Z,d"ee dee fd%d&Z-d"ee d'eeef d(edee fd)d*Z.d+ed'eeef d(edefd,d-Z/d"ee d.ede
eef fd/d0Z0dS )1u_  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

    Nfnmatchcase)glob)Path)	TYPE_CHECKINGDictIterableIteratorListMappingOptionalTupleUnion)log)convert_path)Distributionpathreturnc                 C   s   t j|  S N)osr   basenameisidentifier)r    r   U/var/www/bmteknikk.ddns.net/venv/lib/python3.10/site-packages/setuptools/discovery.py_valid_nameG   s   r   c                   @   sB   e Zd ZdZdefddZdedefddZdedef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.
    patternsc                 G   s   t || _d S r   )dictfromkeys	_patterns)selfr   r   r   r   __init__R   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>V   s    z#_Filter.__call__.<locals>.<genexpr>)anyr   r    r"   r   r%   r   __call__U   s   z_Filter.__call__c                 C   s
   || j v S r   )r   r(   r   r   r   __contains__X   s   
z_Filter.__contains__N)	__name__
__module____qualname____doc__strr!   boolr)   r*   r   r   r   r   r   L   s
    r   c                   @   s   e Zd ZU dZdZeedf ed< dZeedf ed< e				dde
d	ee d
ee dee fddZe	de
d	ed
edefddZdS )_Finderz@Base class that exposes functionality for module/package findersr   .ALWAYS_EXCLUDEDEFAULT_EXCLUDE.*whereexcludeincluder   c                 C   s8   |p| j }t| tt|tg | j|R  t| S )aF  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   r9   r   r   r   findb   s   

z_Finder.findc                 C   s   t r   )NotImplementedErrorr<   r   r   r   r;         z_Finder._find_iterN)r4   r   r5   )r+   r,   r-   r.   r2   r   r/   __annotations__r3   classmethod_Pathr   r
   r>   r   StrIterr;   r   r   r   r   r1   \   s&   
 " r1   c                	   @   sL   e Zd ZdZdZededededefddZ	e
d	ed
edefddZdS )PackageFinderzI
    Generate a list of all Python packages found within a directory
    )ez_setupz*__pycache__r7   r8   r9   r   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   r9   rootdirsfilesall_dirsdir	full_pathrel_pathpackager   r   r   r;      s"   zPackageFinder._find_iterr   _package_namec                 C   s   t jt j| dS )z%Does a directory look like a package?__init__.py)r   r   isfilerJ   )r   rX   r   r   r   rN      s   z!PackageFinder._looks_like_packageN)r+   r,   r-   r.   r2   rB   rC   r   rD   r;   staticmethodr/   r0   rN   r   r   r   r   rE      s    rE   c                   @   s&   e Zd ZedededefddZdS )PEP420PackageFinder_pathrX   r   c                 C   s   dS )NTr   )r]   rX   r   r   r   rN      r@   z'PEP420PackageFinder._looks_like_packageN)r+   r,   r-   r[   rC   r/   r0   rN   r   r   r   r   r\      s    r\   c                	   @   s6   e Zd ZdZededededefddZe	e
ZdS )	ModuleFinderzYFind isolated Python modules.
    This function will **not** recurse subdirectories.
    r7   r8   r9   r   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   rJ   splitextr   _looks_like_module)r=   r7   r8   r9   filemodule_extr   r   r   r;      s   
zModuleFinder._find_iterN)r+   r,   r-   r.   rB   rC   r   rD   r;   r[   r   r`   r   r   r   r   r^      s
    
r^   c                   @   sB   e Zd ZdZeedd eD Z	 edede	de
f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 )rH   Nr   )r#   pr   r   r   r&      s    z!FlatLayoutPackageFinder.<genexpr>r]   package_namer   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>   )splitr   endswithall)r]   r   namesroot_pkg_is_validr   r   r   rN     s   
z+FlatLayoutPackageFinder._looks_like_packageN)r+   r,   r-   _EXCLUDEtuple
chain_iterr3   r[   rC   r/   r0   rN   r   r   r   r   rd      s    )rd   c                   @   s   e Zd ZdZdS )FlatLayoutModuleFinder)setupconftestro   rp   rs   rt   rz   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_pkgpkg_dirc                    s"   t |} g fdd|D  S )Nc                    s   g | ]	}d   |fqS )r4   )rJ   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d-ddZdd Zdd	 Zed
efddZ	ed
e
eef fddZd.ddZded
efddZded
efddZd
efddZd
efddZd
efddZd
efddZd
efd d!Zd"ee d#efd$d%Zd&d' Zd
ee fd(d)Zd
ee fd*d+Zd,S )/ConfigDiscoveryzFill-in metadata and options that can be automatically derived
    (from other metadata/options, the file system or conventions)
    distributionr   c                 C   s   || _ d| _d| _d| _d S )NF)r{   _called	_disabled_skip_ext_modules)r    r   r   r   r   r!   1  s   
zConfigDiscovery.__init__c                 C   
   d| _ dS )z+Internal API to disable automatic discoveryTN)r   r    r   r   r   _disable7  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_modules;  s   

z#ConfigDiscovery._ignore_ext_modulesr   c                 C   s   | j jptjS r   )r{   src_rootr   curdirr   r   r   r   	_root_dirG  s   zConfigDiscovery._root_dirc                 C   s   | j jd u ri S | j jS r   )r{   package_dirr   r   r   r   _package_dirL  s   zConfigDiscovery._package_dirFTc                 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    forcer   ignore_ext_modulesr   r   r   r)   R  s   

zConfigDiscovery.__call__r   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   rJ   )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   rJ   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   )rd   r>   r   r{   r   remove_nested_packagesremove_stubsr   r   _ensure_no_accidental_inclusionr0   )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   r0   r   r   r   r   r     s   z%ConfigDiscovery._analyse_flat_modulesdetectedkindc                 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_namec                 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   )FTF)r+   r,   r-   r.   r!   r   r   propertyrC   r   r   r/   r   r)   r0   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   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   NrY   )
r   r   r   r   rO   find_package_pathr   r   rJ   rZ   )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   rJ   r   r   r   )r   r   r   partsr   partial_nameparentr   r   r   r   A  s   
"r   package_pathc                    s$   t | }t|j  fdd|D S )Nc              	      s&   i | ]}|d  g  |dqS )r   r4   )rJ   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  )1r.   	itertoolsr   fnmatchr   r   pathlibr   typingr   r   r   r	   r
   r   r   r   r   _distutils_hack.override_distutils_hack	distutilsr   distutils.utilr   r/   PathLikerC   rD   chainfrom_iterabler   
setuptoolsr   r0   r   r   r1   rE   r\   r^   rd   r   r   r   r   r   r   r   r  r   r   r   r   <module>   s^    ',.-5 c	



&"