prhRQ dZddlZddlZddlmZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZddlZddlmZddlmZeeejfZe egefZe eZejj Z!e rdd l"m#Z#d ed efd Z$Gd dZ%Gdde%Z&Gdde&Z'Gdde%Z(Gdde'Z)Gdde(Z*deded eefdZ+GddZ,deed eefdZ-deed eefd Z.deed!eeefd"ed eefd#Z/d$ed!eeefd"ed efd%Z0deed&ed e eeffd'Z1dS)(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 N fnmatchcase)glob)Path) TYPE_CHECKINGCallableDictIterableIteratorListMappingOptionalTupleUnion)log) convert_path) Distributionpathreturncdtj|SN)osrbasename isidentifier)rs `/var/lib/jenkins/jobs/Dev/workspace/my-venv/lib/python3.11/site-packages/setuptools/discovery.py _valid_namerIs$ 7  D ! ! . . 0 00c eZdZUdZdZeedfed<dZeedfed<e dde d e ed e ed e efd Z e de d ed ed efd Zeded efdZdS)_Finderz@Base class that exposes functionality for module/package finders.ALWAYS_EXCLUDEDEFAULT_EXCLUDE.*whereexcludeincluderc |p|j}t|tt ||jg|j|R|j|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'. )r"list _find_iterrstr _build_filterr!clsr&r'r(s rfindz _Finder.findTsp40S0 NNSZZ((!!@3#5@@@@!!7+     rctr)NotImplementedErrorr.s rr+z_Finder._find_iterws!!rpatternscfdS)z Given a list of patterns, return a callable that will be true only if the input matches at least one of the patterns. c<tfdDS)Nc38K|]}t|VdSrr).0patnames r z:_Finder._build_filter....s-KK3 D# 6 6KKKKKKr)any)r9r3s`rz'_Finder._build_filter..s%CKKKK(KKKKKrr )r3s`rr-z_Finder._build_filter{s LKKKKrN)r#r r$)__name__ __module__ __qualname____doc__r!rr,__annotations__r" classmethod_Pathr r r0_FilterStrIterr+ staticmethodr-r rrrrNsJJ&(NE#s(O(((')OU38_)))!#!'     #  #  c    [  D"u"w""W"""["LLLLL\LLLrrc beZdZdZdZededededefdZ e ded e de fd Z d S) PackageFinderzI Generate a list of all Python packages found within a directory )ez_setupz *__pycache__r&r'r(rc#Ktjt|dD]\}}}|dd}g|dd<|D]}tj||} tj| |} | tjjd} d|vs|| | s|| r|| s| V| |dS)zy All the packages found in 'where' that pass the 'include' filter, but not the 'exclude' filter. T) followlinksNr#) rwalkr,rjoinrelpathreplacesep_looks_like_packageappend) r/r&r'r(rootdirsfilesall_dirsdir full_pathrel_pathpackages rr+zPackageFinder._find_iters "$U!F!F!F ! ! D$AAAwHDG ! !GLLs33 7??9e<<"**27;<<#::S%<%r?r@r!rBrCrDrEr+rFr,boolrQr rrrHrHs2N!u!w!!W!!![!6A%AAAAA\AAArrHc2eZdZedededefdZdS)PEP420PackageFinder_pathr[rcdS)NTr )rbr[s rrQz'PEP420PackageFinder._looks_like_packagestrN)r=r>r?rFrCr,r_rQr rrrarasG5\rrac PeZdZdZededededefdZe e Z dS) ModuleFinderzYFind isolated Python modules. This function will **not** recurse subdirectories. r&r'r(rc#HKttj|dD]q}tjtj|\}}||sW||r||s|VrdS)Nz*.py)rrrrMsplitextr_looks_like_module)r/r&r'r(filemodule_exts rr+zModuleFinder._find_iterseV4455  D7++BG,<,r?r@rBrCrDrEr+rFrrhr rrrereshuwW[&k22rrecteZdZdZeedeDZ edede de fdZ dS)FlatLayoutPackageFinder) cibindocdocs documentationmanpagesnews changelogtesttests unit_test unit_testsexampleexamplesscriptstoolsutilutilspythonbuilddistvenvenv requirementstasksfabfile site_scons benchmark benchmarksexercise exercises[._]*c#$K|] }||dfV dS)z.*Nr )r7ps rr:z!FlatLayoutPackageFinder.s,&G&Ga888}&G&G&G&G&G&Grrb package_namerc|d}|dp|dd}|o td|ddDS)Nr#r-stubsc3>K|]}|VdSr)r)r7r9s rr:z>FlatLayoutPackageFinder._looks_like_package..s.(S(S):):)<)<(S(S(S(S(S(Sr)splitrendswithall)rbrnamesroot_pkg_is_valids rrQz+FlatLayoutPackageFinder._looks_like_packagesl""3''!!H1133RuQx7H7H7R7R SS(S(Sqrr(S(S(S%S%SSrN) r=r>r?_EXCLUDEtuple chain_iterr"rFrCr,r_rQr rrrmrms$HLeJJ&G&Gh&G&G&GGGHHO T5TTTTT\TTTrrmceZdZdZdS)FlatLayoutModuleFinder)setupconftestrvrwrzr{rtoxfilenoxfilepavementdodorrz[Ss][Cc]onstruct conanfilemanagerrrrhtmlcovrN)r=r>r?r"r rrrrsO6*)rrroot_pkgpkg_dirc\t|}gfd|DzS)Nc>g|]}d|fS)r#)rM)r7nrs r z)_find_packages_within..s)AAAQ8Q-00AAAr)rar0)rrnesteds` r_find_packages_withinrs8 % %g . .F :AAAA&AAA AArc$eZdZdZddZdZdZedefdZ ede e e ffd Z dd Z d edefdZd edefdZdefdZdefdZdefdZdefdZdefdZdee de fdZdZdee fdZdee fdZdS)ConfigDiscoveryzFill-in metadata and options that can be automatically derived (from other metadata/options, the file system or conventions) distributionrc>||_d|_d|_d|_dS)NF)r_called _disabled_skip_ext_modules)selfrs r__init__zConfigDiscovery.__init__%s%   !&rcd|_dS)z+Internal API to disable automatic discoveryTN)rrs r_disablezConfigDiscovery._disable+s rcd|_dS)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_modules/s"&rrc2|jjp tjSr)rsrc_rootrcurdirrs r _root_dirzConfigDiscovery._root_dir;sy!.RY.rc6|jjiS|jjSr)r package_dirrs r _package_dirzConfigDiscovery._package_dir@s 9 (Iy$$rFTc|dur|js|jrdS|||r|d|_dS)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)rforcer9ignore_ext_moduless r__call__zConfigDiscovery.__call__FsX E>>t|>t~> F $$%7888        rrc|p|j}|jjdup| }|jjdup0|jjdup"|p t |jdo |jjS)zF``True`` if the user has specified some form of package/module listingN configuration)rr ext_modulespackages py_moduleshasattrr)rrrs r_explicitly_specifiedz%ConfigDiscovery._explicitly_specified[sw/I43I90D8N.sU  Z "#rw||Hj'I'I J J      rdiscovered packages -- T) rcopypoprrrritemsr*rr)rrpkgsrs @rrz(ConfigDiscovery._analyse_explicit_layoutys',,.. D!!!> 5 J[JJKKK    #.#4#4#6#6     "$ZZ  @DI,>@@AAAtrc|j}tj|j|dd}tj|sdStjd|| dtj |||j _ t||j _t ||j _tjd|j jtjd|j jdS)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)rrrrMrgetisdirrr setdefaultrrrrar0rrer)rrsrc_dirs rrz#ConfigDiscovery._analyse_src_layouts' ',,t~{r5/I/IJJw}}W%% 5 AAABBBr27#3#3G#<#<=== + 055g>> +0099  @DI,>@@AAA Ddi.BDDEEEtrctjd|j|p|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_layoutsB IIIJJJ**,,L0J0J0L0LLrc,t|j|j_t t |jj}tjd|jj| |dt|S)Nrr) rmr0rrrremove_nested_packages remove_stubsrr_ensure_no_accidental_inclusionr_)r top_levels rrz&ConfigDiscovery._analyse_flat_packagessv499$.II *< 8J+K+KLL  @DI,>@@AAA ,,Y CCCIrct|j|j_t jd|jj||jjdt|jjS)Nrmodules) rr0rrrrrrr_rs rrz%ConfigDiscovery._analyse_flat_modulessh5::4>JJ  Ddi.BDDEEE ,,TY-A9MMMDI()))rdetectedkindct|dkr,ddlm}ddlm}d|d|d|d}|||dS) Nrr)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)rrrrrmsgs rrz/ConfigDiscovery._ensure_no_accidental_inclusions x==1   ( ( ( ( ( ( ? ? ? ? ? ?$h NR C(' 66 6)  rc|jjjs |jjrdStjd|p|}|r||jj_dSdS)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)rmetadatar9rr#_find_name_single_package_or_module_find_name_from_packages)rr9s rrzConfigDiscovery.analyse_names 9  " din 4 KLLL  4 4 6 6 /,,..   +&*DI  # # # + +rcdD]V}t|j|dpg}|r:t|dkr'tjd|d|dcSWdS)zExactly one module or package)rrNrz&Single module/package detected, name: r)getattrrrrr)rfieldrs rrz3ConfigDiscovery._find_name_single_package_or_moduleso/  EDIud339rE Uq M58MMNNNQxtrc"|jjsdStt|jjt}|jjpi}t |||j}|rtj d||Stj ddS)zr?r@rrrpropertyrCrr r,rrr_rrrrrrrr rrrrrr rrrr s''''  & & &/5///X/%d38n%%%X% *          $ 4    $$$T2 Md M M M M*t**** 7S 77777.+++"Xc](3-rrrct|t}|dd}t|}tt|D];\}t fd|Dr|||z dz <|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'] rNc3HK|]}|dVdSr#N startswith)r7otherr9s rr:z)remove_nested_packages.. s5CCt%{{{++CCCCCCrr)rr enumeratereversedr;r)rrrsizeir9s @rrrs ( $ $ $DQQQI t99DXd^^,,((4 CCCCCCC C C ( MM$(Q, ' ' ' rcd|DS)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'] cng|]2}|ddd0|3S)r#rr)rr)r7rs rrz remove_stubs..s: P P PC399S>>!+<+E+Eh+O+O PC P P Prr )rs rrrs Q P8 P P PPrrrct|t}g}t|D]B\}tfd||dzdDsn|C|D]Vt ||}t j|d}t j |rcSWdS)z0Find the parent package that is not a namespace.rc3HK|]}|dVdSr r)r7rr9s rr:z&find_parent_package..#s5DD1<<4 ++DDDDDDrrNr]) rrrrrRfind_package_pathrrrMr^)rrrcommon_ancestorsrpkg_pathinitr9s @rrrshC(((HX&&&&4DDDDXacdd^DDDDD  E%%%% $T;AAw||Hm44 7>>$   KKK  4rr9c|d}tt|ddD]M}d|d|}||vr*||}t jj||g||dRcSN|dpd}t jj|g|d|RS)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' r#rNr/)rrangerrMrrr)r9rrpartsr partial_nameparents rrr4s, JJsOOE 3u::q" % %>>xxbqb ** ; & & .F7<&=59=== = = = '__R &BF 7< =6<<#4#4 =u = = ==r package_pathcft|}t|jfd|DS)Nc ji|]/}|dg|d0S)rr#)rMr)r7rprefixs r z)construct_package_dir..Ys< M M M#C4F4SYYs^^455 M M Mr)rrr!)rr$ parent_pkgsr's @rconstruct_package_dirr*Vs:(22K ,   %F M M M M M M MMr)2r@ itertoolsrfnmatchrrpathlibrtypingrrr r r r r rrr_distutils_hack.override_distutils_hack distutilsrdistutils.utilrr,PathLikerCr_rDrEchain from_iterabler setuptoolsrrrrHrarermrrrrrrrr*r rrr7s%%N                          '''''' c2; C5$;  3- _ * (''''''1e11111 3L3L3L3L3L3L3L3Ll&A&A&A&A&AG&A&A&AR- 333337333./T/T/T/T/T1/T/T/Td*****\***>BCB%BDIBBBB ^^^^^^^^BT#Y49$Q49QcQQQQ3i&-c3h&7CH c]0> >#CH->9>>>>>>DNDINUNtCQTH~NNNNNNr