a oeH@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZmZmZmZddlZddlZddlmZddlmZddlmZdd l mZdd lmZgd Zed d Z de !ddvZ"Gddde#Z$Gdddej%j&Z&ej'ddZ(ddZ)ddZ*ddZ+ej'ddZ,ee e-ee-ee-dffZ.Gdd d Z/Gd!d"d"e/Z0Gd#d$d$e0Z1e0Z2e2j3Z3e2j4Z4e2j5Z5e2j6Z6e2j7Z7e"se2j8Z8e2j9Z9e2j:Z:e1Z;dS)%a-A PEP 517 interface to setuptools Previously, when a user or a command line tool (let's call it a "frontend") needed to make a request of setuptools to take a certain action, for example, generating a list of installation requirements, the frontend would would call "setup.py egg_info" or "setup.py bdist_wheel" on the command line. PEP 517 defines a different method of interfacing with setuptools. Rather than calling "setup.py" directly, the frontend should: 1. Set the current directory to the directory with a setup.py file 2. Import this module into a safe python interpreter (one in which setuptools can potentially set global variables or crash hard). 3. Call one of the functions defined in PEP 517. What each function does is defined in PEP 517. However, here is a "casual" definition of the functions (this definition should not be relied on for bug reports or API stability): - `build_wheel`: build a wheel in the folder and return the basename - `get_requires_for_build_wheel`: get the `setup_requires` to build - `prepare_metadata_for_build_wheel`: get the `install_requires` - `build_sdist`: build an sdist in the folder and return the basename - `get_requires_for_build_sdist`: get the `setup_requires` to build Again, this is not a formal definition! Just a "taste" of the module. N)Path)DictIteratorListOptionalUnion)errors) same_path) parse_strings)SetuptoolsDeprecationWarning) strtobool) get_requires_for_build_sdistget_requires_for_build_wheel prepare_metadata_for_build_wheel build_wheel build_sdistget_requires_for_build_editable#prepare_metadata_for_build_editablebuild_editable __legacy__SetupRequirementsErrorSETUPTOOLS_ENABLE_FEATURESzlegacy-editable_-c@seZdZddZdS)rcCs ||_dSN) specifiers)selfrr6C:\Program Files\Certbot\pkgs\setuptools\build_meta.py__init__DszSetupRequirementsError.__init__N)__name__ __module__ __qualname__r!rrrr rCsrc@s&eZdZddZeejddZdS) DistributioncCstt|}t|dSr)listr r)rrZspecifier_listrrr fetch_build_eggsIs zDistribution.fetch_build_eggsccs2tjj}|tj_zdVW|tj_n |tj_0dS)zw Replace distutils.dist.Distribution with this class for the duration of this context. N) distutilsZcorer%)clsorigrrr patchNs zDistribution.patchN)r"r#r$r' classmethod contextlibcontextmanagerr+rrrr r%Hsr%ccs.tj}ddt_zdVW|t_n|t_0dS)a Temporarily disable installing setup_requires Under PEP 517, the backend reports build dependencies to the frontend, and the frontend is responsible for ensuring they're installed. So setuptools (acting as a backend) should not try to install them. cSsdSrr)attrsrrr gz+no_install_setup_requires..N) setuptoolsZ_install_setup_requires)r*rrr no_install_setup_requires^s  r3csfddtDS)Ncs&g|]}tjtj|r|qSr)ospathisdirjoin).0nameZa_dirrr osz1_get_immediate_subdirectories..)r4listdirr:rr:r _get_immediate_subdirectoriesns r=csBfddt|D}z |\}Wnty<tdYn0|S)Nc3s|]}|r|VqdSrendswithr8f extensionrr ur1z'_file_with_extension..z[No distribution was found. Ensure that `setup.py` is not empty and that it calls `setup()`.)r4r< ValueError)Z directoryrCZmatchingfilerrBr _file_with_extensionts   rGcCs&tj|stdSttdt|S)Nz%from setuptools import setup; setup()open)r4r5existsioStringIOgetattrtokenizerH setup_scriptrrr _open_setup_scripts  rPccs>t"tdddVWdn1s00YdS)Nignorezsetup.py install is deprecated)warningscatch_warningsfilterwarningsrrrr suppress_known_deprecations  rUc@sveZdZdZeeeedddZeeedddZ eeeddd Z eeedd d Z eeedd d Z dS)_ConfigSettingsTranslatorzTranslate ``config_settings`` into distutils-style command arguments. Only a limited number of options is currently supported. )keyconfig_settingsreturncCs.|pi}||pg}t|tr*t|S|S)aA Get the value of a specific key in ``config_settings`` as a list of strings. >>> fn = _ConfigSettingsTranslator()._get_config >>> fn("--global-option", None) [] >>> fn("--global-option", {}) [] >>> fn("--global-option", {'--global-option': 'foo'}) ['foo'] >>> fn("--global-option", {'--global-option': ['foo']}) ['foo'] >>> fn("--global-option", {'--global-option': 'foo'}) ['foo'] >>> fn("--global-option", {'--global-option': 'foo bar'}) ['foo', 'bar'] )get isinstancestrshlexsplit)rrWrXcfgoptsrrr _get_configsz%_ConfigSettingsTranslator._get_config)rXrYccs|pi}hd}d|vs d|vrRt|dp8|dp8d}||vrLdndVd|vsbd|vrt|dpz|dpzd}||vrdndV|d |Ed Hd S) a Let the user specify ``verbose`` or ``quiet`` + escape hatch via ``--global-option``. Note: ``-v``, ``-vv``, ``-vvv`` have similar effects in setuptools, so we just have to cover the basic scenario ``-v``. >>> fn = _ConfigSettingsTranslator()._global_args >>> list(fn(None)) [] >>> list(fn({"verbose": "False"})) ['-q'] >>> list(fn({"verbose": "1"})) ['-v'] >>> list(fn({"--verbose": None})) ['-v'] >>> list(fn({"verbose": "true", "--global-option": "-q --no-user-cfg"})) ['-v', '-q', '--no-user-cfg'] >>> list(fn({"--quiet": None})) ['-q'] >0noZofffalseverbosez --verbose1z-qz-vquietz--quietz--global-optionN)r\rZlowerra)rrXr_Zfalseylevelrrr _global_argssz&_ConfigSettingsTranslator._global_argsccsT|pi}d|vr2tt|dpd}|r,dndVd|vrPdt|dgEdHdS)a The ``dist_info`` command accepts ``tag-date`` and ``tag-build``. .. warning:: We cannot use this yet as it requires the ``sdist`` and ``bdist_wheel`` commands run in ``build_sdist`` and ``build_wheel`` to reuse the egg-info directory created in ``prepare_metadata_for_build_wheel``. >>> fn = _ConfigSettingsTranslator()._ConfigSettingsTranslator__dist_info_args >>> list(fn(None)) [] >>> list(fn({"tag-date": "False"})) ['--no-date'] >>> list(fn({"tag-date": None})) ['--no-date'] >>> list(fn({"tag-date": "true", "tag-build": ".a"})) ['--tag-date', '--tag-build', '.a'] ztag-daterdz --tag-datez --no-datez tag-buildz --tag-buildN)r r\)rrXr_valrrr Z__dist_info_argss z*_ConfigSettingsTranslator.__dist_info_argsccs:|pi}|dp|d}|s$dSdt|gEdHdS)a The ``editable_wheel`` command accepts ``editable-mode=strict``. >>> fn = _ConfigSettingsTranslator()._editable_args >>> list(fn(None)) [] >>> list(fn({"editable-mode": "strict"})) ['--mode', 'strict'] z editable-modeZ editable_modeNz--mode)rZr\)rrXr_moderrr _editable_argss z(_ConfigSettingsTranslator._editable_argsccs|d|EdHdS)av Users may expect to pass arbitrary lists of arguments to a command via "--global-option" (example provided in PEP 517 of a "escape hatch"). >>> fn = _ConfigSettingsTranslator()._arbitrary_args >>> list(fn(None)) [] >>> list(fn({})) [] >>> list(fn({'--build-option': 'foo'})) ['foo'] >>> list(fn({'--build-option': ['foo']})) ['foo'] >>> list(fn({'--build-option': 'foo'})) ['foo'] >>> list(fn({'--build-option': 'foo bar'})) ['foo', 'bar'] >>> list(fn({'--global-option': 'foo'})) [] z--build-optionN)rarrXrrr _arbitrary_argssz)_ConfigSettingsTranslator._arbitrary_argsN) r"r#r$__doc__r\_ConfigSettingsrrarrjZ)_ConfigSettingsTranslator__dist_info_argsrmrorrrr rVs  rVc@seZdZddZd!ddZd"ddZd#d d Zeeed d d Zeee d ddZ d$ddZ ddZ d%ddZ d&ddZeeeedddZesd'ddZd(ddZd)dd ZdS)*_BuildMetaBackendc Csgtjdd||dt_z4t|Wdn1sJ0YWn.ty}z||j7}WYd}~n d}~00|S)NrZegg_info)sysargvrjr%r+ run_setuprr)rrX requirementserrr _get_build_requiress  * z%_BuildMetaBackend._get_build_requiressetup.pyc Cstj|}d}t| }|dd}Wdn1s>0Yzt|tWn<ty}z$|j rpt j ddddWYd}~n d}~00dS)N__main__z\r\nz\nz6Running `setup.py` directly as CLI tool is deprecated.znPlease avoid using `sys.exit(0)` or similar statements that don't fit in the paradigm of a configuration file.zAhttps://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html)Zsee_url) r4r5abspathrPreadreplaceexeclocals SystemExitcoder emit)rrO__file__r"rArrwrrr ru-s  .z_BuildMetaBackend.run_setupNcCs|j|dgdS)NZwheelrvrxrnrrr rDsz._BuildMetaBackend.get_requires_for_build_wheelcCs|j|gdS)Nrrrnrrr rGsz._BuildMetaBackend.get_requires_for_build_sdist)metadata_directorysuffixrYcCs.|||}t|j|s(tt|||jS)z PEP 517 requires that the .dist-info directory be placed in the metadata_directory. To comply, we MUST copy the directory to the root. Returns the basename of the info directory, e.g. `proj-0.0.0.dist-info`. )_find_info_directoryr parentshutilmover\r9)rrrinfo_dirrrr _bubble_up_info_directoryJs  z+_BuildMetaBackend._bubble_up_info_directorycst|D]b\}}}fdd|D}t|dks>t|dkr t|dksZJddt||dSq dd|}t|dS) Ncsg|]}|r|qSrr>r@rrr r;Yr1z:_BuildMetaBackend._find_info_directory..rrz Multiple z directories foundzNo z directory found in )r4walklenrr Z InternalError)rrrrdirsrZ candidatesmsgrrr rWsz&_BuildMetaBackend._find_info_directorycCstgtjdd||dd|dt_t|Wdn1sR0Y||d||dS)NrZ dist_infoz --output-dirz--keep-egg-infoz .egg-infoz .dist-info)rsrtrjr3rurrrrXrrr rbs" & z2_BuildMetaBackend.prepare_metadata_for_build_wheelc Cstj|}tj|ddd|d}tjfi|}gtjdd|||d|t_t | Wdn1s0Yt ||}tj ||}tj |rt|ttj |||Wdn1s0Y|S)NT)exist_okz.tmp-)prefixdirrz --dist-dir)r4r5r{makedirstempfileZTemporaryDirectoryrsrtrjr3rurGr7rIremoverename) rZ setup_commandZresult_extensionZresult_directoryrXZ temp_optsZ tmp_dist_dirZresult_basename result_pathrrr _build_with_temp_dirss.   &   4z&_BuildMetaBackend._build_with_temp_dircCsFt,|dg||d||WdS1s80YdS)NZ bdist_wheel.whl)rUrro)rwheel_directoryrXrrrr rsz_BuildMetaBackend.build_wheelcCs|gdd||S)N)Zsdistz --formatsgztarz.tar.gz)r)rZsdist_directoryrXrrr rs z_BuildMetaBackend.build_sdist)rrYcCs>|sdStt|d}t|dks*J|r:t|dSdS)Nz *.dist-inforr)r&rglobrr\)rrZdist_info_candidatesrrr _get_dist_info_dirs z$_BuildMetaBackend._get_dist_info_dircCsh||}|rd|gng}dg|||}t ||d||WdS1sZ0YdS)Nz--dist-info-dirZeditable_wheelr)rrmrUr)rrrXrrr`cmdrrr rs z _BuildMetaBackend.build_editablecCs ||Sr)rrnrrr rsz1_BuildMetaBackend.get_requires_for_build_editablecCs |||Sr)rrrrr rsz5_BuildMetaBackend.prepare_metadata_for_build_editable)ry)N)N)N)NN)N)NN)N)N)r"r#r$rxrurrr\rrrrrrrrrLEGACY_EDITABLErrrrrrr rrs&       rrcs"eZdZdZdfdd ZZS)_BuildMetaLegacyBackendaOCompatibility backend for setuptools This is a version of setuptools.build_meta that endeavors to maintain backwards compatibility with pre-PEP 517 modes of invocation. It exists as a temporary bridge between the old packaging mechanism and the new packaging mechanism, and will eventually be removed. ryc sttj}tjtj|}|tjvr6tjd|tjd}|tjd<z.tt |j |dW|tjdd<|tjd<n|tjdd<|tjd<0dS)NrrN) r&rsr5r4dirnamer{insertrtsuperrru)rrOZsys_pathZ script_dirZ sys_argv_0 __class__rr rus     z!_BuildMetaLegacyBackend.run_setup)ry)r"r#r$rpru __classcell__rrrr rs r)s\          &)