_d@ 6dZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZddlmZmZmZmZmZmZmZmZmZmZmZmZddlmZdd lmZdd lm Z d d l!m"Z#d d l$m%Z%erddl&m'Z'ddl(m)Z)ddl*m+Z+ejXZ-ee.ej^fZ0edZ1eddZ2GddZ3 d@dee.dee0dee.fdZ4d@dee.e5ee0fde.fdZ6dee0dee0fdZ7dee5e0fde.fdZ8de0de.fd Z9 dAd!e.d"eee.e.fdee0fd#Z:d$e.d%ee0de fd&Z;d'e d$e.defd(Z dAd,ee.e.fd"eee.e.fdee0dee.effd-Z?dddd.d/eee.e.fdee0dee.fd0Z@d1e0d2e0de.fd3ZAd4eeeee.eBfe.fde.fd5ZCd6eDdeDfd7ZE d@d8eeFeDfdee0deee.ee.ffd9ZGdBd:e.dee.eDffd;ZHGd<d=ZIGd>d?ee1e2fZJy)CaiUtility 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. N)iglob) ConfigParser) ModuleSpec)chain) TYPE_CHECKINGCallableDictIterableIteratorListMappingOptionalTupleTypeVarUnioncast)Path) ModuleType)DistutilsOptionError) same_path)SetuptoolsWarning) Distribution)ConfigDiscovery)DistributionMetadata_K_VT) covariantcjeZdZdZdedefdZdeee je jffdZ dZ y) StaticModulez>Proxy to a module object that avoids executing arbitrary code.namespecctjtj|jj }t |jt|` yN) astparsepathlibrorigin read_bytesvarsupdatelocalsself)r-r!r"modules :/usr/lib/python3/dist-packages/setuptools/config/expand.py__init__zStaticModule.__init__Bs?7<< 4??AB T &(# Ireturnc#<K|jjD]|ttjrfdj DEd{;ttj sVjscjjf~y7Jw)Nc3:K|]}|jfywr$value).0target statements r/ z1StaticModule._find_assignments..JsV&VY__5Vs) r.body isinstancer%Assigntargets AnnAssignr6r8)r-r9s @r/_find_assignmentszStaticModule._find_assignmentsGsn)) :I)SZZ0VIDUDUVVVIs}}5)// ''99  :VsA BBB0 B=Bc tfd|jDS#t$r }t|jd|d}~wwxYw)zHAttempt to load an attribute "statically", via :func:`ast.literal_eval`.c3K|]E\}}t|tjr&|jk(rtj|Gywr$)r<r%Nameid literal_eval)r7r8r6attrs r/r:z+StaticModule.__getattr__..QsA!FEfchh/FII4E  'sA Az has no attribute N)nextr@ ExceptionAttributeErrorr!)r-rFes ` r/ __getattr__zStaticModule.__getattr__Ns] P%)%;%;%=   P DII;.@!GHa O Ps!% AA  AN) __name__ __module__ __qualname____doc__strrr0r rr%ASTr@rKr1r/r r ?sAHS  :8E#''3772B,C#D: Pr1r patternsroot_dirr2c hd}g}xstj|D]tfd|Drltjj tjj }|j tfdt|dDtjjjtjd}|j||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|]}|v ywr$rR)r7charr6s r/r:z glob_relative..is9tu}9sc3K|]B}tjj|jtjdDyw)/N)ospathrelpathreplacesepr7rarTs r/r:z glob_relative..ms9GGOOD(3;;BFFCHsAA T) recursiver_) r`getcwdanyraabspathjoinextendsortedrrbrcrdappend)rSrTglob_charactersexpanded_values glob_pathrar6s ` @r/ glob_relativerqZs5OO&299;H) 99 9 Xu(EFI  " " %i4 @ 77??5(3;;BFFCHD  " "4 ()" r1 filepathscddlm}tjj xstj fd||D}dj fdt|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_iterablec3^K|]$}tjj|&ywr$)r`rarjres r/r:zread_files..s V4"'',,x.Vs*- c3LK|]}t|r t|ywr$) _assert_local _read_fileres r/r:zread_files..s(  x ( 4s!$) setuptools.extern.more_itertoolsrtr`rarirgrj_filter_existing_files)rrrTrt _filepathss ` r/ read_filesr}{sXAwwx6299;7HV?9;UVJ 99*:6 r1c#K|D]?}tjj|r|'tjd|dAyw)NzFile z cannot be found)r`raisfileremit)rrras r/r{r{sDE 77>>$ J  " "U4(2B#C D EsAAfilepathc|tj|d5}|jcdddS#1swYyxYw)Nzutf-8)encoding)ioopenread)rfs r/ryrys0 G ,vvxs2;cttjj|ttjj|jvrd|d|d}t |y)NzCannot access z (or anything outside )T)rr`rariparentsr)rrTmsgs r/rxrxsW BGGOOH %&d277??83L.M.U.UUxl*@ AN"3'' r1 attr_desc package_dirct|xstj}|jjd}|j }dj |}|xsd}t |||\}}}t||} tt|||S#t$rt||} 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 .r0) r`rgstripsplitpoprj _find_module _find_specgetattrr rH _load_spec) rrrT attrs_path attr_name module_name _parent_pathrar"r.s r/ read_attrrs,&299;H"((-J I((:&K+K&2; X&V#L$ k4 (D*|K6 BB *D+.vy))*s=B!B76B7r module_pathctjj||}|xstjj|}| t ||Sr$) importlibutilspec_from_file_location find_specModuleNotFoundError)rrr"s r/rrsF >> 1 1+{ KD  89>>++K8D |!+.. Kr1r"ct|d|}|tjvrtj|Stjj |}|tj|<|j j||S)NrL)rsysmodulesrrmodule_from_specloader exec_module)r"rr!r.s r/rrsd 4[ 1D s{{{{4  ^^ , ,T 2FCKKKKF# Mr1cb|}|jd}|r|d|vrk||d}|jdd}t|dkDr)tjj ||d}|d}n|}dj |g|dd}n'd|vr#tjj ||d}tjj |g|jd}t |dtjj |dft|d } td | Dd} || |fS) a0Given a module (that could normally be imported by ``module_name`` after the build is complete), find the path to the parent directory where it is contained and the canonical name that could be used to import it considering the ``package_dir`` in the build configuration and ``root_dir`` rrr_Nz.pyz __init__.pyz.*c3`K|]&}tjj|s#|(ywr$)r`rar)r7xs r/r:z_find_module..sCa1BCs$..) rrsplitlenr`rarjrrrG) rrrT parent_path module_parts custom_pathparts parent_module path_start candidatesrs r/rrs0K$$S)L ?k )%l1o6K&&sA.E5zA~ ggll8U1X> %a + ((M#EL4D#EFK ; '',,xRAKkCK,=,=c,BCJ  R41aA}Q X6 6 RR Rs0) namespacesfill_package_dirrTrc P ddlm}ddlm}m}|rddlm}nddlm}|xstj}|jddg}g} |in|}t||| t dk(r+t fd d|fDr|jd d D]} t|| } |j| fi|} | j!| | s6|j#d | k(rKtj$j'| |rl|j)|| | | 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)construct_package_dir)unique_everseenrt)PEP420PackageFinder) PackageFinderwhererrc3>K|]}td| yw)rN) _same_path)r7rsearchs r/r:z find_packages..?sVJvay!$< <Vsr)setuptools.discoveryrrzrrtrrr`curdirrlistrall setdefault _nest_pathfindrkgetrasamefiler+)rrrTkwargsrrrtrrpackagesra package_pathpkgsrs @r/ find_packagesrs0;QM6$299H JJw &EH-5r;K //%"89 :F 6{aCVsHoVV##Bq 2G!(D1 !}!!,9&9    $ ,0@0@x0X  # #$9$$E FG Or1parentrac|dvr|ntjj||}tjj|S)N>rr)r`rarjnormpath)rras r/rrNs4Y&6BGGLL,FD 77  D !!r1r6ct|r|}ttttt f|}t |ts2t|dr!djtt|}|Sd|z}|S)z`When getting the version directly from an attribute, it should be normalised to string. __iter__rz%s) callablerr rrPintr<hasattrrjmapr5s r/versionrSsj %S/*E 2E eS ! 5* %HHSe_-E L5LE Lr1 package_datac6d|vr|jd|d<|S)NrVr)r)rs r/canonic_package_datares% l'++C0 R r1 data_filesc t|tr|S|jDcgc]\}}|t||fc}}Scc}}w)zFor compatibility with ``setup.py``, ``data_files`` should be a list of pairs instead of a dict. This function also expands glob patterns. )r<rrrq)rrTdestrSs r/canonic_data_filesrksO*d#)..0  D( }Xx01  sAtextc tdd}t|_|j|||j Dcic]\}}|t |j !}}}|j |jd|Scc}}w)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 delimiters)rrP optionxform read_stringrdictrr)r text_sourceparserrrgroupss r/ entry_pointsr|sr$6 BFF t[)-3\\^ >> 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_valuec ||_d|_yr$)_obtain_value)r-rs r/r0zLazyMappingProxy.__init__s+ 15 r1r2c\|j|j|_|jSr$)rrrs r/_targetzLazyMappingProxy._targets# ;; ,,.DK{{r1keyc(|j|Sr$)r)r-rs r/ __getitem__zLazyMappingProxy.__getitem__s||~c""r1c4t|jSr$)rrrs r/__len__zLazyMappingProxy.__len__s4<<>""r1c4t|jSr$)iterrrs r/rzLazyMappingProxy.__iter__sDLLN##r1N)rLrMrNrOrr rrr0rrrrr rrRr1r/rrsh 6Xb'"b&/6I-J6R #r#b###$(2,$r1rr$)NN)z entry-points)KrOr%rrr`r'rglobr configparserrimportlib.machineryr itertoolsrtypingrrr r r r r rrrrrrtypesrdistutils.errorsr_pathrrwarningsrsetuptools.distrrrdistutils.distr from_iterable chain_iterrPPathLike_Pathrrr rqbytesr}r{ryrxrrrrrrrrrrrrrrrrrrRr1r/r0s&   %*    1+(,43   c2;; T] TT"PP8:>sm'/ #YB%UHUO ;<PS$EhuoE(5/Eue|, ES04 $#*#*'#s(+,#*uo#*LChuo*Zcj11#+GCH,=#>1JO1 5(3- $%1H04 $ ' ''#s(+, 'uo ' '$04 $S cNS'#s(+,SuoS #x- S15 $ 2tCH~.2uo 2  #Y 2j"u"E"c" 58E#s(O#