a oe@@spdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZmZmZmZmZmZmZddlmZdd lmZdd lmZd d l m!Z"d d l#m$Z$erddl%m&Z&ddl'm(Z(ddl)m*Z*e j+Z,ee-ej.fZ/edZ0edddZ1GdddZ2dOee-ee/ee-dddZ3dPee-e4ee/fe-dddZ5ee/ee/dddZ6ee4e/fe-dd d!Z7e/e-d"d#d$Z8dQe-eee-e-fee/d%d&d'Z9e-ee/e d(d)d*Z:e e-ed+d,d-Z;e-eee-e-fe/ee/ee-e-fd.d/d0Zdddd7eee-e-fee/ee-d8d9d:Z?e/e/e-d;dd?d@ZBeCeCdAdBdCZDdTeeEeCfee/eee-ee-fdDdEdFZFdUe-ee-eCfdHdIdJZGGdKdLdLZHGdMdNdNee0e1fZIdS)VaiUtility 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) covariantc@sFeZdZdZeedddZeee j e j fdddZ dd Z d S) StaticModulez>Proxy to a module object that avoids executing arbitrary code.)namespeccCs.tt|j}t|t|` dSN) astparsepathlibrorigin read_bytesvarsupdatelocalsself)r*rr moduler,9C:\Program Files\Certbot\pkgs\setuptools\config\expand.py__init__AszStaticModule.__init__returnc#sZ|jjD]Lttjr4fddjDEdHqttjrjrjjfVqdS)Nc3s|]}|jfVqdSr!value).0targetZ statementr,r- Iz1StaticModule._find_assignments..) r+body isinstancer"ZAssigntargetsZ AnnAssignr2r4r*r,r5r-_find_assignmentsFs   zStaticModule._find_assignmentsc s\ztfdd|DWStyV}z"t|jd|WYd}~n d}~00dS)zHAttempt to load an attribute "statically", via :func:`ast.literal_eval`.c3s2|]*\}}t|tjr|jkrt|VqdSr!)r9r"NameidZ literal_eval)r3r4r2attrr,r-r6Psz+StaticModule.__getattr__..z has no attribute N)nextr< ExceptionAttributeErrorr)r*r@er,r?r- __getattr__Ms   zStaticModule.__getattr__N) __name__ __module__ __qualname____doc__strrr.r rr"ZASTr<rEr,r,r,r-r>sr)patternsroot_dirr0c shd}g}pt|D]xtfdd|Drrtjtj}|tfddt|ddDqtj  tj d}| |q|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 >*]?}[{c3s|]}|vVqdSr!r,)r3charr1r,r-r6hr7z glob_relative..c3s&|]}tj|tjdVqdS)/N)ospathrelpathreplacesepr3rVrLr,r-r6lsT) recursiverT) rUgetcwdanyrVabspathjoinextendsortedrrWrXrYappend)rKrLZglob_charactersZexpanded_valuesZ glob_pathrVr,)rLr2r- glob_relativeYs      rd) filepathsr0csRddlm}tjptfdd||D}dfddt|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_iterablec3s|]}tj|VqdSr!)rUrVr`rZr[r,r-r6r7zread_files.. c3s |]}t|rt|VqdSr!) _assert_local _read_filerZr[r,r-r6s ) setuptools.extern.more_itertoolsrfrUrVr_r]r`_filter_existing_files)rerLrfZ _filepathsr,r[r- read_fileszs  rlccs4|D]*}tj|r|Vqtd|dqdS)NzFile z cannot be found)rUrVisfileremit)rerVr,r,r-rks rk)filepathr0cCs8t|dd}|WdS1s*0YdS)Nzutf-8)encoding)openread)rofr,r,r-risri)rorLcCs@ttj|ttj|jvr.) r{rsplitlenrUrVr`rrrA) rrxrL parent_pathZ module_partsZ custom_pathparts parent_moduleZ path_startZ candidatesrr,r,r-r}s(       r})qualified_class_namerxrLr0c Cs^|p t}|d}||dd}|d|}t|||\}}}tt|||} t| |S)z@Given a qualified class name, return the associated class objectryrN)rUr]rfindr}rr~r) rrxrLidx class_namepkg_namerrVrr+r,r,r- resolve_classs   r)valuesrxrLr0csfdd|DS)zGiven a dictionary mapping command names to strings for qualified class names, apply :func:`resolve_class` to the dict values. csi|]\}}|t|qSr,)rr3kvrxrLr,r- r7zcmdclass..)items)rrxrLr,rr-cmdclass sr) namespacesfill_package_dirrL)rrLr0c  sddlm}ddlm}m}|r.ddlm}n ddlm}|pBtj}| ddg}g} |durbin|}t |||t d krt fd d d|fDr| d dD]Z} t|| } |j| fi|} | | | r|d | kstj| |s||| | q| 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_everseenrf)PEP420PackageFinder) PackageFinderwhereryNrc3s|]}td| VqdS)rN) _same_pathrsearchr,r-r6>r7z find_packages..r)setuptools.discoveryrrjrrfrrrUcurdirr|listrall setdefault _nest_pathfindragetrVsamefiler() rrrLkwargsrrrfrrZpackagesrV package_pathZpkgsr,rr- find_packagess.   &    r)parentrVr0cCs&|dvr |n tj||}tj|S)N>rry)rUrVr`normpath)rrVr,r,r-rMsr)r2r0cCsVt|r|}tttttf|}t|tsRt|drJdt t|}nd|}|S)z`When getting the version directly from an attribute, it should be normalised to string. __iter__ryz%s) callablerr rrJintr9hasattrr`mapr1r,r,r-versionRs  r) package_datar0cCsd|vr|d|d<|S)NrMr)r|)rr,r,r-canonic_package_datadsr) data_filesrLr0cs$t|tr|Sfdd|DS)zFor compatibility with ``setup.py``, ``data_files`` should be a list of pairs instead of a dict. This function also expands glob patterns. csg|]\}}|t|fqSr,)rd)r3destrKr[r,r- usz&canonic_data_files..)r9rr)rrLr,r[r-canonic_data_filesjs   r entry-points)textr0cCsBtddd}t|_|||dd|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_sectionZ delimiterscSsi|]\}}|t|qSr,)dictrrr,r,r-rr7z entry_points..)rrJZ optionxformZ read_stringrr|r)rZ text_sourceparsergroupsr,r,r- entry_points{s   rc@sfeZdZdZddddZddZdd Zd d Zee e fd d dZ e ee e fd ddZ dS)EnsurePackagesDiscoveredaSome expand functions require all the packages to already be discovered before they run, e.g. :func:`read_attr`, :func:`resolve_class`, :func:`cmdclass`. Therefore in some cases we will need to run autodiscovery during the evaluation of the configuration. However, it is better to postpone calling package discovery as much as possible, because some parameters can influence it (e.g. ``package_dir``), and those might not have been processed yet. r) distributioncCs||_d|_dS)NF)_dist_called)r*rr,r,r-r.sz!EnsurePackagesDiscovered.__init__cCs|jsd|_|jjdddS)zBTrigger the automatic package discovery, if it is still necessary.TF)rN)rr set_defaultsr;r,r,r-__call__sz!EnsurePackagesDiscovered.__call__cCs|Sr!r,r;r,r,r- __enter__sz"EnsurePackagesDiscovered.__enter__cCs|jr|jjdSr!)rrrZ analyse_name)r*Z _exc_typeZ _exc_valueZ _tracebackr,r,r-__exit__sz!EnsurePackagesDiscovered.__exit__r/cCs||jj}|duriS|Sr!)rrx)r*Zpkg_dirr,r,r-_get_package_dirsz)EnsurePackagesDiscovered._get_package_dircCs t|jS)zCProxy to ``package_dir`` that may trigger auto-discovery when used.)LazyMappingProxyrr;r,r,r-rxsz$EnsurePackagesDiscovered.package_dirN) rFrGrHrIr.rrrr rJrpropertyrxr,r,r,r-rs rc@steZdZdZegeeeffdddZeeefdddZ eedd d Z e dd d Z e edd dZdS)raMapping proxy that delays resolving the target object, until really needed. >>> 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_valuecCs||_d|_dSr!)_obtain_value)r*rr,r,r-r.szLazyMappingProxy.__init__r/cCs|jdur||_|jSr!)rrr;r,r,r-_targets  zLazyMappingProxy._target)keyr0cCs ||Sr!)r)r*rr,r,r- __getitem__szLazyMappingProxy.__getitem__cCs t|Sr!)rrr;r,r,r-__len__szLazyMappingProxy.__len__cCs t|Sr!)iterrr;r,r,r-rszLazyMappingProxy.__iter__N)rFrGrHrIrr rrr.rrrrr rr,r,r,r-rs  r)N)N)NN)NN)NN)N)r)JrIr"rrUr$rglobrZ configparserrimportlib.machineryr itertoolsrtypingrrrr r r r r rrrrrtypesrZdistutils.errorsr_pathrrwarningsrZsetuptools.distrrrZdistutils.distr from_iterableZ chain_iterrJPathLikeZ_Pathrrrrdbytesrlrkrirhrr~rr}rrrrrrrrrrrrrr,r,r,r-s    8           !   &   $    5& &