
    &S                       S r SSKJr  SSKrSSKrSSKJrJrJr  SSK	J
r
  SSKJr  SSKJr  SSKJrJr  SSKrS	S
KJr  SSKJr  SSKJr  \(       a  SSKJr  \R6                  R8                  rS%S jr " S S5      r " S S5      r  " S S\ 5      r! " S S\!5      r" " S S\ 5      r# " S S\"5      r$ " S S\#5      r%S&S jr& " S S5      r'S'S  jr(S'S! jr)        S(S" jr*        S)S# jr+S*S$ jr,g)+u_  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)Distributionc                \    [         R                  R                  U 5      R                  5       $ N)ospathbasenameisidentifier)r   s    Oplatform/bundledpythonunix/lib/python3.13/site-packages/setuptools/discovery.py_valid_namer   ?   s     77D!..00    c                  6    \ rS rSrSrSS jrS	S jrS	S jrSrg)
_FilterD   zw
Given a list of patterns, create a callable that will be true only if
the input matches at least one of the patterns.
c                8    [         R                  U5      U l        g r   )dictfromkeys	_patterns)selfpatternss     r   __init___Filter.__init__J   s    x0r   c                B   ^ [        U4S jU R                   5       5      $ )Nc              3  <   >#    U  H  n[        TU5      v   M     g 7fr   r   ).0patitems     r   	<genexpr>#_Filter.__call__.<locals>.<genexpr>N   s     D^c;tS))^s   )anyr!   r"   r*   s    `r   __call___Filter.__call__M   s    DT^^DDDr   c                    XR                   ;   $ r   r!   r.   s     r   __contains___Filter.__contains__P   s    ~~%%r   r2   N)r#   strreturnNone)r*   r5   r6   bool)	__name__
__module____qualname____firstlineno____doc__r$   r/   r3   __static_attributes__ r   r   r   r   D   s    
1E&r   r   c                      \ rS rSr% SrSrS\S'   SrS\S'   \   S
       SS jj5       r	\        SS j5       r
Srg	)_FinderT   z@Base class that exposes functionality for module/package findersr?   zClassVar[tuple[str, ...]]ALWAYS_EXCLUDEDEFAULT_EXCLUDEc           	         U=(       d    U R                   n[        U R                  [        [	        U5      5      [        / U R                  QUQ76 [        U6 5      5      $ )a  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``.
)rD   list
_find_iterr   r5   r   rC   clswhereexcludeincludes       r   find_Finder.findZ   sW    4 0S00NNSZ(6++6g6!
 	
r   c                    [         er   )NotImplementedErrorrH   s       r   rG   _Finder._find_iter}   s
     "!r   N).r?   )*)rJ   r   rK   Iterable[str]rL   rT   r6   	list[str]rJ   r   rK   r   rL   r   r6   zIterator[str])r9   r:   r;   r<   r=   rC   __annotations__rD   classmethodrM   rG   r>   r?   r   r   rA   rA   T   s    J02N-213O.3 !#!'	 
 
  
 	 

 
 
  
D ""&-"8?"	" "r   rA   c                  T    \ rS rSrSrSr\        SS j5       r\S	S j5       r	Sr
g)
PackageFinder   zA
Generate a list of all Python packages found within a directory
)ez_setupz*__pycache__c              #    #    [         R                  " [        U5      SS9 H  u  pEnUSS n/ USS& U H  n[         R                  R	                  XH5      n	[         R                  R                  X5      n
U
R                  [         R                  R                  S5      nSU;   d  U R                  X5      (       d  M  U" U5      (       a  U" U5      (       d  Uv   U S3U;   d	  U S3U;   a  M  UR                  U5        M     M     g7f)za
All the packages found in 'where' that pass the 'include' filter, but
not the 'exclude' filter.
T)followlinksNrR   rS   .*)
r   walkr5   r   joinrelpathreplacesep_looks_like_packageappend)rI   rJ   rK   rL   rootdirsfilesall_dirsdir	full_pathrel_pathpackages               r   rG   PackageFinder._find_iter   s      "$U!FDAwHDGGGLL3	77??9<"**277;;< #:S%<%<Y%P%P 7##GG,<,<!M Ya=G+'"~/H C '   "Gs   DDc                |    [         R                  R                  [         R                  R                  U S5      5      $ )z%Does a directory look like a package?__init__.py)r   r   isfilera   )r   _package_names     r   re   !PackageFinder._looks_like_package   s&     ww~~bggll4?@@r   r?   NrV   )r   r   rs   r5   r6   r8   )r9   r:   r;   r<   r=   rC   rX   rG   staticmethodre   r>   r?   r   r   rZ   rZ      sW     2N!!&-!8?!	! !B A Ar   rZ   c                  (    \ rS rSr\SS j5       rSrg)PEP420PackageFinder   c                    g)NTr?   )_pathrs   s     r   re   'PEP420PackageFinder._looks_like_package   s    r   r?   N)rz   r   rs   r5   r6   r8   )r9   r:   r;   r<   ru   re   r>   r?   r   r   rw   rw      s     r   rw   c                  L    \ rS rSrSr\        SS j5       r\" \5      r	Sr
g)ModuleFinder   zQFind isolated Python modules.
This function will **not** recurse subdirectories.
c              #  \  #    [        [        R                  R                  US5      5       H{  n[        R                  R	                  [        R                  R                  U5      5      u  pVU R                  U5      (       d  MY  U" U5      (       d  Mh  U" U5      (       a  Mw  Uv   M}     g 7f)Nz*.py)r	   r   r   ra   splitextr   _looks_like_module)rI   rJ   rK   rL   filemodule_exts          r   rG   ModuleFinder._find_iter   st      eV45D77++BGG,<,<T,BCLF))&11vwv 6s   BB,B,#	B,r?   NrV   )r9   r:   r;   r<   r=   rX   rG   ru   r   r   r>   r?   r   r   r}   r}      sH     

&-
8?
	
 
 &k2r   r}   c                  X    \ rS rSrSr\" \" S \ 5       5      5      r \SS j5       r	Sr
g)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              #  .   #    U  H  oU S 34v   M     g7f)r_   Nr?   )r(   ps     r   r+   !FlatLayoutPackageFinder.<genexpr>   s     &GhaS8}hs   c                    UR                  S5      nUS   R                  5       =(       d    US   R                  S5      nU=(       a    [        S USS   5       5      $ )NrR   r   -stubsc              3  @   #    U  H  oR                  5       v   M     g 7fr   )r   )r(   names     r   r+   >FlatLayoutPackageFinder._looks_like_package.<locals>.<genexpr>  s     (S):):)<)<s   r   )splitr   endswithall)rz   package_namenamesroot_pkg_is_valids       r   re   +FlatLayoutPackageFinder._looks_like_package   sU    ""3'!!H113RuQx7H7H7R SS(Sqr(S%SSr   r?   N)rz   r   r   r5   r6   r8   )r9   r:   r;   r<   _EXCLUDEtuple
chain_iterrD   ru   re   r>   r?   r   r   r   r      s8    'HR J&Gh&GGHO T Tr   r   c                      \ rS rSrSrSrg)FlatLayoutModuleFinderi  )setupconftestr   r   r   r   r   toxfilenoxfilepavementdodor   r   z[Ss][Cc]onstruct	conanfilemanager   r   r   r   r   r?   N)r9   r:   r;   r<   rD   r>   r?   r   r   r   r     s    O4 *r   r   c                    [         R                  U5      nU /U Vs/ s H  nSR                  X45      PM     sn-   $ s  snf )NrR   )rw   rM   ra   )root_pkgpkg_dirnestedns       r   _find_packages_withinr   %  s<     %%g.F:&A&Q8-0&AAAAs   =c                      \ rS rSrSrSS jrS rS r\SS j5       r	\SS j5       r
 S       SS jjrSS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSrg) ConfigDiscoveryi*  z}Fill-in metadata and options that can be automatically derived
(from other metadata/options, the file system or conventions)
c                :    Xl         SU l        SU l        SU l        g )NF)r   _called	_disabled_skip_ext_modules)r"   distributions     r   r$   ConfigDiscovery.__init__/  s     	!&r   c                    SU l         g)z+Internal API to disable automatic discoveryTN)r   r"   s    r   _disableConfigDiscovery._disable5  s	    r   c                    SU l         g)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   s    r   _ignore_ext_modules#ConfigDiscovery._ignore_ext_modules9  s     "&r   c                \    U R                   R                  =(       d    [        R                  $ r   )r   src_rootr   curdirr   s    r   	_root_dirConfigDiscovery._root_dirE  s     yy!!.RYY.r   c                `    U R                   R                  c  0 $ U R                   R                  $ r   )r   package_dirr   s    r   _package_dirConfigDiscovery._package_dirJ  s'    99  (Iyy$$$r   c                    USL a#  U R                   (       d  U R                  (       a  gU R                  U5        U(       a  U R                  5         SU l         g)ay  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_moduless       r   r/   ConfigDiscovery.__call__P  s?     E>t||t~~$$%78r   c                l   U=(       d    U R                   nU R                  R                  SL =(       d    U(       + nU R                  R                  SL=(       d[    U R                  R                  SL=(       d<    U=(       d3    [        U R                  S5      =(       a    U R                  R                  $ )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   s      r   _explicitly_specified%ConfigDiscovery._explicitly_specifiedg  s    /I43I3I9900D8N<NOIId* (yy##4/(( tyy/2 (		''	
r   c                    U R                  U5      (       a  g[        R                  " S5        U R                  5       =(       d'    U R	                  5       =(       d    U R                  5       $ )NTzLNo `packages` or `py_modules` configuration, performing automatic discovery.)r   r   debug_analyse_explicit_layout_analyse_src_layout_analyse_flat_layout)r"   r   s     r   r   'ConfigDiscovery._analyse_package_layoutt  sa    %%&899 		#	
 ))+ +'')+ ((*		
r   c                  ^ U R                   R                  5       nUR                  SS5        U R                  mU(       d  g[        R
                  " SU 35        [        U4S jUR                  5        5       5      n[        U5      U R                  l
        [        R
                  " SU R                  R                   35        g)zAThe user can explicitly give a package layout via ``package_dir`` NFz(`explicit-layout` detected -- analysing c              3  |   >#    U  H1  u  p[        U[        R                  R                  TU5      5      v   M3     g 7fr   )r   r   r   ra   )r(   pkg
parent_dirroot_dirs      r   r+   ;ConfigDiscovery._analyse_explicit_layout.<locals>.<genexpr>  s3      
#6 "#rww||Hj'IJJ#6s   9<discovered packages -- T)r   copypopr   r   r   r   itemsrF   r   r   )r"   r   pkgsr   s      @r   r   (ConfigDiscovery._analyse_explicit_layout  s    '',,.D!>>		<[MJK 
#.#4#4#6
 
 "$Z				+DII,>,>+?@Ar   c                   U R                   n[        R                  R                  U R                  UR                  SS5      5      n[        R                  R                  U5      (       d  g[        R                  " SU 35        UR                  S[        R                  R                  U5      5        XR                  l        [        R                  U5      U R                  l        [         R                  U5      U R                  l        [        R                  " SU R                  R                   35        [        R                  " SU R                  R"                   35        g)av  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   ra   r   getisdirr   r   
setdefaultr   r   r   rw   rM   r   r}   r   )r"   r   src_dirs      r   r   #ConfigDiscovery._analyse_src_layout  s     '''',,t~~{r5/IJww}}W%%		7yABr277#3#3G#<= +		055g>		+009				+DII,>,>+?@A		-dii.B.B-CDEr   c                    [         R                  " SU R                   35        U R                  5       =(       d    U R	                  5       $ )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   s    r   r   $ConfigDiscovery._analyse_flat_layout  s:     			88HIJ**,L0J0J0LLr   c                B   [         R                  U R                  5      U R                  l        [        [        U R                  R                  5      5      n[        R                  " SU R                  R                   35        U R                  US5        [        U5      $ )Nr  r   )r   rM   r   r   r   remove_nested_packagesremove_stubsr   r   _ensure_no_accidental_inclusionr8   )r"   	top_levels     r   r  &ConfigDiscovery._analyse_flat_packages  so    499$..I		*<		8J8J+KL			+DII,>,>+?@A,,Y
CIr   c                B   [         R                  U R                  5      U R                  l        [
        R                  " SU R                  R                   35        U R                  U R                  R                  S5        [        U R                  R                  5      $ )Nr	  modules)	r   rM   r   r   r   r   r   r  r8   r   s    r   r  %ConfigDiscovery._analyse_flat_modules  sk    5::4>>J				-dii.B.B-CDE,,TYY-A-A9MDII(())r   c                n    [        U5      S:  a&  SSKJn  SSKJn  SU SU SU S3nU" U" U5      5      eg )	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"   detectedkindr  r  msgs         r   r  /ConfigDiscovery._ensure_no_accidental_inclusion  sU    x=1(?)$/MhZ XM
 NRF 	SC (66) r   c                D   U R                   R                  R                  (       d  U R                   R                  (       a  g[        R                  " S5        U R                  5       =(       d    U R                  5       nU(       a  XR                   R                  l        gg)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   s     r   r   ConfigDiscovery.analyse_name  so     99""diinn		KL 446 /,,. 	 &*II# r   c                    S H^  n[        U R                  US5      =(       d    / nU(       d  M,  [        U5      S:X  d  M=  [        R                  " SUS    35        US   s  $    g)zExactly one module or package)r   r   Nr   z&Single module/package detected, name: r   )getattrr   r  r   r   )r"   fieldr  s      r   r(  3ConfigDiscovery._find_name_single_package_or_module  sX    /EDIIud39rEuUq		B58*MNQx	 0 r   c                l   U R                   R                  (       d  g[        [        U R                   R                  [        S95      nU R                   R
                  =(       d    0 n[        XU R                  5      nU(       a  [        R                  " SU 35        U$ [        R                  " S5        g)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_pkgs       r   r)  (ConfigDiscovery._find_name_from_packages  s~    yy!!tyy'9'9s CDii++1r(O
II>zlKLJKr   )r   r   r   r   N)r   r   r6   r7   )r6   r   )r6   dict[str, str])FTF)r   r8   r   r8   r   r8   r6   r7   )r   r8   r6   r8   )r6   r8   )r"  rU   r#  r5   )r6   r7   )r6   
str | None)r9   r:   r;   r<   r=   r$   r   r   propertyr   r   r/   r   r   r   r   r   r  r  r  r   r(  r)  r>   r?   r   r   r   r   *  s    '
& / / % % RW)-JN	.

$$2M*7.+"r   r   c                   ^ [        U [        S9nUSS n[        U5      n[        [        U5      5       H8  u  nm[	        U4S jU 5       5      (       d  M"  UR                  X4-
  S-
  5        M:     U$ )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']
r0  Nc              3  L   >#    U  H  nTR                  U S 35      v   M     g7frR   N
startswith)r(   otherr   s     r   r+   )remove_nested_packages.<locals>.<genexpr>  s#     Ct%{++s   !$r   )r2  r  	enumeratereversedr-   r  )r   r  r  sizeir   s        @r   r  r    se     ($DQIt9DXd^,4CCCCMM$(Q,' - r   c                    U  Vs/ s H.  oR                  S5      S   R                  S5      (       a  M,  UPM0     sn$ s  snf )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']
rR   r   r   )r   r   )r   r   s     r   r  r     s4     $P8C99S>!+<+E+Eh+OC8PPPs   +==c                n  ^ [        U [        S9n / n[        U 5       H8  u  nm[        U4S jXS-   S  5       5      (       d    OUR	                  T5        M:     U HW  m[        TX5      n[        R                  R                  US5      n[        R                  R                  U5      (       d  MU  Ts  $    g)z0Find the parent package that is not a namespace.r0  c              3  J   >#    U  H  oR                  T S 35      v   M     g7fr<  r=  )r(   r   r   s     r   r+   &find_parent_package.<locals>.<genexpr>0  s#     G5F<<4&
++5Fs    #r   Nrq   )
r2  r  rA  r   rf   find_package_pathr   r   ra   rr   )r   r   r   common_ancestorsrD  pkg_pathinitr   s          @r   r3  r3  )  s     hC(HX&4GX!eg5FGGG
 % ' !$T;Aww||Hm477>>$K	 ! r   c                z   U R                  S5      n[        [        U5      SS5       HE  nSR                  USU 5      nXQ;   d  M  X   n[        R
                  R                  " X&/X4S Q76 s  $    UR                  S5      =(       d    Sn[        R
                  R                  " U/UR                  S5      QUQ76 $ )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'
rR   r   Nr   /)r   ranger  ra   r   r   r
  )r   r   r   partsrD  partial_nameparents          r   rI  rI  A  s    , JJsOE3u:q"%xxbq	*& .F77<<=59== & __R &BF77<<=6<<#4=u==r   c           
         [        U 5      n[        U5      R                  nU Vs0 s H'  oDSR                  / UQUR	                  S5      Q5      _M)     sn$ s  snf )NrO  rR   )r  r
   rQ  ra   r   )r   package_pathparent_pkgsprefixr   s        r   construct_package_dirrX  c  sS    (2K,%%FALM#4F4SYYs^455MMMs   .A)r   r   r6   r8   )r   r5   r   r   r6   rU   )r   rU   r6   rU   )r   rU   r   Mapping[str, str]r   r   r6   r8  )r   r5   r   rY  r   r   r6   r5   )r   rU   rU  r   r6   r7  )-r=   
__future__r   	itertoolsr   collections.abcr   r   r   fnmatchr   r	   pathlibr
   typingr   r   _distutils_hack.override_distutils_hackrz   r   	distutilsr   distutils.utilr   
setuptoolsr   chainfrom_iterabler   r   r   rA   rZ   rw   r}   r   r   r   r   r  r  r3  rI  rX  r?   r   r   <module>rg     s  %N #  	 7 7    *    ''__**
1
& & -" -"`,AG ,A^- 37 322T1 2Tj*\ *<B
a aH$Q&7CJ0>
>->9@>>DNr   