bg>NdZddlmZddlZddlZddlZddlZddlZddlm Z m Z m Z ddl m Z ddlmZddlmZmZddlmZdd lmZdd lmZmZdd lmZmZmZmZd d lmZm Z!d dl"m#Z#d dl$m%Z%ddl&m'Z'er ddl(m)Z)ddl*m+Z+edZ,eddZ-GddZ. d[d\dZ/ d[d]d#Z0d^d&Z1d_d)Z2d`d+Z3 dadbd0Z4dcd4Z5ddd7Z6ded9Z7 dadfd<Z8 dadgd@Z9ddddAdhdDZ:didGZ;djdJZ dmdndVZ?GdWdXZ@GdYdZe e,e-fZAdS)oaiUtility functions to expand configuration directives or special values (such glob patterns). We can split the process of interpreting configuration files into 2 steps: 1. The parsing the file contents from strings to value objects that can be understand by Python (for example a string with a comma separated list of keywords into an actual Python list of strings). 2. The expansion (or post-processing) of these values according to the semantics ``setuptools`` assign to them (for example a configuration field with the ``file:`` directive should be expanded from a list of file paths to a single string with the contents of those files concatenated) This module focus on the second step, and therefore allow sharing the expansion functions among several configuration file formats. **PRIVATE MODULE**: API reserved for setuptools internal usage only. ) annotationsN)IterableIteratorMapping) ConfigParser)iglob) ModuleSpec all_suffixes)chain)Path) ModuleType TracebackType) TYPE_CHECKINGAnyCallableTypeVar)StrPath same_path)find_package_path)SetuptoolsWarning)DistutilsOptionError)Self) Distribution_K_V_coT) covariantc*eZdZdZddZdd Zdd Zd S) StaticModulez>Proxy to a module object that avoids executing arbitrary code.namestrspecr returnNonectjtj|j}t |t|` dSN) astparsepathlibr origin read_bytesvarsupdatelocalsself)r/r r"modules O/opt/cloudlinux/venv/lib64/python3.11/site-packages/setuptools/config/expand.py__init__zStaticModule.__init__7sP7< 44??AABB T &((### III!Iterator[tuple[ast.AST, ast.AST]]c#K|jjD]gttjrfdjDEd{V6ttjrjrjjfVhdS)Nc3*K|] }|jfVdSr&)value).0target statements r1 z1StaticModule._find_assignments..?s*VV&VY_5VVVVVVr3) r0body isinstancer'Assigntargets AnnAssignr7r9)r/r:s @r1_find_assignmentszStaticModule._find_assignments<s) : :I)SZ00 :VVVVIDUVVVVVVVVVVVIs}55 :)/ : '9999  : :r3attrc tfd|DS#t$r}t|jd|d}~wwxYw)zHAttempt to load an attribute "statically", via :func:`ast.literal_eval`.c3K|]@\}}t|tjr!|jk*tj|VAdSr&)r=r'Nameid literal_eval)r8r9r7rBs r1r;z+StaticModule.__getattr__..Fsa!FEfch//5;I4E4E ''4E4E4E4Er3z has no attribute N)nextrA ExceptionAttributeErrorr )r/rBes ` r1 __getattr__zStaticModule.__getattr__Cs P%)%;%;%=%=   P P P DI!G!G!G!GHHa O Ps,0 AAAN)r r!r"r r#r$)r#r4)rBr!)__name__ __module__ __qualname____doc__r2rArLr3r1rr4s\HH :::: P P P P P Pr3rpatterns Iterable[str]root_dirStrPath | Noner# list[str]c hd}g}ptj|D]tfd|Dr{tjtj}|tfdt|dDtj  tj d}| ||S)aExpand the list of glob patterns, but preserving relative paths. :param list[str] patterns: List of glob patterns :param str root_dir: Path to which globs should be relative (current directory by default) :rtype: list >*?[]{}c3 K|]}|vV dSr&rQ)r8charr7s r1r;z glob_relative..^s'99tu}999999r3c3K|]B}tj|tjdVCdS)/N)ospathrelpathreplacesepr8rcrTs r1r;z glob_relative..bsYGOOD(33;;BFCHHr3T) recursivera) rbgetcwdanyrcabspathjoinextendsortedrrdrerfappend)rRrTglob_charactersexpanded_values glob_pathrcr7s ` @r1 glob_relativersOs 544OO&29;;H)) 9999999 9 9 ) Xu(E(EFFI  " " %i4 @ @ @    7??5(33;;BFCHHD  " "4 ( ( ( ( r3 filepathsStrPath | Iterable[StrPath]r!cddlm}tjptjfd||D}dfdt|DS)zReturn the content of the files concatenated using `` `` as str This function is sandboxed and won't reach anything outside ``root_dir`` (By default ``root_dir`` is the current directory). r)always_iterablec3XK|]$}tj|V%dSr&rbrcrlrgs r1r;zread_files..|s3VV4"',,x..VVVVVVr3 c3VK|]#}t|t|V$dSr&) _assert_local _read_filergs r1r;zread_files..}sO  x ( (4r3)more_itertoolsrwrbrcrkrirl_filter_existing_files)rtrTrw _filepathss ` r1 read_filesrps/.....wx629;;77HVVVV??9;U;UVVVJ 99*:66  r3Iterable[StrPath]Iterator[StrPath]c#K|D]>}tj|r|V&tjd|d?dS)NzFile z cannot be found)rbrcisfileremit)rtrcs r1rrseEE 7>>$   EJJJJ  "#C4#C#C#C D D D D EEr3filepathbytes | StrPathct|d5}|cdddS#1swxYwYdS)Nzutf-8)encoding)openread)rfs r1r}r}s h ) ) )Qvvxxs 377rcttj|ttj|jvrd|d|d}t |dS)NzCannot access z (or anything outside )T)r rbrcrkparentsr)rrTmsgs r1r|r|sg BGOOH % %&&d27??83L3L.M.M.UUUNxNNNNN"3''' 4r3 attr_desc package_dirMapping[str, str] | Nonerc|ptj}|d}|}d|}|pd}t |||}t||} tt|||S#t$r#t||}t||cYSwxYw)aReads the value of an attribute from a module. This function will try to read the attributed statically first (via :func:`ast.literal_eval`), and only evaluate the module if it fails. Examples: read_attr("package.attr") read_attr("package.module.attr") :param str attr_desc: Dot-separated string describing how to reach the attribute (see examples above) :param dict[str, str] package_dir: Mapping of package names to their location in disk (represented by paths relative to ``root_dir``). :param str root_dir: Path to directory containing all the packages in ``package_dir`` (current directory by default). :rtype: str .r2) rbristripsplitpoprl _find_module _find_specgetattrrrI _load_spec) rrrT attrs_path attr_name module_namercr"r0s r1 read_attrrs,&29;;H""((--J  I((:&&K+K  [( ; ;D k4 ( (D*|K66 BBB ***D+..vy)))))*s B***CCr module_pathr ctj||}|ptj|}|t ||Sr&) importlibutilspec_from_file_location find_specModuleNotFoundError)rrr"s r1rrsK > 1 1+{ K KD  89>++K88D |!+... Kr3r"r c t|d|}|tjvrtj|Stj|}|tj|<|jJ|j||S)NrM)rsysmodulesrrmodule_from_specloader exec_module)r"rr r0s r1rrsw 4[ 1 1D s{{4  ^ , ,T 2 2FCK ; " " "KF### Mr3 str | Nonect||pi|tjfdtD}t d|DdS)aFind the path to the module named ``module_name``, considering the ``package_dir`` in the build configuration and ``root_dir``. >>> tmp = getfixture('tmpdir') >>> _ = tmp.ensure("a/b/c.py") >>> _ = tmp.ensure("a/b/d/__init__.py") >>> r = lambda x: x.replace(str(tmp), "tmp").replace(os.sep, "/") >>> r(_find_module("a.b.c", None, tmp)) 'tmp/a/b/c.py' >>> r(_find_module("f.g.h", {"": "1", "f": "2", "f.g": "3", "f.g.h": "a/b/d"}, tmp)) 'tmp/a/b/d/__init__.py' c3jK|]-}|tjd|fV.dS)r2Nry)r8ext path_starts r1r;z_find_module..s`%%     rw||J8H38H8HIIJ%%%%%%r3c3XK|]%}tj|!|V&dSr&)rbrcr)r8xs r1r;z_find_module..s5<>%%%J <zcmdclass..s+ R R R41aA}Q X66 R R Rr3)items)rrrTs ``r1cmdclassrs, S R R R R6<<>> R R RRr3) namespacesfill_package_dirrTrdict[str, str] | Nonec  ddlm}m}ddlm}|sddlm}nddlm}|p tj}| ddg}g} |in|}t||| t d kr9t fd d|fDr| d d D]} t|| } |j| fi|} | | | rX|d | ks?tj| |s||| | | S) aWorks similarly to :func:`setuptools.find_packages`, but with all arguments given as keyword arguments. Moreover, ``where`` can be given as a list (the results will be simply concatenated). When the additional keyword argument ``namespaces`` is ``True``, it will behave like :func:`setuptools.find_namespace_packages`` (i.e. include implicit namespaces as per :pep:`420`). The ``where`` argument will be considered relative to ``root_dir`` (or the current working directory when ``root_dir`` is not given). If the ``fill_package_dir`` argument is passed, this function will consider it as a similar data structure to the ``package_dir`` configuration parameter add fill-in any missing package location. :rtype: list r)rwunique_everseen)construct_package_dir) PackageFinder)PEP420PackageFinderwhererNrc3FK|]}td| VdS)rN) _same_path)r8rsearchs r1r;z find_packages...s4VVJvay!$<$< <VVVVVVr3)r~rwrsetuptools.discoveryrrrrbcurdirrlistlenall setdefault _nest_pathfindrmgetrcsamefiler-)rrrTkwargsrwrrrrpackagesrc package_pathpkgsrs @r1 find_packagesrs0@???????:::::: N6666666MMMMMM$29H JJw & &EH-5rr;K ////%"8"899 : :F 6{{aCVVVVsHoVVVVV##Bq 222GG!(D11 !}!,99&99  G   $ $ , ,0@0@x0X0X ,  # #$9$9$$E$E F F F Or3parentrcc|dvr|ntj||}tj|S)N>rr)rbrcrlnormpath)rrcs r1rr=s;Y&&66BGLL,F,FD 7  D ! !!r3r7$Callable | Iterable[str | int] | strct|r |n|}t|tr|St|dr(dt t|Sd|zS)z`When getting the version directly from an attribute, it should be normalised to string. __iter__rz%s)callabler=r!hasattrrlmap)r7_values r1versionrBsm! 2UUWWWUF&# vz""*xxC(())) &=r3 package_datadictc>d|vr|d|d<|S)NrXr)r)rs r1canonic_package_datarOs+ l'++C00 R r3 data_files list | dictlist[tuple[str, list[str]]]crt|tr|Sfd|DS)zFor compatibility with ``setup.py``, ``data_files`` should be a list of pairs instead of a dict. This function also expands glob patterns. c:g|]\}}|t|fSrQ)rs)r8destrRrTs r1 z&canonic_data_files..`s<    D( }Xx001   r3)r=rr)rrTs `r1canonic_data_filesrUsT*d##    (..00   r3 entry-pointstext text_sourcedict[str, dict[str, str]]ctdd}t|_|||d|D}||jd|S)a?Given the contents of entry-points file, process it into a 2-level dictionary (``dict[str, dict[str, str]]``). The first level keys are entry-point groups, the second level keys are entry-point names, and the second level values are references to objects (that correspond to the entry-point value). N)=)default_section delimiterscXi|]'\}}|t|(SrQ)rr)r8rrs r1rz entry_points..ss, < < >> def obtain_mapping(): ... print("Running expensive function!") ... return {"key": "value", "other key": "other value"} >>> mapping = LazyMappingProxy(obtain_mapping) >>> mapping["key"] Running expensive function! 'value' >>> mapping["other key"] 'other value' obtain_mapping_value Callable[[], Mapping[_K, _V_co]]r#r$c"||_d|_dSr&)_obtainr)r/r(s r1r2zLazyMappingProxy.__init__s+ 15 r3Mapping[_K, _V_co]cP|j||_|jSr&)rr+rs r1_targetzLazyMappingProxy._targets! ; ,,..DK{r3keyrrc6||Sr&)r.)r/r/s r1 __getitem__zLazyMappingProxy.__getitem__s||~~c""r3intcDt|Sr&)rr.rs r1__len__zLazyMappingProxy.__len__s4<<>>"""r3 Iterator[_K]cDt|Sr&)iterr.rs r1rzLazyMappingProxy.__iter__sDLLNN###r3N)r(r)r#r$)r#r,)r/rr#r)r#r2)r#r5) rMrNrOrPr2r.r1r4rrQr3r1r%r%s  6666 ########$$$$$$r3r%r&)rRrSrTrUr#rV)rtrurTrUr#r!)rtrr#r)rrr#r!)rrrTr!)NN)rr!rrrTrUr#r)rr!rrUr#r )r"r rr!r#r )rr!rrrTrr#r)rr!rrrTrUr#r)rrrrrTrUr#r)rrrTrUr#rV)rrrcrr#r!)r7rr#r!)rrr#r)rrrTrUr#r)r)rr!rr!r#r)BrP __future__rr'rrbr)rcollections.abcrrr configparserrglobrimportlib.machineryr r itertoolsr r typesr rtypingrrrr_pathrrr discoveryrwarningsrdistutils.errorsrtyping_extensionsrsetuptools.distrrrrrsrrr}r|rrrrrrrrrrrr r r%rQr3r1rFs(#"""""   7777777777%%%%%%88888888++++++++88888888888844444444))))))((((((111111-&&&&&&,,,,,, WT]]4(((PPPPPPPP89=DHL(EEEE -1##*#*#*#*#*LDDDD2-1# ' ' ' ' '$-1#SSSSS.2# 444444n""""    9=$#1$(7(7(7(7(7(7(7(7V$$$$$wr5y)$$$$$r3