~fRdZddlmZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z mZddlZdd lmZdd lmZdd lmZe eZej2j4Ze rdd lmZd$d ZGddZGddZ Gdde Z!Gdde!Z"Gdde Z#Gdde"Z$Gdde#Z%d%dZ&GddZ'd&dZ(d&d Z) d'd!Z* d(d"Z+d)d#Z,y)*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 fnmatchcase)glob)Path) TYPE_CHECKINGIterableIteratorMapping)StrPath)log) convert_path) Distributionc\tjj|jSN)ospathbasename isidentifier)rs ]/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/setuptools/discovery.py _valid_namerDs 77  D ! . . 00c(eZdZdZddZddZddZy)_Filterz Given a list of patterns, create a callable that will be true only if the input matches at least one of the patterns. c8tj||_yr)dictfromkeys _patterns)selfpatternss r__init__z_Filter.__init__Osx0rc@tfd|jDS)Nc36K|]}t|ywrr).0patitems r z#_Filter.__call__..SsDc;tS)Ds)anyrr r's `r__call__z_Filter.__call__RsDT^^DDDrc||jvSr)rr*s r __contains__z_Filter.__contains__Ust~~%%rN)r!str)r'r.returnbool)__name__ __module__ __qualname____doc__r"r+r-rrrrIs 1E&rrcheZdZUdZdZded<dZded<e d d dZed dZ y) _Finderz@Base class that exposes functionality for module/package findersr5ztuple[str, ...]ALWAYS_EXCLUDEDEFAULT_EXCLUDEc |xs |j}t|jtt |t g|j |t |S)aFReturn 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'. )r9list _find_iterrr.rr8clswhereexcludeincludes rfindz _Finder.find_sW40S00 NNSZ(6++6g6!   rctr)NotImplementedErrorr=s rr<z_Finder._find_iters!!rN).r5)*)r?r r@ Iterable[str]rArGr/ list[str]r?r r@rrArr/StrIter) r1r2r3r4r8__annotations__r9 classmethodrBr<r5rrr7r7YsqJ&(NO(')O_)!#!'            D""rr7c8eZdZdZdZeddZeddZy) PackageFinderzI Generate a list of all Python packages found within a directory )ez_setupz *__pycache__c#Ktjt|dD]\}}}|dd}g|dd|D]}tjj ||} tjj | |} | j tjjd} d|vs|j| | s|| r || s| | d|vs| d|vr|j|yw)zy All the packages found in 'where' that pass the 'include' filter, but not the 'exclude' filter. T) followlinksNrErF.*) rwalkr.rjoinrelpathreplacesep_looks_like_packageappend) r>r?r@rArootdirsfilesall_dirsdir full_pathrel_pathpackages rr<zPackageFinder._find_iters "$U!F D$AwHDGGGLLs3 77??9e<"**277;;<#:S%<%AArrNceZdZeddZy)PEP420PackageFindercy)NTr5)_pathres rrXz'PEP420PackageFinder._looks_like_packagesrN)rjr rer.r/r0)r1r2r3rfrXr5rrrhrhsrrhc2eZdZdZeddZeeZy) ModuleFinderzYFind isolated Python modules. This function will **not** recurse subdirectories. c#6Kttjj|dD]i}tjj tjj |\}}|j |sT||s]||rf|kyw)Nz*.py)rrrrTsplitextr_looks_like_module)r>r?r@rAfilemodule_exts rr<zModuleFinder._find_itersneV45D77++BGG,<,s&GaS8}&Gsc|jd}|djxs|djd}|xrtd|ddDS)NrEr-stubsc3<K|]}|jywr)r)r%names rr(z>FlatLayoutPackageFinder._looks_like_package..s(S):):)<(Ssr )splitrendswithall)rj package_namenamesroot_pkg_is_valids rrXz+FlatLayoutPackageFinder._looks_like_packagesU""3'!!H113RuQx7H7H7R SS(Sqr(S%SSrN)rjr rr.r/r0) r1r2r3_EXCLUDEtuple chain_iterr9rfrXr5rrrtrts8'HRJ&Gh&GGHO TTrrtceZdZdZy)FlatLayoutModuleFinder)setupconftestrrrrrtoxfilenoxfilepavementdodorrz[Ss][Cc]onstruct conanfilemanagerrrrrN)r1r2r3r9r5rrrrsO4*rrctj|}|g|Dcgc]}dj||fc}zScc}w)NrE)rhrBrT)root_pkgpkg_dirnestedns r_find_packages_withinr$s: % %g .F :&AQ8Q-0A AAAs;ceZdZdZddZdZdZeddZeddZ ddZ ddZ dd Z dd Z dd Zdd Zdd ZddZddZdZddZddZy)ConfigDiscoveryzFill-in metadata and options that can be automatically derived (from other metadata/options, the file system or conventions) c<||_d|_d|_d|_y)NF)r_called _disabled_skip_ext_modules)r distributions rr"zConfigDiscovery.__init__.s   !&rcd|_y)z+Internal API to disable automatic discoveryTN)rr s r_disablezConfigDiscovery._disable4s rcd|_y)aInternal 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)rrs r_ignore_ext_modulesz#ConfigDiscovery._ignore_ext_modules8s "&rcR|jjxstjSr)rsrc_rootrcurdirrs r _root_dirzConfigDiscovery._root_dirDsyy!!.RYY.rc^|jjiS|jjSr)r package_dirrs r _package_dirzConfigDiscovery._package_dirIs' 99 (Iyy$$$rc|dur|js |jry|j||r|jd|_y)aAutomatically 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)rr_analyse_package_layout analyse_name)r forcerignore_ext_moduless rr+zConfigDiscovery.__call__Os? E>t||t~~  $$%78      rc(|xs |j}|jjduxs| }|jjduxsL|jjduxs2|xs.t |jdxr|jj S)zF``True`` if the user has specified some form of package/module listingN configuration)rr ext_modulespackages py_moduleshasattrr)r rrs r_explicitly_specifiedz%ConfigDiscovery._explicitly_specifiedds/I43I3I9900D8N.s3 Z "#rww||Hj'I J s7:discovered packages -- T) rcopypoprrrritemsr;rr)r rpkgsrs @rrz(ConfigDiscovery._analyse_explicit_layouts'',,. D!>> <[MJK #.#4#4#6  "$Z  +DII,>,>+?@Arc|j}tjj|j|j dd}tjj |sytjd||jdtjj|||j_ tj||j_t j||j_tjd|jjtjd|jj"y)aTry 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"``. rsrcFz#`src-layout` detected -- analysing rdiscovered py_modules -- T)rrrrTrgetisdirrr setdefaultrrrrhrBrrlr)r rsrc_dirs rrz#ConfigDiscovery._analyse_src_layouts'' '',,t~~{r5/IJww}}W% 7yABr277#3#3G#<= + 055g> +009  +DII,>,>+?@A -dii.B.B-CDErctjd|j|jxs|j S)aTry 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 )rrr_analyse_flat_packages_analyse_flat_modulesrs rrz$ConfigDiscovery._analyse_flat_layouts: 88HIJ**,L0J0J0LLrc@tj|j|j_t t |jj}tjd|jj|j|dt|S)Nrr) rtrBrrrremove_nested_packages remove_stubsrr_ensure_no_accidental_inclusionr0)r top_levels rrz&ConfigDiscovery._analyse_flat_packagesso499$..I *< 8J8J+KL  +DII,>,>+?@A ,,Y CIrc@tj|j|j_t j d|jj|j|jjdt|jjS)Nrmodules) rrBrrrrrrr0rs rrz%ConfigDiscovery._analyse_flat_modulessk5::4>>J  -dii.B.B-CDE ,,TYY-A-A9MDII(())rclt|dkDr&ddlm}ddlm}d|d|d|d}|||y) 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. )leninspectrsetuptools.errorsr)r detectedkindrrmsgs rrz/ConfigDiscovery._ensure_no_accidental_inclusionsU x=1  ( ?)$/MhZXM NRF S C( 6 6) rc|jjjs|jjrytjd|j xs|j }|r||jj_yy)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)rmetadatarrr#_find_name_single_package_or_module_find_name_from_packages)r rs rrzConfigDiscovery.analyse_namesq 99   " "diinn  KL  4 4 6 /,,.  &*DII   # rcdD]P}t|j|dxsg}|s!t|dk(s0tjd|d|dcSy)zExactly one module or package)rrNr z&Single module/package detected, name: r)getattrrrrr)r fieldrs rrz3ConfigDiscovery._find_name_single_package_or_modulesV/EDIIud39rEUq B58*MNQx 0 rcR|jjsytt|jjt}|jj xsi}t |||j}|rtjd||Stjdy)zzlK L  JKrN)rr)r/r )r/dict[str, str])FTF)rr0r/r0)r/r0)rrHrr.)r/ str | None)r1r2r3r4r"rrpropertyrrr+rrrrrrrrrrrr5rrrr)s{'  &//%% *   $$2 M* 7.+"rrct|t}|dd}t|}tt|D]1\}t fd|Ds|j ||z dz 3|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'] rNc3FK|]}j|dywrEN startswith)r%otherrs rr(z)remove_nested_packages..s Ct%{+C!r )r r enumeratereversedr)r)rrrsizeirs @rrr sd ( $DQI t9DXd^,4 CC C MM$(Q, '- rct|Dcgc](}|jddjdr'|*c}Scc}w)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'] rErr)rr)rrs rrrs2 $ PC399S>!+<+E+Eh+OC PP Ps(55cZt|t}g}t|D]2\}tfd||dzdDsn|j 4|D]Rt ||}t jj|d}t jj|sPcSy)z0Find the parent package that is not a namespace.rc3FK|]}|jdywrr)r%rrs rr(z&find_parent_package..-s G1<<4& +Grr Nrc) r rrrrYfind_package_pathrrrTrd)rrrcommon_ancestorsrpkg_pathinitrs @rr r &shC(HX&4GXa!eg5FGG %'!$T;Aww||Hm4 77>>$ K ! rcl|jd}tt|ddD]E}dj|d|}||vs||}t j j||g||dcS|j dxsd}t j j|g|jd|S)aGiven 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' rErNr/)rrangerrTrrr)rrrpartsr partial_nameparents rrr>s, JJsOE 3u:q" %xxbq * ; & .F77<<&=59= = &__R &BF 77<< =6<<#4 =u ==rc t|}t|j}|Dcic]'}|djg||j d)c}Scc}w)Nr%rE)rrr'rTr)r package_path parent_pkgsprefixrs rconstruct_package_dirr.`sQ(2K ,  % %FAL M#C4F4SYYs^45 5 MM Ms,A)rr r/r0)rr.rr r/rH)rrHr/rH)rrHrMapping[str, str]rr r/r)rr.rr/rr r/r.)rrHr+r r/r)-r4 __future__r itertoolsrfnmatchrrpathlibrtypingrr r r _distutils_hack.override_distutils_hackrjr distutilsrdistutils.utilrr.rJchain from_iterabler setuptoolsrrrr7rNrhrlrtrrrrrr rr.r5rrr<s!%N#  ' 3- __ * * '1 & & +"+"\*AG*AZ- 373.2T12Tj*\*<B __D$Q&7CJ0> >->9@>>DNr