/ lib / setuptools / discovery.pyc
discovery.pyc
  1  o

  2  ���c?Q�	@sdZddlZddlZddlmZddlmZddlmZddlm	Z	m
  3  Z
  4  mZmZm
Z
mZmZmZmZmZddlZddlmZddlmZeeejfZe
  5  egefZe
eZejj Z!e	rbdd	l"m#Z#d
  6  edefdd
�Z$Gdd�d�Z%Gdd�de%�Z&Gdd�de&�Z'Gdd�de%�Z(Gdd�de'�Z)Gdd�de(�Z*dededeefdd�Z+Gdd�d�Z,d eedeefd!d"�Z-d eedeefd#d$�Z.d eed%eeefd&edeefd'd(�Z/d)ed%eeefd&edefd*d+�Z0d eed,edeeeffd-d.�Z1dS)/u_Automatic discovery of Python modules and packages (for inclusion in the
  7  distribution) and other config values.
  8  
  9  For the purposes of this module, the following nomenclature is used:
 10  
 11  - "src-layout": a directory representing a Python project that contains a "src"
 12    folder. Everything under the "src" folder is meant to be included in the
 13    distribution when packaging the project. Example::
 14  
 15      .
 16      ├── tox.ini
 17      ├── pyproject.toml
 18      └── src/
 19          └── mypkg/
 20              ├── __init__.py
 21              ├── mymodule.py
 22              └── my_data_file.txt
 23  
 24  - "flat-layout": a Python project that does not use "src-layout" but instead
 25    have a directory under the project root for each package::
 26  
 27      .
 28      ├── tox.ini
 29      ├── pyproject.toml
 30      └── mypkg/
 31          ├── __init__.py
 32          ├── mymodule.py
 33          └── my_data_file.txt
 34  
 35  - "single-module": a project that contains a single Python script direct under
 36    the project root (no directory used)::
 37  
 38      .
 39      ├── tox.ini
 40      ├── pyproject.toml
 41      └── mymodule.py
 42  
 43  �N��fnmatchcase)�glob)�Path)
 44  �
TYPE_CHECKING�Callable�Dict�Iterable�Iterator�List�Mapping�Optional�Tuple�Union)�log)�convert_path)�Distribution�path�returncCstj�|���S�N)�osr�basename�isidentifier)r�r��C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\site-packages\setuptools\discovery.py�_valid_nameIsrc@s�eZdZUdZdZeedfed<dZeedfed<e				dde
 45  d	eed
 46  eedeefdd
��Z
e	de
 47  d	ed
 48  edefdd��Zededefdd��ZdS)�_Finderz@Base class that exposes functionality for module/package findersr.�ALWAYS_EXCLUDE�DEFAULT_EXCLUDE�.��*�where�exclude�includercCs<|p|j}t|�tt|��|jg|j�|�R�|j|���S)aFReturn a list of all Python items (packages or modules, depending on
 49          the finder implementation) found within directory 'where'.
 50  
 51          'where' is the root directory which will be searched.
 52          It should be supplied as a "cross-platform" (i.e. URL-style) path;
 53          it will be converted to the appropriate local path syntax.
 54  
 55          'exclude' is a sequence of names to exclude; '*' can be used
 56          as a wildcard in the names.
 57          When finding packages, 'foo.*' will exclude all subpackages of 'foo'
 58          (but not 'foo' itself).
 59  
 60          'include' is a sequence of names to include.
 61          If it's specified, only the named items will be included.
 62          If it's not specified, all found items will be included.
 63          'include' can contain shell style wildcard patterns just like
 64          'exclude'.
 65          )r�list�
 66  _find_iterr�str�
_build_filterr��clsr"r#r$rrr�findTs
 67  
 68  ��z_Finder.findcCst�r)�NotImplementedErrorr)rrrr&w�z_Finder._find_iter�patternscs�fdd�S)z�
 69          Given a list of patterns, return a callable that will be true only if
 70          the input matches at least one of the patterns.
 71          cst�fdd��D��S)Nc3s�|]}t�|�VqdSrr)�.0�pat��namerr�	<genexpr>�s�z:_Finder._build_filter.<locals>.<lambda>.<locals>.<genexpr>)�anyr1�r.r1r�<lambda>�sz'_Finder._build_filter.<locals>.<lambda>rr5rr5rr({sz_Finder._build_filterN)rrr )�__name__�
 72  __module__�__qualname__�__doc__rrr'�__annotations__r�classmethod�_Pathr	rr+�_Filter�StrIterr&�staticmethodr(rrrrrNs*
 73  �����"rc	@sLeZdZdZdZededededefdd��Z	e
 74  d	ed
 75  edefdd��Z
d
S)�
PackageFinderzI
 76      Generate a list of all Python packages found within a directory
 77      )�ez_setupz*__pycache__r"r#r$rccs��tjt|�dd�D]G\}}}|dd�}g|dd�<|D]3}tj�||�}	tj�|	|�}
 78  |
 79  �tjjd�}d|vs?|�|	|�s@q||�rK||�sK|V|�	|�qq
 80  dS)zy
 81          All the packages found in 'where' that pass the 'include' filter, but
 82          not the 'exclude' filter.
 83          T)�followlinksNr)
 84  r�walkr'r�join�relpath�replace�sep�_looks_like_package�append)r*r"r#r$�root�dirs�files�all_dirs�dir�	full_path�rel_path�packagerrrr&�s���zPackageFinder._find_iterr�
_package_namecCstj�tj�|d��S)z%Does a directory look like a package?�__init__.py)rr�isfilerE)rrSrrrrI�sz!PackageFinder._looks_like_packageN)r7r8r9r:rr<r=r>r?r&r@r'�boolrIrrrrrA�srAc@s&eZdZedededefdd��ZdS)�PEP420PackageFinder�_pathrSrcCsdS)NTr)rXrSrrrrI�r-z'PEP420PackageFinder._looks_like_packageN)r7r8r9r@r=r'rVrIrrrrrW�srWc	@s6eZdZdZededededefdd��Ze	e
 85  �ZdS)	�ModuleFinderzYFind isolated Python modules.
 86      This function will **not** recurse subdirectories.
 87      r"r#r$rccsX�ttj�|d��D]}tj�tj�|��\}}|�|�sq
 88  ||�r)||�s)|Vq
 89  dS)Nz*.py)rrrrE�splitextr�_looks_like_module)r*r"r#r$�file�module�_extrrrr&�s�
 90  ��zModuleFinder._find_iterN)r7r8r9r:r<r=r>r?r&r@rr[rrrrrY�s
 91  
 92  rYc@sBeZdZdZeedd�eD���Z	edede	de
 93  fdd��Zd	S)
 94  �FlatLayoutPackageFinder) �ci�bin�doc�docs�
documentation�manpages�news�	changelog�test�tests�	unit_test�
 95  unit_tests�example�examples�scripts�tools�util�utils�python�build�dist�venv�env�requirements�tasks�fabfile�
 96  site_scons�	benchmark�
 97  benchmarks�exercise�	exercises�[._]*ccs�|]
 98  }||�d�fVqdS)z.*Nr)r/�prrrr3�s�z!FlatLayoutPackageFinder.<genexpr>rX�package_namercCsB|�d�}|d��p|d�d�}|o tdd�|dd�D��S)Nrr�-stubscss�|]}|��VqdSr)r)r/r2rrrr3�s�z>FlatLayoutPackageFinder._looks_like_package.<locals>.<genexpr>�)�splitr�endswith�all)rXr��names�root_pkg_is_validrrrrI�s
 99  z+FlatLayoutPackageFinder._looks_like_packageN)r7r8r9�_EXCLUDE�tuple�
100  chain_iterrr@r=r'rVrIrrrrr_�s&r_c@seZdZdZdS)�FlatLayoutModuleFinder)�setup�conftestrhrirlrmrs�toxfile�noxfile�pavement�dodorxryz[Ss][Cc]onstruct�	conanfile�manager{r|r}r~rN)r7r8r9rrrrrr��sr��root_pkg�pkg_dircs"t�|�}�g�fdd�|D�S)Ncsg|]	}d��|f��qS)r)rE�r/�n�r�rr�
101  <listcomp>sz)_find_packages_within.<locals>.<listcomp>)rWr+)r�r��nestedrr�r�_find_packages_withins
102  r�c@seZdZdZd-dd�Zdd�Zdd	�Zed
103  efdd��Z	ed
104  e
105  eeffd
d��Zd.dd�Z
ded
106  efdd�Zded
107  efdd�Zd
108  efdd�Zd
109  efdd�Zd
110  efdd�Zd
111  efdd�Zd
112  efd d!�Zd"eed#efd$d%�Zd&d'�Zd
113  eefd(d)�Zd
114  eefd*d+�Zd,S)/�ConfigDiscoveryz�Fill-in metadata and options that can be automatically derived
115      (from other metadata/options, the file system or conventions)
116      �distributionrcCs||_d|_d|_d|_dS)NF)rt�_called�	_disabled�_skip_ext_modules)�selfr�rrr�__init__$s
117  zConfigDiscovery.__init__cC�
118  d|_dS)z+Internal API to disable automatic discoveryTN)r��r�rrr�_disable*s
119  zConfigDiscovery._disablecCr�)a�Internal API to disregard ext_modules.
120  
121          Normally auto-discovery would not be triggered if ``ext_modules`` are set
122          (this is done for backward compatibility with existing packages relying on
123          ``setup.py`` or ``setup.cfg``). However, ``setuptools`` can call this function
124          to ignore given ``ext_modules`` and proceed with the auto-discovery if
125          ``packages`` and ``py_modules`` are not given (e.g. when using pyproject.toml
126          metadata).
127          TN)r�r�rrr�_ignore_ext_modules.s
128  
129  z#ConfigDiscovery._ignore_ext_modulesrcCs|jjptjSr)rt�src_rootr�curdirr�rrr�	_root_dir:szConfigDiscovery._root_dircCs|jjduriS|jjSr)rt�package_dirr�rrr�_package_dir?szConfigDiscovery._package_dirFTcCs8|dur|js
130  |jrdS|�|�|r|��d|_dS)a�Automatically discover missing configuration fields
131          and modifies the given ``distribution`` object in-place.
132  
133          Note that by default this will only have an effect the first time the
134          ``ConfigDiscovery`` object is called.
135  
136          To repeatedly invoke automatic discovery (e.g. when the project
137          directory changes), please use ``force=True`` (or create a new
138          ``ConfigDiscovery`` instance).
139          FNT)r�r��_analyse_package_layout�analyse_name)r��forcer2�ignore_ext_modulesrrr�__call__Es
140  
141  zConfigDiscovery.__call__r�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�rt�ext_modules�packages�
142  py_modules�hasattrr�)r�r�r�rrr�_explicitly_specifiedZs
143  
144  ���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�fs
145  ���z'ConfigDiscovery._analyse_package_layoutcsr|j��}|�dd�|j�|sdSt�d|���t�fdd�|��D��}t|�|j	_
146  t�d|j	j
147  ���dS)	zAThe user can explicitly give a package layout via ``package_dir``�NFz(`explicit-layout` detected -- analysing c3s(�|]\}}t|tj��|��VqdSr)r�rrrE)r/�pkg�
148  parent_dir��root_dirrrr3�s
149  ��
150  �z;ConfigDiscovery._analyse_explicit_layout.<locals>.<genexpr>�discovered packages -- T)r��copy�popr�rr�r��itemsr%rtr�)r�r��pkgsrr�rr�xs
151  �z(ConfigDiscovery._analyse_explicit_layoutcCs�|j}tj�|j|�dd��}tj�|�sdSt�d|���|�	dtj�
152  |��||j_t
�|�|j_t�|�|j_t�d|jj���t�d|jj���dS)a�Try to find all packages or modules under the ``src`` directory
153          (or anything pointed by ``package_dir[""]``).
154  
155          The "src-layout" is relatively safe for automatic discovery.
156          We assume that everything within is meant to be included in the
157          distribution.
158  
159          If ``package_dir[""]`` is not given, but the ``src`` directory exists,
160          this function will set ``package_dir[""] = "src"``.
161          r��srcFz#`src-layout` detected -- analysing r��discovered py_modules -- T)r�rrrEr��get�isdirrr��
162  setdefaultrrtr�rWr+r�rYr�)r�r��src_dirrrrr��sz#ConfigDiscovery._analyse_src_layoutcCs"t�d|j���|��p|��S)a�Try to find all packages and modules under the project root.
163  
164          Since the ``flat-layout`` is more dangerous in terms of accidentally including
165          extra files/directories, this function is more conservative and will raise an
166          error if multiple packages or modules are found.
167  
168          This assumes that multi-package dists are uncommon and refuse to support that
169          use case in order to be able to prevent unintended errors.
170          z$`flat-layout` detected -- analysing )rr�r��_analyse_flat_packages�_analyse_flat_modulesr�rrrr��s
171  z$ConfigDiscovery._analyse_flat_layoutcCsHt�|j�|j_tt|jj��}t�d|jj���|�	|d�t
172  |�S)Nr�r�)r_r+r�rtr��remove_nested_packages�remove_stubsrr��_ensure_no_accidental_inclusionrV)r��	top_levelrrrr��s
173  z&ConfigDiscovery._analyse_flat_packagescCs@t�|j�|j_t�d|jj���|�|jjd�t|jj�S)Nr��modules)	r�r+r�rtr�rr�r�rVr�rrrr��sz%ConfigDiscovery._analyse_flat_modules�detected�kindcCsLt|�dkr$ddlm}ddlm}d|�d|�d|�d�}|||���dS)	Nr�r)�cleandoc)�PackageDiscoveryErrorzMultiple top-level z discovered in a flat-layout: z�.
174  
175              To avoid accidental inclusion of unwanted files or directories,
176              setuptools will not proceed with this build.
177  
178              If you are trying to create a single distribution with multiple a�
179              on purpose, you should not rely on automatic discovery.
180              Instead, consider the following options:
181  
182              1. set up custom discovery (`find` directive with `include` or `exclude`)
183              2. use a `src-layout`
184              3. explicitly set `py_modules` or `packages` with a list of names
185  
186              To find more information, look for "package discovery" on setuptools docs.
187              )�len�inspectr��setuptools.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.
188          Therefore the name of the distribution can be derived from them.
189          Nz7No `name` configuration, performing automatic discovery)rt�metadatar2rr��#_find_name_single_package_or_module�_find_name_from_packages)r�r2rrrr��s
190  ��zConfigDiscovery.analyse_namecCsPdD]#}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)�getattrrtr�rr�)r��fieldr�rrrr��s�z3ConfigDiscovery._find_name_single_package_or_modulecCs`|jjsdStt|jjtd��}|jjpi}t|||j�}|r)t�	d|���|St�
191  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`)rtr�r��sortedr�r��find_parent_packager�rr��warn)r�r�r��
192  parent_pkgrrrr��s
193  z(ConfigDiscovery._find_name_from_packagesN)r�r)FTF)r7r8r9r:r�r�r��propertyr=r�rr'r�r�rVr�r�r�r�r�r�r�rr�r�r
r�r�rrrrr�s*
194  
195  

196  r�r�csbt|td�}|dd�}t|�}tt|��D]\}�t�fdd�|D��r.|�||d�q|S)z�Remove nested packages from a list of packages.
197  
198      >>> remove_nested_packages(["a", "a.b1", "a.b2", "a.b1.c1"])
199      ['a']
200      >>> remove_nested_packages(["a", "b", "c.d", "c.d.e.f", "g.h", "a.a1"])
201      ['a', 'b', 'c.d', 'g.h']
202      r�Nc3s �|]}��|�d��VqdS�rN��
203  startswith)r/�otherr1rrr3��z)remove_nested_packages.<locals>.<genexpr>r�)r�r��	enumerate�reversedr4r�)r�r�r��size�irr1rr�s�r�cCsdd�|D�S)z�Remove type stubs (:pep:`561`) from a list of packages.
204  
205      >>> remove_stubs(["a", "a.b", "a-stubs", "a-stubs.b.c", "b", "c-stubs"])
206      ['a', 'a.b', 'b']
207      cSs$g|]}|�d�d�d�s|�qS)rrr�)r�r��r/r�rrrr�s$z remove_stubs.<locals>.<listcomp>r)r�rrrr�sr�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�r1rrr3"r�z&find_parent_package.<locals>.<genexpr>r�NrT)
208  r�r�r�r�rJ�find_package_pathrrrErU)r�r�r��common_ancestorsr��pkg_path�initrr1rr�s"�r�r2cCs�|�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
209      disk, considering the ``package_dir`` option.
210  
211      >>> path = find_package_path("my.pkg", {"": "root/is/nested"}, ".")
212      >>> path.replace(os.sep, "/")
213      './root/is/nested/my/pkg'
214  
215      >>> path = find_package_path("my.pkg", {"my": "root/is/nested"}, ".")
216      >>> path.replace(os.sep, "/")
217      './root/is/nested/pkg'
218  
219      >>> path = find_package_path("my.pkg", {"my.pkg": "root/is/nested"}, ".")
220      >>> path.replace(os.sep, "/")
221      './root/is/nested'
222  
223      >>> path = find_package_path("other.pkg", {"my.pkg": "root/is/nested"}, ".")
224      >>> path.replace(os.sep, "/")
225      './other/pkg'
226      rr�����Nr��/)r��ranger�rErrr�)r2r�r��partsr��partial_name�parentrrrr�3s
227  "�r��package_pathcs$t|�}t|�j��fdd�|D�S)Nc	s&i|]}|d�g��|�d����qS)r�r)rEr�r���prefixrr�
228  <dictcomp>Xs&z)construct_package_dir.<locals>.<dictcomp>)r�rr�)r�r��parent_pkgsrr�r�construct_package_dirUs
229  r)2r:�	itertoolsr�fnmatchrr�pathlibr�typingrrrr	r
230  rrr
rr�_distutils_hack.override�_distutils_hack�	distutilsr�distutils.utilrr'�PathLiker=rVr>r?�chain�
from_iterabler��
231  setuptoolsrrrrArWrYr_r�r�r�r�r�r�r�rrrrr�<module>s^'0
6)2b	�
232  ��
233  ��
234  ��
235  �&"