bg SdZddlmZddlZddlZddlmZmZmZddl m Z ddl m Z ddl m Z ddlmZmZddlZd d lmZdd lmZdd lmZerdd lmZejjZd5dZGddZGddZ Gdde Z!Gdde!Z"Gdde Z#Gdde"Z$Gdd e#Z%d6d%Z&Gd&d'Z'd7d)Z(d7d*Z)d8d/Z*d9d1Z+d:d4Z,dS);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)IterableIteratorMapping fnmatchcase)glob)Path) TYPE_CHECKINGClassVar)StrPath)log) convert_path) Distributionpathrreturnboolcdtj|SN)osrbasename isidentifier)rs K/opt/cloudlinux/venv/lib64/python3.11/site-packages/setuptools/discovery.py _valid_namer?s$ 7  D ! ! . . 0 00c*eZdZdZd dZd d Zd d Zd 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. patternsstrrNonecDt||_dSr)dictfromkeys _patterns)selfrs r__init__z_Filter.__init__Jsx00ritemrcDtfd|jDS)Nc38K|]}t|VdSrr).0patr(s r z#_Filter.__call__..Ns-DDc;tS))DDDDDDr)anyr%r&r(s `r__call__z_Filter.__call__Ms(DDDDT^DDDDDDrc||jvSr)r%r/s r __contains__z_Filter.__contains__Pst~%%rN)rr rr!)r(r rr)__name__ __module__ __qualname____doc__r'r0r2rrrrDs^ 1111EEEE&&&&&&rrcheZdZUdZdZded<dZded<e dddZeddZ dS)_Finderz@Base class that exposes functionality for module/package findersr7zClassVar[tuple[str, ...]]ALWAYS_EXCLUDEDEFAULT_EXCLUDE.*whererexclude Iterable[str]includer list[str]c |p|j}t|tt |t g|j|Rt |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_iterrr rr:clsr?r@rBs rfindz _Finder.findZsf40S0 NNSZZ((6+6g666!     rr Iterator[str]ctr)NotImplementedErrorrGs rrFz_Finder._find_iter}s "!rN)r<r7r=)r?rr@rArBrArrCr?rr@rrBrrrJ) r3r4r5r6r:__annotations__r; classmethodrIrFr7rrr9r9TsJJ02N222213O3333!#!'     [  D"""["""rr9cFeZdZdZdZedd ZeddZdS) PackageFinderzI Generate a list of all Python packages found within a directory )ez_setupz *__pycache__r?rr@rrBrrJc#Ktjt|dD]\}}}|dd}g|dd<|D]}tj||} tj| |} | tjjd} d|vs|| | s|| r|| s| V| d|vs| d|vr| |dS)zy All the packages found in 'where' that pass the 'include' filter, but not the 'exclude' filter. T) followlinksNr<r>.*) rwalkr rjoinrelpathreplacesep_looks_like_packageappend) rHr?r@rBrootdirsfilesall_dirsdir full_pathrel_pathpackages rrFzPackageFinder._find_iters;"$U!F!F!F ! ! D$AAAwHDG ! !GLLs33 7??9e<<"**27;<<#::S%<%s,&G&Ga888}&G&G&G&G&G&Grrlr package_namer rrc|d}|dp|dd}|o td|ddDS)Nr<r-stubsc3>K|]}|VdSr)r)r+names rr-z>FlatLayoutPackageFinder._looks_like_package..s.(S(S):):)<)<(S(S(S(S(S(Srr )splitrendswithall)rlrnamesroot_pkg_is_valids rr[z+FlatLayoutPackageFinder._looks_like_packagesl""3''!!H1133RuQx7H7H7R7R SS(S(Sqrr(S(S(S%S%SSrN)rlrrr rr) r3r4r5_EXCLUDEtuple chain_iterr;rir[r7rrrwrwsm'HReJJ&G&Gh&G&G&GGGHHO TTT\TTTrrwceZdZdZdS)FlatLayoutModuleFinder)setupconftestrrrrrtoxfilenoxfilepavementdodorrz[Ss][Cc]onstruct conanfilemanagerrrrrN)r3r4r5r;r7rrrrsO4*)rrroot_pkgr pkg_dirrCc\t|}gfd|DzS)Nc>g|]}d|fS)r<)rW)r+nrs r z)_find_packages_within..'s)AAAQ8Q-00AAAr)rkrI)rrnesteds` r_find_packages_withinr%s8 % %g . .F :AAAA&AAA AArceZdZdZd%dZdZdZed&d Zed'd Z d(d)dZ d*dZ d*dZ d+dZ d+dZd+dZd+dZd+dZd,dZd-d Zd.d"Zd.d#Zd$S)/ConfigDiscoveryzFill-in metadata and options that can be automatically derived (from other metadata/options, the file system or conventions) distributionrrr!c>||_d|_d|_d|_dS)NF)r_called _disabled_skip_ext_modules)r&rs rr'zConfigDiscovery.__init__/s%   !&rcd|_dS)z+Internal API to disable automatic discoveryTN)rr&s r_disablezConfigDiscovery._disable5s 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_modules9s"&rrc2|jjp tjSr)rsrc_rootrcurdirrs r _root_dirzConfigDiscovery._root_dirEsy!.RY.rdict[str, str]c6|jjiS|jjSr)r package_dirrs r _package_dirzConfigDiscovery._package_dirJs 9 (Iy$$rFTforcerrignore_ext_modulesc|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)r&rrrs rr0zConfigDiscovery.__call__PsX E>>t|>t~> F $$%7888        rc|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)r&rrs r_explicitly_specifiedz%ConfigDiscovery._explicitly_specifiedgsw/I43I90D8N.sU  Z "#rw||Hj'I'I J J      rdiscovered packages -- T) rcopypoprrrritemsrErr)r&rpkgsrs @rrz(ConfigDiscovery._analyse_explicit_layouts',,.. 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)rrrrWrgetisdirrr setdefaultrrrrkrIrror)r&rsrc_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) rwrIrrrremove_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) rrIrrrrrrrrs rrz%ConfigDiscovery._analyse_flat_modulessh5::4>JJ  Ddi.BDDEEE ,,TY-A9MMMDI()))rdetectedrCkindr ct|dkr,ddlm}ddlm}d|d|d|d}|||dS) 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&rrrrmsgs 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)rmetadatarrr#_find_name_single_package_or_module_find_name_from_packages)r&rs rrzConfigDiscovery.analyse_names 9  " din  F KLLL  4 4 6 6 /,,..   +&*DI  # # # + +r str | NonecdD]V}t|j|dpg}|r:t|dkr'tjd|d|dcSWdS)zExactly one module or package)rrNr z&Single module/package detected, name: r)getattrrrrr)r&fieldrs rrz3ConfigDiscovery._find_name_single_package_or_moduleso/  EDIud339rE Uq M58MMNNNQxtrc"|jjsdStt|jjt}|jjpi}t |||j}|rtj d||Stj ddS)z>> 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)r+otherrs rr-z)remove_nested_packages..s5CCt%{{{++CCCCCCrr )rr enumeratereversedr.r)rrrsizeirs @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)r+rs rrz remove_stubs..&s: P P PC399S>>!+<+E+Eh+O+O PC P P Prr7)rs rrr s Q P8 P P PPrrMapping[str, str]rr ct|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|]}|dVdSrr)r+rrs rr-z&find_parent_package..0s5GG1<<4 ++GGGGGGrr Nrg) rrrrr\find_package_pathrrrWrh)rrrcommon_ancestorsrpkg_pathinitrs @rrr)shC(((HX&&&&4GGGGXa!egg5FGGGGG  E%%%% $T;AAw||Hm44 7>>$   KKK  4rrc|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/)rrangerrWrrr)rrrpartsr partial_nameparents rr%r%As, JJsOOE 3u::q" % %>>xxbqb ** ; & & .F7<&=59=== = = = '__R &BF 7< =6<<#4#4 =u = = ==r package_pathrcft|}t|jfd|DS)Nc ji|]/}|dg|d0S)r+r<)rWr)r+rprefixs r z)construct_package_dir..fs< M M M#C4F4SYYs^^455 M M Mr)rr r-)rr0 parent_pkgsr3s @rconstruct_package_dirr6cs:(22K ,   %F M M M M M M MMr)rrrr)rr rrrrC)rrCrrC)rrCrr"rrrr )rr rr"rrrr )rrCr0rrr)-r6 __future__r itertoolsrcollections.abcrrrfnmatchrr pathlibr typingr r _distutils_hack.override_distutils_hackrlr distutilsrdistutils.utilr setuptoolsrchain from_iterablerrrr9rQrkrorwrrrrrrr%r6r7rrrDs%%N#""""" 7777777777********''''''('''''' _ * 1111 & & & & & & & & -"-"-"-"-"-"-"-"`,A,A,A,A,AG,A,A,A^- 33333733322T2T2T2T2T12T2T2Tj*****\***<BBBB aaaaaaaaH$QQQQ0>>>>DNNNNNNr