a „oeîHã@sÒdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZmZmZmZddlZddlZddlmZddlmZddlmZdd l mZdd lmZgd ¢Ze d d ¡ ¡Z de  !dd¡vZ"Gdd„de#ƒZ$Gdd„dej%j&ƒZ&ej'dd„ƒZ(dd„Z)dd„Z*dd„Z+ej'dd„ƒZ,ee e-ee-ee-dffZ.Gdd „d ƒZ/Gd!d"„d"e/ƒZ0Gd#d$„d$e0ƒZ1e0ƒZ2e2j3Z3e2j4Z4e2j5Z5e2j6Z6e2j7Z7e"�sÈe2j8Z8e2j9Z9e2j:Z:e1ƒZ;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)ÚDictÚIteratorÚListÚOptionalÚUnioné)Úerrors)Ú same_path)Ú parse_strings)ÚSetuptoolsDeprecationWarning)Ú strtobool) Úget_requires_for_build_sdistÚget_requires_for_build_wheelÚ prepare_metadata_for_build_wheelÚ build_wheelÚ build_sdistÚget_requires_for_build_editableÚ#prepare_metadata_for_build_editableÚbuild_editableÚ __legacy__ÚSetupRequirementsErrorÚSETUPTOOLS_ENABLE_FEATURESÚzlegacy-editableÚ_ú-c@seZdZdd„ZdS)rcCs ||_dS©N)Ú specifiers)Úselfr©rú6C:\Program Files\Certbot\pkgs\setuptools\build_meta.pyÚ__init__DszSetupRequirementsError.__init__N)Ú__name__Ú __module__Ú __qualname__r!rrrr rCsrc@s&eZdZdd„Zeejdd„ƒƒZdS)Ú 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%)ÚclsÚorigrrr ÚpatchNs zDistribution.patchN)r"r#r$r'Ú classmethodÚ contextlibÚcontextmanagerr+rrrr r%Hsr%ccs.tj}dd„t_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 Úgóz+no_install_setup_requires..N)Ú setuptoolsZ_install_setup_requires)r*rrr Úno_install_setup_requires^s  r3cs‡fdd„t ˆ¡DƒS)Ncs&g|]}tj tj ˆ|¡¡r|‘qSr)ÚosÚpathÚisdirÚjoin)Ú.0Úname©Za_dirrr Ú osz1_get_immediate_subdirectories..)r4Úlistdirr:rr:r Ú_get_immediate_subdirectoriesns ÿr=csB‡fdd„t |¡Dƒ}z |\}Wnty<tdƒ‚Yn0|S)Nc3s|]}| ˆ¡r|VqdSr©Úendswith©r8Úf©Ú 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 directoryrCZmatchingÚfilerrBr Ú_file_with_extensionts  ÿ rGcCs&tj |¡st d¡Sttdtƒ|ƒS)Nz%from setuptools import setup; setup()Úopen)r4r5ÚexistsÚioÚStringIOÚgetattrÚtokenizerH©Ú setup_scriptrrr Ú_open_setup_script€s  rPccs>t ¡�"t dd¡dVWdƒn1s00YdS)NÚignorezsetup.py install is deprecated)ÚwarningsÚcatch_warningsÚfilterwarningsrrrr Úsuppress_known_deprecationˆs  rUc@sveZdZdZeeeedœdd„Zeeedœdd„Z eeedœdd „Z eeedœd d „Z eeedœd d „Z dS)Ú_ConfigSettingsTranslatorz‡Translate ``config_settings`` into distutils-style command arguments. Only a limited number of options is currently supported. )ÚkeyÚconfig_settingsÚreturncCs.|pi}| |¡pg}t|tƒr*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Ú isinstanceÚstrÚshlexÚsplit)rrWrXÚcfgÚoptsrrr Ú _get_config¦sz%_ConfigSettingsTranslator._get_config)rXrYccsª|pi}hd£}d|vs d|vrRt| d¡p8| d¡p8dƒ}| ¡|vrLdndVd|vsbd|vr”t| d¡pz| d¡pzdƒ}| ¡|vrŽdndV| 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'] >Ú0ÚnoZoffÚfalseÚverbosez --verboseÚ1z-qz-vÚquietz--quietz--global-optionN)r\rZÚlowerra)rrXr_ZfalseyÚlevelrrr Ú _global_args¼sz&_ConfigSettingsTranslator._global_argsccsT|pi}d|vr2tt|dpdƒƒ}|r,dndVd|vrPdt|dƒgEdHdS)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_argsÜs z*_ConfigSettingsTranslator.__dist_info_argsccs:|pi}| d¡p| 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_argsös 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)ra©rrXrrr Ú_arbitrary_argssz)_ConfigSettingsTranslator._arbitrary_argsN) r"r#r$Ú__doc__r\Ú_ConfigSettingsrrarrjZ)_ConfigSettingsTranslator__dist_info_argsrmrorrrr rVŸs  rVc@s¶eZdZdd„Zd!dd„Zd"dd„Zd#d d „Zeeed œd d „Zeee d œdd„Z d$dd„Z dd„Z d%dd„Z d&dd„Zeeeedœdd„Zes²d'dd„Zd(dd„Zd)dd „ZdS)*Ú_BuildMetaBackendc CsŠgtjdd…¢| |¡¢d‘t_z4t ¡�| ¡Wdƒn1sJ0YWn.ty„}z||j7}WYd}~n d}~00|S)NrZegg_info)ÚsysÚargvrjr%r+Ú run_setuprr)rrXÚ requirementsÚerrr Ú_get_build_requiress ÿþý * z%_BuildMetaBackend._get_build_requiresúsetup.pyc Csštj |¡}d}t|ƒ� }| ¡ dd¡}Wdƒn1s>0Yzt|tƒƒWn<ty”}z$|j rp‚t j dddd�WYd}~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) r4r5ÚabspathrPÚreadÚreplaceÚexecÚlocalsÚ SystemExitÚcoder Úemit)rrOÚ__file__r"rAr�rwrrr ru-s  .üz_BuildMetaBackend.run_setupNcCs|j|dgd�S)NZwheel©rv©rxrnrrr rDsz._BuildMetaBackend.get_requires_for_build_wheelcCs|j|gd�S)Nr„r…rnrrr rGsz._BuildMetaBackend.get_requires_for_build_sdist)Úmetadata_directoryÚsuffixrYcCs.| ||¡}t|j|ƒs(t t|ƒ|¡|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 ÚparentÚshutilÚmover\r9)rr†r‡Úinfo_dirrrr Ú_bubble_up_info_directoryJs  z+_BuildMetaBackend._bubble_up_info_directorycsŒt |¡D]b\}}}‡fdd„|Dƒ}t|ƒdks>t|ƒdkr t|ƒdksZJdˆ›d�ƒ‚t||dƒSq dˆ›d|›�}t |¡‚dS) Ncsg|]}| ˆ¡r|‘qSrr>r@©r‡rr r;Yr1z:_BuildMetaBackend._find_info_directory..rrz Multiple z directories foundzNo z directory found in )r4ÚwalkÚlenrr Z InternalError)rr†r‡r‰ÚdirsrZ candidatesÚmsgrrŽr rˆWsz&_BuildMetaBackend._find_info_directorycCstgtjdd…¢| |¡¢d‘d‘|‘d‘t_tƒ�| ¡Wdƒn1sR0Y| |d¡| |d¡S)NrZ dist_infoz --output-dirz--keep-egg-infoz .egg-infoz .dist-info)rsrtrjr3rur�©rr†rXrrr rbs" ÿþýüûú& z2_BuildMetaBackend.prepare_metadata_for_build_wheelc Csôtj |¡}tj|dd�d|dœ}tjfi|¤Ž�¬}gtjdd…¢| |¡¢|¢d‘|‘t_t ƒ�|  ¡Wdƒn1s„0Yt ||ƒ}tj  ||¡}tj  |¡r¼t |¡t tj  ||¡|¡Wdƒn1sæ0Y|S)NT)Úexist_okz.tmp-)ÚprefixÚdirrz --dist-dir)r4r5r{ÚmakedirsÚtempfileZTemporaryDirectoryrsrtrjr3rurGr7rIÚremoveÚrename) 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||¡WdƒS1s80YdS)NZ bdist_wheelú.whl)rUrœro)rÚwheel_directoryrXr†rrr r�süz_BuildMetaBackend.build_wheelcCs| gd¢d||¡S)N)Zsdistz --formatsÚgztarz.tar.gz)rœ)rZsdist_directoryrXrrr r›s ÿz_BuildMetaBackend.build_sdist)r†rYcCs>|sdStt|ƒ d¡ƒ}t|ƒdks*J‚|r:t|dƒSdS)Nz *.dist-inforr)r&rÚglobr�r\)rr†Zdist_info_candidatesrrr Ú_get_dist_info_dir s z$_BuildMetaBackend._get_dist_info_dircCsh| |¡}|rd|gng}dg|¢| |¡¢}tƒ� | |d||¡WdƒS1sZ0YdS)Nz--dist-info-dirZeditable_wheelr�)r¡rmrUrœ)rržrXr†rŒr`Úcmdrrr r¬s ÿz _BuildMetaBackend.build_editablecCs | |¡Sr)rrnrrr r¸sz1_BuildMetaBackend.get_requires_for_build_editablecCs | ||¡Sr)rr“rrr r»sÿz5_BuildMetaBackend.prepare_metadata_for_build_editable)ry)N)N)N)NN)N)NN)N)N)r"r#r$rxrurrr\r�rrˆrrœrrrr¡ÚLEGACY_EDITABLErrrrrrr rrs&     ÿ ÿ ÿ ÿrrcs"eZdZdZd‡fdd„ Z‡ZS)Ú_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 s˜ttjƒ}tj tj |¡¡}|tjvr6tj d|¡tjd}|tjd<z.tt |ƒj |d�W|tjdd…<|tjd<n|tjdd…<|tjd<0dS)NrrN) r&rsr5r4Údirnamer{ÚinsertrtÚsuperr¤ru)rrOZsys_pathZ script_dirZ sys_argv_0©Ú __class__rr ruÏs     ÿz!_BuildMetaLegacyBackend.run_setup)ry)r"r#r$rpruÚ __classcell__rrr¨r r¤Ãs r¤)s\          &)