a „oeÓCã@svdZddlZddlZddlmZddlmZddlmZm Z m Z m Z m Z m Z mZddlmZmZddlmZd d lmZd d lmZmZd d lmZer¤dd lmZeeejfZ e !e"¡Z#e e$dœdd„Z%e$e e&dœdd„Z'd+de ddœdd„Z(d,e e ddœdd„Z)d-e$e e e&e de$dœdd„Z*Gd d!„d!ƒZ+d"d#„Z,ee&d$œd%d&„ƒZ-Gd'd(„d(ej.ƒZ/Gd)d*„d*eƒZ0dS).ac Load setuptools configuration from ``pyproject.toml`` files. **PRIVATE MODULE**: API reserved for setuptools internal usage only. To read project metadata, consider using ``build.util.project_wheel_metadata`` (https://pypi.org/project/build/). For simple scenarios, you can also try parsing the file directly with the help of ``tomllib`` or ``tomli``. éN)Úcontextmanager)Úpartial)Ú TYPE_CHECKINGÚCallableÚDictÚMappingÚOptionalÚSetÚUnioné)Ú FileErrorÚInvalidConfigError)ÚSetuptoolsWarningé)Úexpand)Ú_PREVIOUSLY_DEFINEDÚ_MissingDynamic)Úapply©Ú Distribution)ÚfilepathÚreturncCsDddlm}t|dƒ�}| |¡WdƒS1s60YdS)Nr)ÚtomliÚrb)Zsetuptools.externrÚopenÚload)rrÚfile©rú@C:\Program Files\Certbot\pkgs\setuptools\config\pyprojecttoml.pyÚ load_files  r)Úconfigrrc Cs¶ddlm}|j d¡}t|dƒr*| ¡z | |¡WS|jy°}z`d|j›�}|j   d¡dkrzt   |¡t   |j ¡d|j ›d �}t|›d |›�ƒd‚WYd}~n d}~00dS) Nr)Ú_validate_pyprojectztrove-classifierÚ_disable_downloadzconfiguration error: ú`Úprojectzinvalid pyproject.toml config: Ú.Ú )Úr!ZFORMAT_FUNCTIONSÚgetÚhasattrr"ÚvalidateZValidationErrorÚsummaryÚnameÚstripÚ_loggerÚdebugÚdetailsÚ ValueError)r rZ validatorZtrove_classifierÚexr+Úerrorrrrr*%s       r*Fr)ÚdistrrcCst|d||ƒ}t|||ƒS)zeApply the configuration from a ``pyproject.toml`` file into an existing distribution object. T)Úread_configurationÚ_apply)r4rÚignore_option_errorsr rrrÚapply_configuration:sr8T)rr4c Cs tj |¡}tj |¡s(td|›d�ƒ‚t|ƒp2i}| di¡}| di¡}| di¡}|rd|sh|shiSd|vr|tjdd�|r t |d d ƒd ur |  d |j ¡n |  d d ¡||d<||d<t |ƒ�(|d|id œ}t ||ƒWd ƒn1sò0Y|�rtj |¡} t|| ||ƒS|S)aÉRead given configuration file and returns options from it as a dict. :param str|unicode filepath: Path to configuration file in the ``pyproject.toml`` format. :param bool expand: Whether to expand directives and other computed values (i.e. post-process the given configuration) :param bool ignore_option_errors: Whether to silently ignore options, values of which could not be resolved (e.g. due to exceptions in directives such as file:, attr:, etc.). If False exceptions are propagated as expected. :param Distribution|None: Distribution object to which the configuration refers. If not given a dummy object will be created and discarded after the configuration is read. This is used for auto-discovery of packages and in the case a dynamic configuration (e.g. ``attr`` or ``cmdclass``) is expanded. When ``expand=False`` this object is simply ignored. :rtype: dict zConfiguration file z does not exist.r$ÚtoolÚ setuptoolsZ distutilsz[tool.distutils])ZsubjectÚinclude_package_dataNzinclude-package-dataT)r$r9)ÚosÚpathÚabspathÚisfiler rr(Ú_ExperimentalConfigurationÚemitÚgetattrÚ setdefaultr;Ú_ignore_errorsr*ÚdirnameÚexpand_configuration) rrr7r4ZasdictZ project_tableZ tool_tableZsetuptools_tableZsubsetÚroot_dirrrrr5Fs.          ( r5)r rGr7r4rcCst||||ƒ ¡S)a®Given a configuration with unresolved fields (e.g. dynamic, cmdclass, ...) find their final values. :param dict config: Dict containing the configuration for the distribution :param str root_dir: Top-level directory for the distribution/project (the same directory where ``pyproject.toml`` is place) :param bool ignore_option_errors: see :func:`read_configuration` :param Distribution|None: Distribution object to which the configuration refers. If not given a dummy object will be created and discarded after the configuration is read. Used in the case a dynamic configuration (e.g. ``attr`` or ``cmdclass``). :rtype: dict )Ú_ConfigExpanderr©r rGr7r4rrrrFˆsrFc@s`eZdZd4eeeeeddœdd„Zddœdd „Zee e d œd d „Z d5dd„Z dd„Z dd„Zdd„Zee e fdœdd„Zdee e fdœdd„Zde dœdd„Ze ee e fdœd d!„Zde ee e fd"œd#d$„Zdee e fdœd%d&„Zdeee e fd'œd(d)„Zdee e feee efd*œd+d,„Zdd-œd.d/„Zdd-œd0d1„Zdd-œd2d3„ZdS)6rHNFrrIcCsp||_|pt ¡|_| di¡|_|j dg¡|_| di¡ di¡|_|j di¡|_||_ ||_ t ƒ|_ dS)Nr$Údynamicr9r:) r r<ÚgetcwdrGr(Ú project_cfgrJÚsetuptools_cfgÚ dynamic_cfgr7Ú_distÚsetÚ_referenced_files)Úselfr rGr7r4rrrÚ__init__ sz_ConfigExpander.__init__)rcCs0ddlm}|j|j dd¡dœ}|jp.||ƒS)Nrrr,)Zsrc_rootr,)Úsetuptools.distrrGrLr(rO)rRrÚattrsrrrÚ _ensure_dist±s z_ConfigExpander._ensure_dist)Ú containerÚfieldÚfncCsF||vrBt|jƒ� |||ƒ||<Wdƒn1s80YdS©N)rDr7)rRrWrXrYrrrÚ_process_field·s z_ConfigExpander._process_fieldú package-datacCs|j |i¡}t |¡SrZ)rMr(Ú_expandZcanonic_package_data)rRrXZ package_datarrrÚ_canonic_package_data¼sz%_ConfigExpander._canonic_package_datacCsŽ| ¡| ¡| d¡| ¡}t||j|jƒ}|�4}|j}| ¡| |¡|  ||¡Wdƒn1sp0Y|j   |j ¡|j S)Nzexclude-package-data) Ú_expand_packagesr^rVÚ_EnsurePackagesDiscoveredrLrMÚ package_dirÚ_expand_data_filesÚ_expand_cmdclassÚ_expand_all_dynamicrQÚupdater )rRr4ÚctxZensure_discoveredrarrrrÀs  *z_ConfigExpander.expandcCsš|j d¡}|dus"t|ttfƒr&dS| d¡}t|tƒr–|j|d<|j di¡|d<t|j ƒ�&t j fi|¤Ž|jd<Wdƒn1sŒ0YdS)NÚpackagesÚfindrGú package-dirZfill_package_dir) rMr(Ú isinstanceÚlistÚtupleÚdictrGrCrDr7r]Z find_packages)rRrgrhrrrr_Ñs     z _ConfigExpander._expand_packagescCs$ttj|jd�}| |jd|¡dS)N)rGz data-files)rr]Zcanonic_data_filesrGr[rM)rRZ data_filesrrrrbÝsz"_ConfigExpander._expand_data_files)racCs*|j}ttj||d�}| |jd|¡dS)N)rarGÚcmdclass)rGrr]rnr[rM)rRrarGrnrrrrcász _ConfigExpander._expand_cmdclass)r4rac s‚d‰‡‡‡‡fdd„ˆjDƒ}|jˆ ˆˆ¡p0iˆ ˆˆ¡ˆ ˆ¡ˆ ˆ¡ˆ ˆ¡ˆ ˆ¡d�dd„| ¡Dƒ}ˆj  |¡dS)N)ÚversionÚreadmeú entry-pointsÚscriptsú gui-scriptsÚ classifiersÚ dependenciesúoptional-dependenciescs$i|]}|ˆvr|ˆ ˆ|ˆ¡“qSr)Ú_obtain©Ú.0rX©r4rarRZspecialrrÚ òsþz7_ConfigExpander._expand_all_dynamic..)rorprtruZoptional_dependenciescSsi|]\}}|dur||“qSrZr)ryÚkÚvrrrr{ó) rJreÚ_obtain_entry_pointsÚ_obtain_versionÚ_obtain_readmeÚ_obtain_classifiersÚ_obtain_dependenciesÚ_obtain_optional_dependenciesÚitemsrL)rRr4raZobtained_dynamicZupdatesrrzrrdæs þ ú z#_ConfigExpander._expand_all_dynamic)r4rXcCs2t||ƒ}|dur.|js.d|›d�}t|ƒ‚dS)Nz#No configuration found for dynamic z�. Some dynamic fields need to be specified via `tool.setuptools.dynamic` others must be specified via the equivalent attribute in `setup.py`.)rr7r )rRr4rXZpreviousÚmsgrrrÚ_ensure_previously_sets   ÿz&_ConfigExpander._ensure_previously_set)Ú specifierracCs¶ddlm}t|jƒ�Œ|j}d|vrX|j ||dƒ¡t |d|¡WdƒSd|vr€t  |d||¡WdƒSt d|›d|›�ƒ‚Wdƒn1s¨0YdS)Nr)Úalways_iterablerÚattrz invalid `z`: ) Z setuptools.extern.more_itertoolsr‰rDr7rGrQrer]Z read_filesZ read_attrr1)rRrˆÚ directiverar‰rGrrrÚ_expand_directives   2z!_ConfigExpander._expand_directive)r4rXracCs4||jvr$| d|›�|j||¡S| ||¡dS)Nztool.setuptools.dynamic.)rNrŒr‡)rRr4rXrarrrrws ý z_ConfigExpander._obtaincCs,d|jvr(d|jvr(t | |d|¡¡SdS)Nro)rJrNr]rorw)rRr4rarrrr€'sz_ConfigExpander._obtain_version)r4rcCsLd|jvrdS|j}d|vr<| |di¡|d dd¡dœS| |d¡dS)Nrpú content-typez text/x-rst)Útextr�)rJrNrwr(r‡)rRr4rNrrrr�-s  þ z_ConfigExpander._obtain_readme)r4rarcszd}t‡fdd„|DƒƒsdSˆ |d|¡}|dur8dSt |¡‰dˆi‰ttdœ‡‡‡fdd„ }|dd ƒ|d d ƒˆS) N)rqrrrsc3s|]}|ˆjvVqdSrZ)rJrx©rRrrÚ ?r~z7_ConfigExpander._obtain_entry_points..rq)rXÚgroupcs8|ˆvr4ˆ |¡}|ˆjvr,tt ||¡ƒ‚|ˆ|<dSrZ)ÚpoprJr rr0)rXr‘Úvalue©ZexpandedÚgroupsrRrrÚ _set_scriptsIs   z:_ConfigExpander._obtain_entry_points.._set_scriptsrrZconsole_scriptsrsZ gui_scripts)Úanyrwr]Z entry_pointsÚstr)rRr4raÚfieldsrŽr–rr”rr;s   z$_ConfigExpander._obtain_entry_points)r4cCs(d|jvr$| |di¡}|r$| ¡SdS)Nrt)rJrwÚ splitlines©rRr4r“rrrr‚Us  z#_ConfigExpander._obtain_classifierscCs(d|jvr$| |di¡}|r$t|ƒSdS)Nru)rJrwÚ_parse_requirements_listr›rrrrƒ\s  z$_ConfigExpander._obtain_dependenciescsVdˆjvrdSdˆjvrFˆjd}t|tƒs0J‚‡fdd„| ¡DƒSˆ |d¡dS)Nrvc s*i|]"\}}|tˆ d|›�|i¡ƒ“qS)z.tool.setuptools.dynamic.optional-dependencies.)rœrŒ)ryr‘r‹r�rrr{isùýÿzA_ConfigExpander._obtain_optional_dependencies..)rJrNrjrmr…r‡)rRr4Zoptional_dependencies_maprr�rr„cs    ø z-_ConfigExpander._obtain_optional_dependencies)NFN)r\)Ú__name__Ú __module__Ú __qualname__rmrÚ_PathÚboolrSrVr˜rr[r^rr_rbrrcrdr‡rŒrwr€rr�rr‚rƒr„rrrrrHŸs:ûû    ÿ   þ rHcCsdd„| ¡DƒS)NcSs&g|]}| ¡r| ¡ d¡s|‘qS)ú#)r-Ú startswith)ryÚlinerrrÚ xsþz,_parse_requirements_list..)rš)r“rrrrœwsþrœ)r7c cs\|sdVdSz dVWn>tyV}z&t d|jj›d|›�¡WYd}~n d}~00dS)Nzignored error: z - )Ú Exceptionr.r/Ú __class__r�)r7r2rrrrDs rDcs>eZdZdeedœ‡fdd„ Z‡fdd„Z‡fdd„Z‡ZS) r`r)Ú distributionrLrMcstƒ |¡||_||_dSrZ)ÚsuperrSÚ _project_cfgÚ_setuptools_cfg)rRr¨rLrM©r§rrrSŒs z"_EnsurePackagesDiscovered.__init__csŒ|j|j}}| di¡}| |jp&i¡||_|j ¡|jjdurV|j   d¡|j_|j durl|  d¡|_ |j dur‚|  d¡|_ t ƒ ¡S)z«When entering the context, the values of ``packages``, ``py_modules`` and ``package_dir`` that are missing in ``dist`` are copied from ``setuptools_cfg``. riNr,ú py-modulesrg)rOr«rCreraÚ set_defaultsZ_ignore_ext_modulesÚmetadatar,rªr(Ú py_modulesrgr©Ú __enter__)rRr4Zcfgrar¬rrr±“s       z#_EnsurePackagesDiscovered.__enter__cs4|j d|jj¡|j d|jj¡tƒ |||¡S)zŸWhen exiting the context, if values of ``packages``, ``py_modules`` and ``package_dir`` are missing in ``setuptools_cfg``, copy from ``dist``. rgr­)r«rCrOrgr°r©Ú__exit__)rRÚexc_typeÚ exc_valueÚ tracebackr¬rrr²©sz"_EnsurePackagesDiscovered.__exit__)r�ržrŸrmrSr±r²Ú __classcell__rrr¬rr`‹sÿ r`c@seZdZdZdS)r@z``{subject}` in `pyproject.toml` is still *experimental* and likely to change in future releases.N)r�ržrŸZ_SUMMARYrrrrr@³sÿr@)F)TFN)NFN)1Ú__doc__Zloggingr<Ú contextlibrÚ functoolsrÚtypingrrrrrr r Úerrorsr r Úwarningsrr'rr]Z_apply_pyprojecttomlrrrr6rTrr˜ÚPathLiker Z getLoggerr�r.rmrr¡r*r8r5rFrHrœrDZEnsurePackagesDiscoveredr`r@rrrrÚs\   $     ýü üü Düû Y (