a „oe›Rã@sädZddlZddlZddlmZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZddlZddlmZddlmZeeejfZe eZejjZe r²dd lm Z ee!d œd d „Z"Gd d„dƒZ#Gdd„dƒZ$Gdd„de$ƒZ%Gdd„de%ƒZ&Gdd„de$ƒZ'Gdd„de&ƒZ(Gdd„de'ƒZ)eee edœdd„Z*Gdd„dƒZ+e ee ed œd!d"„Z,e ee ed œd#d$„Z-e eeeefeeed%œd&d'„Z.eeeefeed(œd)d*„Z/e eee eefd+œd,d-„Z0dS).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_CHECKINGÚDictÚIterableÚIteratorÚListÚMappingÚOptionalÚTupleÚUnion)Úlog)Ú convert_path)Ú Distribution)ÚpathÚreturncCstj |¡ ¡S©N)ÚosrÚbasenameÚ isidentifier)r©rú5C:\Program Files\Certbot\pkgs\setuptools\discovery.pyÚ _valid_nameGsrc@s>eZdZdZedœdd„Zeedœdd„Zeedœdd „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. )ÚpatternscGst |¡|_dSr)ÚdictÚfromkeysÚ _patterns)ÚselfrrrrÚ__init__Rsz_Filter.__init__)Úitemrcst‡fdd„|jDƒƒS)Nc3s|]}tˆ|ƒVqdSrr)Ú.0Úpat©r"rrÚ Vóz#_Filter.__call__..)Úanyr©r r"rr%rÚ__call__Usz_Filter.__call__cCs ||jvSr)rr)rrrÚ __contains__Xsz_Filter.__contains__N) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ústrr!Úboolr*r+rrrrrLsrc@sxeZdZUdZdZeedfed<dZeedfed<e de e ee ee edœd d „ƒZ e e eeedœd d „ƒZd S)Ú_Finderz@Base class that exposes functionality for module/package findersr.ÚALWAYS_EXCLUDEÚDEFAULT_EXCLUDEÚ.©Ú*©ÚwhereÚexcludeÚincludercCs8|p|j}t| tt|ƒƒtg|j¢|¢RŽ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'. )r4ÚlistÚ _find_iterrr0rr3©Úclsr9r:r;rrrÚfindbs  ýÿz _Finder.findcCst‚dSr)ÚNotImplementedErrorr>rrrr=…sz_Finder._find_iterN)r5rr6)r,r-r.r/r3r r0Ú__annotations__r4Ú classmethodÚ_Pathrr r@rÚStrIterr=rrrrr2\s üû"r2c@sBeZdZdZdZeeeeedœdd„ƒZ e ee e dœdd„ƒZ d S) Ú PackageFinderzI Generate a list of all Python packages found within a directory )Zez_setupz *__pycache__r8c csÄtjt|ƒdd�D]¬\}}}|dd…}g|dd…<|D]„}tj ||¡} tj | |¡} |  tjjd¡} d|vs8| | | ¡s~q8|| ƒr”|| ƒs”| V| ›d�|vs8| ›d�|vr²q8|  |¡q8qdS)zy All the packages found in 'where' that pass the 'include' filter, but not the 'exclude' filter. T)Ú followlinksNr5r7ú.*) rÚwalkr0rÚjoinÚrelpathÚreplaceÚsepÚ_looks_like_packageÚappend) r?r9r:r;ÚrootÚdirsÚfilesZall_dirsÚdirÚ full_pathZrel_pathÚpackagerrrr=‘s  zPackageFinder._find_iter)rÚ _package_namercCstj tj |d¡¡S)z%Does a directory look like a package?ú __init__.py)rrÚisfilerJ)rrVrrrrN±sz!PackageFinder._looks_like_packageN)r,r-r.r/r3rCrDrrEr=Ú staticmethodr0r1rNrrrrrFŠs rFc@s"eZdZeeeedœdd„ƒZdS)ÚPEP420PackageFinder)Ú_pathrVrcCsdS)NTr)r[rVrrrrN¸sz'PEP420PackageFinder._looks_like_packageN)r,r-r.rYrDr0r1rNrrrrrZ·srZc@s0eZdZdZeeeeedœdd„ƒZe e ƒZ dS)Ú ModuleFinderzYFind isolated Python modules. This function will **not** recurse subdirectories. r8ccsVttj |d¡ƒD]>}tj tj |¡¡\}}| |¡s:q||ƒr||ƒs|VqdS)Nz*.py)rrrrJÚsplitextrÚ_looks_like_module)r?r9r:r;ÚfileÚmoduleZ_extrrrr=Âs  zModuleFinder._find_iterN) r,r-r.r/rCrDrrEr=rYrr^rrrrr\½s r\c@s<eZdZdZeedd„eDƒƒƒZeee e dœdd„ƒZ dS)ÚFlatLayoutPackageFinder)#ZciÚbinZdebianÚdocZdocsZ documentationZmanpagesÚnewsZ newsfragmentsZ changelogÚtestÚtestsZ unit_testZ unit_testsÚexampleÚexamplesZscriptsZtoolsÚutilZutilsZpythonÚbuildÚdistÚvenvÚenvZ requirementsÚtasksÚfabfileZ site_sconsÚ benchmarkÚ benchmarksÚexerciseÚ exercisesZhtmlcovú[._]*ccs|]}||›d�fVqdS)rHNr)r#Úprrrr&þr'z!FlatLayoutPackageFinder.)r[Ú package_namercCsB| d¡}|d ¡p"|d d¡}|o@tdd„|dd…DƒƒS)Nr5rú-stubscss|]}| ¡VqdSr)r)r#Únamerrrr&r'z>FlatLayoutPackageFinder._looks_like_package..é)ÚsplitrÚendswithÚall)r[rvÚnamesZroot_pkg_is_validrrrrNs z+FlatLayoutPackageFinder._looks_like_packageN) r,r-r.Z_EXCLUDEÚtupleÚ chain_iterr4rYrDr0r1rNrrrrraÔs)rac@seZdZdZdS)ÚFlatLayoutModuleFinder)ZsetupZconftestrerfrgrhrjZtoxfileZnoxfileZpavementZdodornroz[Ss][Cc]onstructZ conanfileZmanagerprqrrrsrtN)r,r-r.r4rrrrr€ sr€)Úroot_pkgÚpkg_dirrcs"t |¡}ˆg‡fdd„|DƒS)Ncsg|]}d ˆ|f¡‘qS)r5)rJ©r#Ún©r�rrÚ )r'z)_find_packages_within..)rZr@)r�r‚Únestedrr…rÚ_find_packages_within's rˆc@s eZdZdZddœdd„Zdd„Zdd „Zeed œd d „ƒZ ee e e fd œd d„ƒZ d,dd„Z eedœdd„Zeedœdd„Zed œdd„Zed œdd„Zed œdd„Zed œdd„Zed œd d!„Zee e d"œd#d$„Zd%d&„Zee d œd'd(„Zee d œd)d*„Zd+S)-ÚConfigDiscoveryz…Fill-in metadata and options that can be automatically derived (from other metadata/options, the file system or conventions) r)Ú distributioncCs||_d|_d|_d|_dS)NF)rkÚ_calledÚ _disabledÚ_skip_ext_modules)r rŠrrrr!1szConfigDiscovery.__init__cCs d|_dS)z+Internal API to disable automatic discoveryTN)rŒ©r rrrÚ_disable7szConfigDiscovery._disablecCs d|_dS)aäInternal 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)r�rŽrrrÚ_ignore_ext_modules;s z#ConfigDiscovery._ignore_ext_modules)rcCs|jjp tjSr)rkZsrc_rootrÚcurdirrŽrrrÚ _root_dirGszConfigDiscovery._root_dircCs|jjduriS|jjSr)rkÚ package_dirrŽrrrÚ _package_dirLs zConfigDiscovery._package_dirFTcCs8|dur|js|jrdS| |¡|r.| ¡d|_dS)a±Automatically 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)r‹rŒÚ_analyse_package_layoutÚ analyse_name)r ÚforcerxÚignore_ext_modulesrrrr*Rs  zConfigDiscovery.__call__)r˜rcCsL|p|j}|jjdup| }|jjdupJ|jjdupJ|pJt|jdƒoJ|jjS)zF``True`` if the user has specified some form of package/module listingNÚ configuration)r�rkÚ ext_modulesÚpackagesÚ py_modulesÚhasattrr™)r r˜ršrrrÚ_explicitly_specifiedgs   ÿþ ûz%ConfigDiscovery._explicitly_specifiedcCs0| |¡rdSt d¡| ¡p.| ¡p.| ¡S)NTzLNo `packages` or `py_modules` configuration, performing automatic discovery.)ržrÚdebugÚ_analyse_explicit_layoutÚ_analyse_src_layoutÚ_analyse_flat_layout)r r˜rrrr•ts ÿÿüz'ConfigDiscovery._analyse_package_layoutcsr|j ¡}| dd¡|j‰|s$dSt d|›�¡t‡fdd„| ¡Dƒƒ}t|ƒ|j _ t d|j j ›�¡dS) zAThe user can explicitly give a package layout via ``package_dir``ÚNFz(`explicit-layout` detected -- analysing c3s&|]\}}t|tj ˆ|¡ƒVqdSr)rˆrrrJ)r#ÚpkgZ parent_dir©Úroot_dirrrr&�sÿz;ConfigDiscovery._analyse_explicit_layout..údiscovered packages -- T) r”ÚcopyÚpopr’rrŸrÚitemsr<rkr›)r r“Úpkgsrr¥rr †s   þ z(ConfigDiscovery._analyse_explicit_layoutcCs¢|j}tj |j| dd¡¡}tj |¡s.dSt d|›�¡|  dtj  |¡¡||j _ t  |¡|j _t |¡|j _t d|j j›�¡t d|j j›�¡dS)a®Try 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"``. r£ÚsrcFz#`src-layout` detected -- analysing r§údiscovered py_modules -- T)r”rrrJr’ÚgetÚisdirrrŸÚ setdefaultrrkr“rZr@r›r\rœ)r r“Zsrc_dirrrrr¡˜s  z#ConfigDiscovery._analyse_src_layoutcCs"t d|j›�¡| ¡p | ¡S)aÆTry 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 )rrŸr’Ú_analyse_flat_packagesÚ_analyse_flat_modulesrŽrrrr¢±s z$ConfigDiscovery._analyse_flat_layoutcCsHt |j¡|j_tt|jjƒƒ}t d|jj›�¡|  |d¡t |ƒS)Nr§r›) rar@r’rkr›Úremove_nested_packagesÚ remove_stubsrrŸÚ_ensure_no_accidental_inclusionr1)r Ú top_levelrrrr±¾s  z&ConfigDiscovery._analyse_flat_packagescCs@t |j¡|j_t d|jj›�¡| |jjd¡t|jjƒS)Nr­Úmodules) r€r@r’rkrœrrŸrµr1rŽrrrr²Åsz%ConfigDiscovery._analyse_flat_modules)ÚdetectedÚkindcCsLt|ƒdkrHddlm}ddlm}d|›d|›d|›d�}|||ƒƒ‚dS) Nryr)Ú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. )ÚlenÚinspectrºZsetuptools.errorsr»)r r¸r¹rºr»ÚmsgrrrrµËs   ûz/ConfigDiscovery._ensure_no_accidental_inclusioncCsB|jjjs|jjrdSt d¡| ¡p.| ¡}|r>||jj_dS)z”The 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)rkÚmetadatarxrrŸÚ#_find_name_single_package_or_moduleÚ_find_name_from_packages)r rxrrrr–âs þzConfigDiscovery.analyse_namecCsPdD]F}t|j|dƒpg}|rt|ƒdkrt d|d›�¡|dSqdS)zExactly one module or package)r›rœNryz&Single module/package detected, name: r)Úgetattrrkr¼rrŸ)r ZfieldrªrrrrÀós z3ConfigDiscovery._find_name_single_package_or_modulecCs`|jjs dStt|jjtd�ƒ}|jjp*i}t|||jƒ}|rRt  d|›�¡|St  d¡dS)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'] rÃNc3s|]}ˆ |›d�¡VqdS©r5N©Ú startswith)r#Úother©rxrrr&r'z)remove_nested_packages..ry)rÅr¼Ú enumerateÚreversedr(r©)r›r«r¶ÚsizeÚirrÍrr³s  r³cCsdd„|DƒS)z Remove 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|]}| d¡d d¡s|‘qS)r5rrw)rzr{©r#r¤rrrr†&r'z remove_stubs..r)r›rrrr´ sr´)r›r“r¦rcsŽt|td�}g}t|ƒD]8\}‰t‡fdd„||dd…DƒƒsFqR| ˆ¡q|D]2‰tˆ||ƒ}tj |d¡}tj  |¡rVˆSqVdS)z0Find the parent package that is not a namespace.rÃc3s|]}| ˆ›d�¡VqdSrÉrÊrƒrÍrrr&0r'z&find_parent_package..ryNrW) rÅr¼rÎr|rOÚfind_package_pathrrrJrX)r›r“r¦Zcommon_ancestorsrÑZpkg_pathÚinitrrÍrrÆ)s "    rÆ)rxr“r¦rcCs�| d¡}tt|ƒddƒD]H}d |d|…¡}||vr||}tjj||g||d…¢RŽSq| d¡ppd}tjj|g| d¡¢|¢RŽS)a—Given 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' r5réÿÿÿÿNr£ú/)rzÚranger¼rJrrr®)rxr“r¦ÚpartsrÑZ partial_nameÚparentrrrrÓAs $rÓ)r›Ú package_pathrcs$t|ƒ}t|ƒj‰‡fdd„|DƒS)Nc s&i|]}|d gˆ¢| d¡¢¡“qS)rÖr5)rJrzrÒ©ÚprefixrrÚ fr'z)construct_package_dir..)r³rrØ)r›rÚZ parent_pkgsrrÛrÚconstruct_package_dircs rÞ)1r/Ú itertoolsrÚfnmatchrrÚpathlibrÚtypingrrrr r r r r rZ_distutils_hack.overrideZ_distutils_hackZ distutilsrZdistutils.utilrr0ÚPathLikerDrEÚchainÚ from_iterablerZ setuptoolsrr1rrr2rFrZr\rar€rˆr‰r³r´rÆrÓrÞrrrrÚsD'   ,    .-5c þ þ "