_dR pdZddlZddlZddlmZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZddlZddlmZddlmZeeej2fZe eZej8j:Ze rdd lm Z d ed e!fd Z"Gd dZ#GddZ$Gdde$Z%Gdde%Z&Gdde$Z'Gdde&Z(Gdde'Z)deded e efdZ*GddZ+d e ed e efd!Z,d e ed e efd"Z-d e ed#eeefd$ed eefd%Z.d&ed#eeefd$ed efd'Z/d e ed(ed e eeffd)Z0y)*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_CHECKINGDictIterableIteratorListMappingOptionalTupleUnion)log) convert_path) Distributionpathreturnc\tjj|jSN)osrbasename isidentifier)rs 6/usr/lib/python3/dist-packages/setuptools/discovery.py _valid_namerGs 77  D ! . . 00c<eZdZdZdefdZdedefdZdedefdZy) _Filterz Given a list of patterns, create a callable that will be true only if the input matches at least one of the patterns. patternsc8tj||_yr)dictfromkeys _patterns)selfrs r__init__z_Filter.__init__Rsx0ritemrc@tfd|jDS)Nc36K|]}t|ywrr).0patr&s r z#_Filter.__call__..VsDc;tS)Ds)anyr#r$r&s `r__call__z_Filter.__call__UsDT^^DDDrc||jvSr)r#r-s r __contains__z_Filter.__contains__Xst~~%%rN) __name__ __module__ __qualname____doc__strr%boolr.r0rrrrLs< 1#1ESETE&&&rrc eZdZUdZdZeedfed<dZeedfed<e d de de ede ed e efd Z e de deded efd Zy )_Finderz@Base class that exposes functionality for module/package findersr7.ALWAYS_EXCLUDEDEFAULT_EXCLUDEwhereexcludeincluderc |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'. )r;list _find_iterrr5rr:clsr<r=r>s rfindz _Finder.findbsW40S00 NNSZ(6++6g6!   rctr)NotImplementedErrorrBs rrAz_Finder._find_iters!!rN).r7)*)r1r2r3r4r:rr5__annotations__r; classmethod_Pathr r rDrStrIterrAr7rrr9r9\sJ&(NE#s(O(')OU38_)!#!'    #  #  c    D"u"w""W""rr9c TeZdZdZdZededededefdZ e ded e de fd Z y ) 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]}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) followlinksNrGrH.*) rwalkr5rjoinrelpathreplacesep_looks_like_packageappend) rCr<r=r>rootdirsfilesall_dirsdir full_pathrel_pathpackages rrAzPackageFinder._find_iters "$U!F ! D$AwHDG !GGLLs3 77??9e<"**277;;<#:S%<%A%AAAArrNc*eZdZedededefdZy)PEP420PackageFinder_pathrbrcy)NTr7)rirbs rrXz'PEP420PackageFinder._looks_like_packagesrN)r1r2r3rfrKr5r6rXr7rrrhrhs)5rrhc BeZdZdZededededefdZe e Z y) ModuleFinderzYFind isolated Python modules. This function will **not** recurse subdirectories. r<r=r>rc#6Kttjj|dD]i}tjj tjj |\}}|j |sT||s]||rf|kyw)Nz*.py)rrrrTsplitextr_looks_like_module)rCr<r=r>filemodule_exts rrAzModuleFinder._find_itersseV45 D77++BGG,<,s&GaS8}&Gsri package_namerc|jd}|djxs|djd}|xrtd|ddDS)NrGr-stubsc3<K|]}|jywr)r)r)names rr+z>FlatLayoutPackageFinder._looks_like_package..s(S):):)<(Ss)splitrendswithall)rirnamesroot_pkg_is_valids rrXz+FlatLayoutPackageFinder._looks_like_packagesU""3'!!H113RuQx7H7H7R SS(Sqr(S%SSrN) r1r2r3_EXCLUDEtuple chain_iterr;rfrKr5r6rXr7rrrtrtsP'HRJ&Gh&GGHO T5TTTTrrtceZdZdZy)FlatLayoutModuleFinder)setupconftestrrrrrtoxfilenoxfilepavementdodorrz[Ss][Cc]onstruct conanfilemanagerrrrrN)r1r2r3r;r7rrrr sO4*rrroot_pkgpkg_dirctj|}|g|Dcgc]}dj||fc}zScc}w)NrG)rhrDrT)rrnestedns r_find_packages_withinr's: % %g .F :&AQ8Q-0A AAAs;ceZdZdZddZdZdZedefdZ ede e e ffdZ ddZ d edefd Zd edefd Zdefd Zdefd ZdefdZdefdZdefdZdee de fdZdZdee fdZdee fdZy)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__1s   !&rcd|_y)z+Internal API to disable automatic discoveryTN)rr$s r_disablezConfigDiscovery._disable7s 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_modules;s "&rrcR|jjxstjSr)rsrc_rootrcurdirrs r _root_dirzConfigDiscovery._root_dirGsyy!!.RYY.rc^|jjiS|jjSr)r package_dirrs r _package_dirzConfigDiscovery._package_dirLs' 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__Rs? E>t||t~~  $$%78      rrc(|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_specifiedgs/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 setdefaultrrrrhrDrrlr)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) rtrDrrrremove_nested_packages remove_stubsrr_ensure_no_accidental_inclusionr6)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) rrDrrrrrrr6rs rrz%ConfigDiscovery._analyse_flat_modulessk5::4>>J  -dii.B.B-CDE ,,TYY-A-A9MDII(())rdetectedkindclt|dkDr&ddlm}ddlm}d|d|d|d}|||y) 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)r$rrrrmsgs 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)rrNrz&Single module/package detected, name: r)getattrrrrr)r$fieldrs rrz3ConfigDiscovery._find_name_single_package_or_modules[/ EDIIud39rEUq B58*MNQx  rcR|jjsytt|jjt}|jj xsi}t |||j}|rtjd||Stjdy)zzlK L  JKrN)rr)FTF)r1r2r3r4r%rrpropertyrKrrr5rr.r6rrrrrrrr rrr rrr7rrrr,s'  &/5//%d38n%% *       $ 4 $$$T2 Md M*t* 7S 77.+"Xc](3-rrrct|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'] r Nc3FK|]}j|dywrGN startswith)r)otherrs rr+z)remove_nested_packages..s Ct%{+C!r)r r enumeratereversedr,r)rrrsizeirs @rrrsi ( $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'] rGrr)rr)rrs rrr s2 $ PC399S>!+<+E+Eh+OC PP Ps(55rrcZt|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.r c3FK|]}|jdywrr)r)rrs rr+z&find_parent_package..0s G1<<4& +GrrNrd) r rrrrYfind_package_pathrrrTre)rrrcommon_ancestorsrpkg_pathinitrs @rr r )shC(HX&&4GXa!eg5FGG %&!$T;Aww||Hm4 77>>$ K  rrcl|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' rGrNr/)rrangerrTrrr)rrrpartsr partial_nameparents rrrAs, JJsOE 3u:q" %>xxbq * ; & .F77<<&=59= = >__R &BF 77<< =6<<#4 =u ==r package_pathc t|}t|j}|Dcic]'}|djg||j d)c}Scc}w)Nr$rG)rrr&rTr)rr) parent_pkgsprefixrs rconstruct_package_dirr-csQ(2K ,  % %FAL M#C4F4SYYs^45 5 MM Ms,A)1r4 itertoolsrfnmatchrrpathlibrtypingrrr r r r r rr_distutils_hack.override_distutils_hack distutilsrdistutils.utilrr5PathLikerKrLchain from_iterabler setuptoolsrr6rrr9rNrhrlrtrrrrrr rr-r7rrr:s%N     ' c2;; 3- __ * * '1e11 & & +"+"\*AG*AZ- 373.2T12Tj*\*<BCB%BDIB __DT#Y49$Q49QcQ3i&-c3h&7CH c]0> >#CH->9>>>DNDINUNtCQTH~Nr