a oeC@svdZddlZddlZddlmZddlmZddlmZm Z m Z m Z m Z m Z mZddlmZmZddlmZd d lmZd d lmZmZd d lmZerdd lmZeeejfZ e!e"Z#e e$dddZ%e$e e&dddZ'd+de ddddZ(d,e e ddddZ)d-e$e e e&e de$dddZ*Gd d!d!Z+d"d#Z,ee&d$d%d&Z-Gd'd(d(ej.Z/Gd)d*d*eZ0dS).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_CHECKINGCallableDictMappingOptionalSetUnion) FileErrorInvalidConfigError)SetuptoolsWarning)expand)_PREVIOUSLY_DEFINED_MissingDynamic)apply Distribution)filepathreturncCsDddlm}t|d}||WdS1s60YdS)Nr)tomlirb)Zsetuptools.externropenload)rrfiler@C:\Program Files\Certbot\pkgs\setuptools\config\pyprojecttoml.py load_files  r)configrrc Csddlm}|jd}t|dr*|z ||WS|jy}z`d|j}|j ddkrzt |t |j d|j d }t|d |dWYd}~n d}~00dS) Nr)_validate_pyprojectztrove-classifier_disable_downloadzconfiguration error: `projectzinvalid pyproject.toml config: . )r!ZFORMAT_FUNCTIONSgethasattrr"validateZValidationErrorsummarynamestrip_loggerdebugdetails ValueError)r rZ validatorZtrove_classifierexr+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)r4rignore_option_errorsr rrrapply_configuration:sr8T)rr4c Cs tj|}tj|s(td|dt|p2i}|di}|di}|di}|rd|sh|shiSd|vr|tjdd|rt |d d d ur| d |j n | d d ||d<||d<t |(|d|id }t ||Wd n1s0Y|rtj|} t|| ||S|S)aRead 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])Zsubjectinclude_package_dataNzinclude-package-dataT)r$r9)ospathabspathisfiler rr(_ExperimentalConfigurationemitgetattr setdefaultr;_ignore_errorsr*dirnameexpand_configuration) rrr7r4ZasdictZ project_tableZ tool_tableZsetuptools_tableZsubsetroot_dirrrrr5Fs.          ( r5)r rGr7r4rcCst||||S)aGiven 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 )_ConfigExpanderrr rGr7r4rrrrFsrFc@s`eZdZd4eeeeeddddZdddd Zee e d d d Z d5ddZ ddZ ddZddZee e fdddZdee e fdddZde dddZe ee e fdd d!Zde ee e fd"d#d$Zdee e fdd%d&Zdeee e fd'd(d)Zdee e feee efd*d+d,Zdd-d.d/Zdd-d0d1Zdd-d2d3ZdS)6rHNFrrIcCsp||_|pt|_|di|_|jdg|_|didi|_|jdi|_||_ ||_ t |_ dS)Nr$dynamicr9r:) r r<getcwdrGr( project_cfgrJsetuptools_cfg dynamic_cfgr7_distset_referenced_files)selfr rGr7r4rrr__init__sz_ConfigExpander.__init__)rcCs0ddlm}|j|jddd}|jp.||S)Nrrr,)Zsrc_rootr,)setuptools.distrrGrLr(rO)rRrattrsrrr _ensure_dists z_ConfigExpander._ensure_dist) containerfieldfncCsF||vrBt|j |||||<Wdn1s80YdSN)rDr7)rRrWrXrYrrr_process_fields z_ConfigExpander._process_field package-datacCs|j|i}t|SrZ)rMr(_expandZcanonic_package_data)rRrXZ package_datarrr_canonic_package_datasz%_ConfigExpander._canonic_package_datacCs|||d|}t||j|j}|4}|j}|||| ||Wdn1sp0Y|j |j |j S)Nzexclude-package-data) _expand_packagesr^rV_EnsurePackagesDiscoveredrLrM package_dir_expand_data_files_expand_cmdclass_expand_all_dynamicrQupdater )rRr4ctxZensure_discoveredrarrrrs  *z_ConfigExpander.expandcCs|jd}|dus"t|ttfr&dS|d}t|tr|j|d<|jdi|d<t|j &t j fi||jd<Wdn1s0YdS)NpackagesfindrG package-dirZfill_package_dir) rMr( isinstancelisttupledictrGrCrDr7r]Z find_packages)rRrgrhrrrr_s     z _ConfigExpander._expand_packagescCs$ttj|jd}||jd|dS)N)rGz data-files)rr]Zcanonic_data_filesrGr[rM)rRZ data_filesrrrrbsz"_ConfigExpander._expand_data_files)racCs*|j}ttj||d}||jd|dS)N)rarGcmdclass)rGrr]rnr[rM)rRrarGrnrrrrcsz _ConfigExpander._expand_cmdclass)r4rac sdfddjD}|jp0iddd|D}j |dS)N)versionreadme entry-pointsscripts gui-scripts classifiers dependenciesoptional-dependenciescs$i|]}|vr||qSr)_obtain.0rXr4rarRZspecialrr sz7_ConfigExpander._expand_all_dynamic..)rorprtruZoptional_dependenciescSsi|]\}}|dur||qSrZr)rykvrrrr{) rJre_obtain_entry_points_obtain_version_obtain_readme_obtain_classifiers_obtain_dependencies_obtain_optional_dependenciesitemsrL)rRr4raZobtained_dynamicZupdatesrrzrrds   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 )rRr4rXZpreviousmsgrrr_ensure_previously_sets   z&_ConfigExpander._ensure_previously_set) specifierracCsddlm}t|j|j}d|vrX|j||dt|d|WdSd|vrt |d||WdSt d|d|Wdn1s0YdS)Nr)always_iterablerattrz invalid `z`: ) Z setuptools.extern.more_itertoolsrrDr7rGrQrer]Z read_filesZ read_attrr1)rRr directiverarrGrrr_expand_directives   2z!_ConfigExpander._expand_directive)r4rXracCs4||jvr$|d||j||S|||dS)Nztool.setuptools.dynamic.)rNrr)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|ddddS||ddS)Nrp content-typez text/x-rst)textr)rJrNrwr(r)rRr4rNrrrr-s   z_ConfigExpander._obtain_readme)r4rarcszd}tfdd|DsdS|d|}|dur8dSt|dittdfdd }|dd |d d S) N)rqrrrsc3s|]}|jvVqdSrZ)rJrxrRrr ?r~z7_ConfigExpander._obtain_entry_points..rq)rXgroupcs8|vr4|}|jvr,tt||||<dSrZ)poprJr rr0)rXrvalueZexpandedgroupsrRrr _set_scriptsIs   z:_ConfigExpander._obtain_entry_points.._set_scriptsrrZconsole_scriptsrsZ gui_scripts)anyrwr]Z entry_pointsstr)rRr4rafieldsrrrrrr;s   z$_ConfigExpander._obtain_entry_points)r4cCs(d|jvr$||di}|r$|SdS)Nrt)rJrw splitlinesrRr4rrrrrUs  z#_ConfigExpander._obtain_classifierscCs(d|jvr$||di}|r$t|SdS)Nru)rJrw_parse_requirements_listrrrrr\s  z$_ConfigExpander._obtain_dependenciescsVdjvrdSdjvrFjd}t|ts0Jfdd|DS|ddS)Nrvc s*i|]"\}}|td||iqS)z.tool.setuptools.dynamic.optional-dependencies.)rr)ryrrrrrr{iszA_ConfigExpander._obtain_optional_dependencies..)rJrNrjrmrr)rRr4Zoptional_dependencies_maprrrrcs     z-_ConfigExpander._obtain_optional_dependencies)NFN)r\)__name__ __module__ __qualname__rmr_PathboolrSrVrrr[r^rr_rbrrcrdrrrwrrrrrrrrrrrrHs:       rHcCsdd|DS)NcSs&g|]}|r|ds|qS)#)r- startswith)rylinerrr xsz,_parse_requirements_list..)r)rrrrrwsr)r7c cs\|sdVdSz dVWn>tyV}z&td|jjd|WYd}~n d}~00dS)Nzignored error: z - ) Exceptionr.r/ __class__r)r7r2rrrrDs rDcs>eZdZdeedfdd ZfddZfddZZS) r`r) distributionrLrMcst|||_||_dSrZ)superrS _project_cfg_setuptools_cfg)rRrrLrMrrrrSs z"_EnsurePackagesDiscovered.__init__cs|j|j}}|di}||jp&i||_|j|jjdurV|j d|j_|j durl| d|_ |j dur| d|_ t S)zWhen 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)rOrrCrera set_defaultsZ_ignore_ext_modulesmetadatar,rr( py_modulesrgr __enter__)rRr4Zcfgrarrrrs       z#_EnsurePackagesDiscovered.__enter__cs4|jd|jj|jd|jjt|||S)zWhen exiting the context, if values of ``packages``, ``py_modules`` and ``package_dir`` are missing in ``setuptools_cfg``, copy from ``dist``. rgr)rrCrOrgrr__exit__)rRexc_type exc_value tracebackrrrrsz"_EnsurePackagesDiscovered.__exit__)rrrrmrSrr __classcell__rrrrr`s r`c@seZdZdZdS)r@z``{subject}` in `pyproject.toml` is still *experimental* and likely to change in future releases.N)rrrZ_SUMMARYrrrrr@sr@)F)TFN)NFN)1__doc__Zloggingr< contextlibr functoolsrtypingrrrrrr r errorsr r warningsrr'rr]Z_apply_pyprojecttomlrrrr6rTrrPathLikerZ getLoggerrr.rmrrr*r8r5rFrHrrDZEnsurePackagesDiscoveredr`r@rrrrs\   $       D Y (