o nh S@spdZddlmZddlZddlZddlmZmZmZddl m Z ddl m Z ddl m Z ddlmZmZddlZd d lmZdd lmZdd lmZerRdd lmZejjZdd+d,Z(d>d-d.Z)d?d3d4Z*d@d6d7Z+dAd:d;Z,dS)Bu_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) Distributionpathr returnboolcCstj|SN)osrbasename isidentifier)rrW/opt/prometheus-monitoring-scripts/lib/python3.10/site-packages/setuptools/discovery.py _valid_name?src@s.eZdZdZdddZdd d Zdd d ZdS)_Filterz Given a list of patterns, create a callable that will be true only if the input matches at least one of the patterns. patternsstrrNonecGst||_dSr)dictfromkeys _patterns)selfrrrr__init__Jsz_Filter.__init__itemrcstfdd|jDS)Nc3s|]}t|VqdSrr).0patr$rr Nsz#_Filter.__call__..)anyr!r"r$rr'r__call__Msz_Filter.__call__cCs ||jvSr)r!r*rrr __contains__Ps z_Filter.__contains__N)rrrr)r$rrr)__name__ __module__ __qualname____doc__r#r+r,rrrrrDs   rc@sNeZdZUdZdZded<dZded<e   ddddZedddZ dS)_Finderz@Base class that exposes functionality for module/package findersrzClassVar[tuple[str, ...]]ALWAYS_EXCLUDEDEFAULT_EXCLUDE.*wherer exclude Iterable[str]includer list[str]cCs8|p|j}t|tt|tg|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'. )r3list _find_iterrrrr2clsr7r8r:rrrfindZs  z _Finder.findr Iterator[str]cCstr)NotImplementedErrorr>rrrr=}sz_Finder._find_iterN)r4rr5)r7r r8r9r:r9rr;r7r r8rr:rrrA) r-r.r/r0r2__annotations__r3 classmethodr@r=rrrrr1Ts   "r1c@s0eZdZdZdZedd d ZedddZdS) PackageFinderzI Generate a list of all Python packages found within a directory )ez_setupz *__pycache__r7r r8rr:rrAc cstjt|ddD]V\}}}|dd}g|dd<|D]B}tj||} tj| |} | tjjd} d|vs?|| | s@q|| rK|| sK| V| d|vsY| d|vrZq| |qq dS)zy All the packages found in 'where' that pass the 'include' filter, but not the 'exclude' filter. T) followlinksNr4r6.*) rwalkrrjoinrelpathreplacesep_looks_like_packageappend) r?r7r8r:rootdirsfilesall_dirsdir full_pathrel_pathpackagerrrr=s"   zPackageFinder._find_iterr _package_namerrcCstjtj|dS)z%Does a directory look like a package? __init__.py)rrisfilerK)rrYrrrrOsz!PackageFinder._looks_like_packageNrC)rr rYrrr) r-r.r/r0r2rEr= staticmethodrOrrrrrFs !rFc@seZdZed ddZd S) PEP420PackageFinder_pathr rYrrrcCsdS)NTr)r^rYrrrrOsz'PEP420PackageFinder._looks_like_packageN)r^r rYrrr)r-r.r/r\rOrrrrr]sr]c@s&eZdZdZed d d ZeeZd S) ModuleFinderzYFind isolated Python modules. This function will **not** recurse subdirectories. r7r r8rr:rrAccsXttj|dD]}tjtj|\}}||sq ||r)||s)|Vq dS)Nz*.py)rrrrKsplitextr_looks_like_module)r?r7r8r:filemodule_extrrrr=s zModuleFinder._find_iterNrC) r-r.r/r0rEr=r\rrarrrrr_s   r_c@s6eZdZdZeeddeDZ ed d d Zd S)FlatLayoutPackageFinder)#cibindebiandocdocs documentationmanpagesnews newsfragments changelogtesttests unit_test unit_testsexampleexamplesscriptstoolsutilutilspythonbuilddistvenvenv requirementstasksfabfile site_scons benchmark benchmarksexercise exerciseshtmlcov[._]*ccs|] }||dfVqdS)rINr)r%prrrr(sz!FlatLayoutPackageFinder.r^r package_namerrrcCsB|d}|dp|dd}|o tdd|ddDS)Nr4r-stubscss|]}|VqdSr)r)r%namerrrr(sz>FlatLayoutPackageFinder._looks_like_package..r )splitrendswithall)r^rnamesroot_pkg_is_validrrrrOs z+FlatLayoutPackageFinder._looks_like_packageN)r^r rrrr) r-r.r/_EXCLUDEtuple chain_iterr3r\rOrrrrres )rec@seZdZdZdS)FlatLayoutModuleFinder)setupconftestrprqrtrur{toxfilenoxfilepavementdodorrz[Ss][Cc]onstruct conanfilemanagerrrrrN)r-r.r/r3rrrrrsrroot_pkgrpkg_dirr;cs"t|}gfdd|DS)Ncsg|] }d|fqS)r4)rKr%nrrr 'sz)_find_packages_within..)r]r@)rrnestedrrr_find_packages_within%s rc@seZdZdZd6ddZdd Zd d Zed7d dZed8ddZ d9d:ddZ d;ddZ d;ddZ dd.d/Zd?d1d2Zd?d3d4Zd5S)@ConfigDiscoveryzFill-in metadata and options that can be automatically derived (from other metadata/options, the file system or conventions) distributionrrrcCs||_d|_d|_d|_dS)NF)r|_called _disabled_skip_ext_modules)r"rrrrr#/s zConfigDiscovery.__init__cC d|_dS)z+Internal API to disable automatic discoveryTN)rr"rrr_disable5s zConfigDiscovery._disablecCr)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)rrrrr_ignore_ext_modules9s z#ConfigDiscovery._ignore_ext_modulesr cCs|jjptjSr)r|src_rootrcurdirrrrr _root_dirEszConfigDiscovery._root_dirdict[str, str]cCs|jjduriS|jjSr)r| package_dirrrrr _package_dirJs zConfigDiscovery._package_dirFTforcerrignore_ext_modulescCs8|dur |js |jr dS|||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"rrrrrrr+Ps    zConfigDiscovery.__call__cCsL|p|j}|jjdup | }|jjdup%|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"rrrrr_explicitly_specifiedgs    z%ConfigDiscovery._explicitly_specifiedcCs0||rdStd|p|p|S)NTzLNo `packages` or `py_modules` configuration, performing automatic discovery.)rrdebug_analyse_explicit_layout_analyse_src_layout_analyse_flat_layout)r"rrrrrts z'ConfigDiscovery._analyse_package_layoutcsr|j}|dd|j|sdStd|tfdd|D}t||j _ td|j j dS) zAThe user can explicitly give a package layout via ``package_dir``NFz(`explicit-layout` detected -- analysing c3s(|]\}}t|tj|VqdSr)rrrrK)r%pkg parent_dirroot_dirrrr(s  z;ConfigDiscovery._analyse_explicit_layout..discovered packages -- T) rcopypoprrrritemsr<r|r)r"rpkgsrrrrs    z(ConfigDiscovery._analyse_explicit_layoutcCs|j}tj|j|dd}tj|sdStd|| dtj |||j _ t ||j _t||j _td|j jtd|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)rrrrKrgetisdirrr setdefaultrr|rr]r@rr_r)r"rsrc_dirrrrrs  z#ConfigDiscovery._analyse_src_layoutcCs"td|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_modulesrrrrrs z$ConfigDiscovery._analyse_flat_layoutcCsHt|j|j_tt|jj}td|jj| |dt |S)Nrr) rer@rr|rremove_nested_packages remove_stubsrr_ensure_no_accidental_inclusionr)r" top_levelrrrrs  z&ConfigDiscovery._analyse_flat_packagescCs@t|j|j_td|jj||jjdt|jjS)Nrmodules) rr@rr|rrrrrrrrrrs z%ConfigDiscovery._analyse_flat_modulesdetectedr;kindrcCsLt|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"rrrrmsgrrrrs    z/ConfigDiscovery._ensure_no_accidental_inclusioncCsF|jjjs |jjr dStd|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)r|metadatarrr#_find_name_single_package_or_module_find_name_from_packages)r"rrrrrs zConfigDiscovery.analyse_name str | NonecCsPdD]#}t|j|dp g}|r%t|dkr%td|d|dSqdS)zExactly one module or package)rrNr z&Single module/package detected, name: r)getattrr|rrr)r"fieldrrrrrs z3ConfigDiscovery._find_name_single_package_or_modulecCs`|jjsdStt|jjtd}|jjpi}t|||j}|r)t d||St 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'] rNc3s |] }|dVqdSr4N startswith)r%otherrrrr(z)remove_nested_packages..r )rr enumeratereversedr)r)rrrsizeirrrrs  rcCsdd|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'] cSs$g|]}|ddds|qS)r4rr)rrr%rrrrr&s$z remove_stubs..r)rrrrr srrMapping[str, str]rrcst|td}g}t|D]\}tfdd||ddDs#n|q |D]t||}tj|d}tj |rDSq+dS)z0Find the parent package that is not a namespace.rc3s |] }|dVqdSrrrrrrr(0rz&find_parent_package..r NrZ) rrrrrPfind_package_pathrrrKr[)rrrcommon_ancestorsrpkg_pathinitrrrr)s "   rrcCs|d}tt|ddD]$}d|d|}||vr1||}tjj||g||dRSq |dp8d}tjj|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' r4rNr/)rrangerrKrrr)rrrpartsr partial_nameparentrrrrAs "r package_pathrcs$t|}t|jfdd|DS)Nc s&i|]}|dg|dqS)rr4)rKrrprefixrr fs&z)construct_package_dir..)rr r)rr parent_pkgsrrrconstruct_package_dircs r )rr rr)rrrr rr;)rr;rr;)rr;rrrr rr)rrrrrr rr)rr;rr rr)-r0 __future__r itertoolsrcollections.abcrrrfnmatchrrpathlibr typingr r _distutils_hack.override_distutils_hackr^r distutilsrdistutils.utilr setuptoolsrchain from_iterablerrrr1rFr]r_rerrrrrrrr rrrrs@ '        0/5  e  "