a „oe»cã@s$dZddlZddlZddlZddlmZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZddlmZmZdd lmZdd lmZmZdd lmZdd l m!Z!m"Z"dd l#m$Z$ddl%m&Z&e rôddl'm(Z(ddl)m*Z*ee+ej,fZ-e dede ffZ.e de.fZ/ededd�Z0d;e-e1dœdd„Z2de-ddœdd„Z3dGd9d:„d:e$ƒZ?dS)>a< Load setuptools configuration from ``setup.cfg`` files. **API will be made private in the future** 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 ``configparser``. éN)Ú defaultdict)Úpartial©Úwraps) Ú TYPE_CHECKINGÚCallableÚAnyÚDictÚGenericÚIterableÚListÚOptionalÚSetÚTupleÚTypeVarÚUnioné)Ú FileErrorÚ OptionError)Údefault_environment)ÚInvalidRequirementÚ Requirement)Ú SpecifierSet)ÚInvalidVersionÚVersion)ÚSetuptoolsDeprecationWarningé)Úexpand)ÚDistributionMetadata©Ú DistributionÚstrÚTarget)r r)ÚboundF)ÚfilepathÚreturncCs8ddlm}|ƒ}|r| ¡ng}t||||ƒ}t|ƒS)a,Read given configuration file and returns options from it as a dict. :param str|unicode filepath: Path to configuration file to get options from. :param bool find_others: Whether to search for other configuration files which could be on in various places. :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. :rtype: dict rr)Úsetuptools.distr Zfind_config_filesÚ_applyÚconfiguration_to_dict)r$Z find_othersÚignore_option_errorsr ÚdistÚ filenamesÚhandlers©r-ú;C:\Program Files\Certbot\pkgs\setuptools\config\setupcfg.pyÚread_configuration8s  r/r )r*r$r%cCst||ƒ| ¡|S)z`Apply the configuration from a ``setup.cfg`` file into an existing distribution object. )r'Z_finalize_requires)r*r$r-r-r.Úapply_configurationRs r0r-)Ú ConfigHandler.)r*r$Ú other_filesr)r%c Cs ddlm}tj |¡}tj |¡s4td|›d�ƒ‚t ¡}t tj  |¡¡g|¢|‘}z4|j ||d�t ||j |d�}|  ¡Wt |¡n t |¡0|S)zHRead configuration from ``filepath`` and applies to the ``dist`` object.r)Ú _DistributionzConfiguration file z does not exist.)r+)r))r&r3ÚosÚpathÚabspathÚisfilerÚgetcwdÚchdirÚdirnameZparse_config_filesÚparse_configurationÚcommand_optionsZ_finalize_license_files)r*r$r2r)r3Zcurrent_directoryr+r,r-r-r.r'[s    ÿ r')Ú target_objÚkeycCs*d|›�}t t||¡}t|||ƒ}|ƒS)z  Given a target object and option key, get that option from the target object, either through a get_{key} method or from an attribute directly. Zget_)Ú functoolsrÚgetattr)r=r>Z getter_nameZ by_attributeÚgetterr-r-r.Ú _get_optionys  rB)r,r%cCs<ttƒ}|D]*}|jD]}t|j|ƒ}|||j|<qq |S)z»Returns configuration data gathered by given handlers as a dict. :param list[ConfigHandler] handlers: Handlers list, usually from parse_configuration() :rtype: dict )rÚdictÚ set_optionsrBr=Úsection_prefix)r,Z config_dictZhandlerÚoptionÚvaluer-r-r.r(…s   r()ÚConfigMetadataHandlerÚConfigOptionsHandler)Ú distributionr<r%cCsˆt |¡�f}t||||ƒ}| ¡|js0|j|_t|j||||j|jƒ}| ¡|j  |j|j¡Wdƒn1sv0Y||fS)aÒPerforms additional parsing of configuration options for a distribution. Returns a list of used option handlers. :param Distribution distribution: :param dict command_options: :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. :rtype: list N) rÚEnsurePackagesDiscoveredrIÚparseÚ package_dirrHÚmetadataÚsrc_rootÚ_referenced_filesÚupdate)rJr<r)Úensure_discoveredÚoptionsÚmetar-r-r.r;—s. üúÿ"r;)ÚlabelÚ orig_valueÚparsedc sªd|vstˆƒdkrdStƒ ¡}z,tˆdƒ}|j|vrLtj|ˆdd�WnVty¤}z>t‡fdd„|Dƒƒr�tj |ˆdd�}t|ƒ|‚WYd}~n d}~00dS)amBecause users sometimes misinterpret this configuration: [options.extras_require] foo = bar;python_version<"4" It looks like one requirement with an environment marker but because there is no newline, it's parsed as two requirements with a semicolon as separator. Therefore, if: * input string does not contain a newline AND * parsed result contains two requirements AND * parsing of the two parts from the result (";") leads in a valid Requirement with a valid marker a UserWarning is shown to inform the user about the possible problem. Ú rNr)ZfieldÚreqc3s|]}ˆd |¡VqdS)rN©Ú startswith)Ú.0Zmarker©rWr-r.Ú àóz8_warn_accidental_env_marker_misconfig..) ÚlenÚ marker_envÚkeysrÚnameÚ_AmbiguousMarkerÚemitrÚanyÚmessage)rUrVrWZmarkersrYÚexÚmsgr-r]r.Ú%_warn_accidental_env_marker_misconfigÅs   rjc@sôeZdZUdZeed<iZeeefed<ee e j dœdd„Z e e dœdd „ƒZed d „ƒZd d „Ze d)dd„ƒZe dd„ƒZe dd„ƒZe dd„ƒZedœdd„Zedœdd„Ze dd„ƒZe dd„ƒZe d*d!d"„ƒZd#d$„Zd%d&„Zd'd(„Zd S)+r1z1Handles metadata supplied in configuration files.rEÚaliases)r=rSrRcCs4||_||_t| |¡ƒ|_g|_||_tƒ|_dS©N) r)r=rCÚ_section_optionsÚsectionsrDrRÚsetrP©Úselfr=rSr)rRr-r-r.Ú__init__õszConfigHandler.__init__)rSccs>| ¡D]0\}}| |j¡\}}}|r(q| d¡|fVqdS)NÚ.)ÚitemsÚ partitionrEÚlstrip)ÚclsrSZ full_namerGZpreÚseprcr-r-r.rms zConfigHandler._section_optionscCstd|jjƒ‚dS)ú.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)ÚNotImplementedErrorÚ __class__Ú__name__©rqr-r-r.Úparserss ÿzConfigHandler.parsersc Cs´|j}|j ||¡}zt||ƒ}Wnty<t|ƒ‚Yn0|rFdSz|j |dd„¡|ƒ}Wntf|jy|YdS0t   |j |¡}t|d||ƒ}||ƒ|j   |¡dS)NcSs|Srlr-)Úxr-r-r.Ú%r_z+ConfigHandler.__setitem__..zset_%s)r=rkÚgetr@ÚAttributeErrorÚKeyErrorr~Ú Exceptionr)r?rÚ __setattr__rDÚappend)rqZ option_namerGr=Z current_valuerWZ simple_setterÚsetterr-r-r.Ú __setitem__s  zConfigHandler.__setitem__ú,cCs8t|tƒr|Sd|vr | ¡}n | |¡}dd„|DƒS)z×Represents value as a list. Value is split either by separator (defaults to comma) or by lines. :param value: :param separator: List items separator character. :rtype: list rXcSsg|]}| ¡r| ¡‘qSr-©Ústrip)r\Úchunkr-r-r.Ú Ar_z-ConfigHandler._parse_list..)Ú isinstanceÚlistÚ splitlinesÚsplit)rwrGÚ separatorr-r-r.Ú _parse_list/s   zConfigHandler._parse_listcCsRd}i}| |¡D]:}| |¡\}}}||krrxÚvalr-r-r.Ú _parse_dictCszConfigHandler._parse_dictcCs| ¡}|dvS)zQRepresents value as boolean. :param value: :rtype: bool )Ú1ÚtrueZyes)Úlower©rwrGr-r-r.Ú _parse_boolTszConfigHandler._parse_boolcs‡fdd„}|S)zßReturns a parser function to make sure field inputs are not files. Parses a value after getting the key so error messages are more informative. :param key: :rtype: callable cs d}| |¡rtd ˆ¡ƒ‚|S)Núfile:zCOnly strings are accepted for the {0} field, files are not accepted)r[Ú ValueErrorÚformat)rGZexclude_directive©r>r-r.Úparserjs ÿÿz3ConfigHandler._exclude_files_parser..parserr-)rwr>r¢r-r¡r.Ú_exclude_files_parser^s z#ConfigHandler._exclude_files_parser©Úroot_dircCs\d}t|tƒs|S| |¡s |S|t|ƒd…}dd„| d¡Dƒ}|j |¡t ||¡S)aORepresents value as a string, allowing including text from nearest files using `file:` directive. Directive is sandboxed and won't reach anything outside directory with setup.py. Examples: file: README.rst, CHANGELOG.md, src/file.txt :param str value: :rtype: str ržNcSsg|] }| ¡‘qSr-rŠ)r\r5r-r-r.r�‹r_z-ConfigHandler._parse_file..r‰) rŽr!r[r`r‘rPrQrZ read_files)rqrGr¥Zinclude_directiveÚspecZ filepathsr-r-r.Ú _parse_fileus    zConfigHandler._parse_filecCs:d}| |¡s|S| |d¡}| |jj¡t |||¡S)z·Represents value as a module attribute. Examples: attr: package.attr attr: package.module.attr :param str value: :rtype: str zattr:Ú)r[ÚreplacerQrRrMrZ read_attr)rqrGrMr¥Zattr_directiveZ attr_descr-r-r.Ú _parse_attr�s   zConfigHandler._parse_attrcs‡fdd„}|S)z¹Returns parser function to represents value as a list. Parses a value applying given methods one after another. :param parse_methods: :rtype: callable cs|}ˆD] }||ƒ}q|Srlr-)rGrWÚmethod©Ú parse_methodsr-r.rL­s z1ConfigHandler._get_parser_compound..parser-)rwr­rLr-r¬r.Ú_get_parser_compound£s z"ConfigHandler._get_parser_compoundcCs,i}| ¡D]\}\}}|||ƒ||<q |S)aParses section options into a dictionary. Applies a given parser to each option in a section. :param dict section_options: :param callable values_parser: function with 2 args corresponding to key, value :rtype: dict )rt)rwÚsection_optionsÚ values_parserrGr>Ú_r—r-r-r.Ú_parse_section_to_dict_with_key·s z-ConfigHandler._parse_section_to_dict_with_keyNcs$ˆr‡fdd„ndd„}| ||¡S)aParses section options into a dictionary. Optionally applies a given parser to each value. :param dict section_options: :param callable values_parser: function with 1 arg corresponding to option value :rtype: dict csˆ|ƒSrlr-©r±Úv©r°r-r.r€Ðr_z6ConfigHandler._parse_section_to_dict..cSs|Srlr-r³r-r-r.r€Ðr_©r²)rwr¯r°r¢r-rµr.Ú_parse_section_to_dictÆs z$ConfigHandler._parse_section_to_dictc CsL| ¡D]>\}\}}t t¡�|||<Wdƒq1s<0YqdS)zQParses configuration file section. :param dict section_options: N)rtÚ contextlibÚsuppressrƒ)rqr¯rcr±rGr-r-r.Ú parse_sectionÓs zConfigHandler.parse_sectioncCsh|j ¡D]X\}}d}|r"d|}t|d| dd¡dƒ}|durZtd|j›d|›d�ƒ‚||ƒq dS) zTParses configuration file items from one or more related sections. r¨z_%szparse_section%srsÚ__Nz*Unsupported distribution option section: [ú])rnrtr@r©rrE)rqZ section_namer¯Zmethod_postfixZsection_parser_methodr-r-r.rLÝs$üÿÿÿzConfigHandler.parsec stˆƒ‡‡‡fdd„ƒ}|S)z¢this function will wrap around parameters that are deprecated :param msg: deprecation message :param func: function to be wrapped around cs.ˆ dd¡tjdˆfiˆ¤Žˆ|i|¤ŽS)NÚ stacklevelrz Deprecated config in `setup.cfg`)Ú setdefaultÚ_DeprecatedConfigre)ÚargsÚkwargs©ÚfuncÚkwrir-r.Úconfig_handlerýs z@ConfigHandler._deprecated_config_handler..config_handlerr)rqrÃrirÄrÅr-rÂr.Ú_deprecated_config_handlerösz(ConfigHandler._deprecated_config_handler)r‰)N)r|Ú __module__Ú __qualname__Ú__doc__r!Ú__annotations__rkr r"ÚAllCommandOptionsrrKrrÚ classmethodrmÚpropertyr~rˆr“r˜r�r£Ú_Pathr§rªr®r²r·rºrLrÆr-r-r-r.r1ås>  û          r1csdeZdZdZdddddœZdZdejfd ee e j e e ed œ‡fd d „ Zed d„ƒZdd„Z‡ZS)rHrNÚurlÚ descriptionÚ classifiersÚ platforms)Z home_pageZsummaryZ classifierÚplatformFNr)r=rSr)rRrMr¥cs"tƒ ||||¡||_||_dSrl)ÚsuperrrrMr¥)rqr=rSr)rRrMr¥©r{r-r.rrs zConfigMetadataHandler.__init__c CsL|j}t|j|jd�}|j}|j}||||| ||¡|dƒ||||j|dœ S)ryr¤Úlicense) rÒÚkeywordsZprovidesZ obsoletesrÑrÖZ license_filesrÐZlong_descriptionÚversionZ project_urls)r“rr§r¥r˜r£r®Ú_parse_version)rqÚ parse_listZ parse_fileÚ parse_dictZexclude_files_parserr-r-r.r~#s  õzConfigMetadataHandler.parserscCsn| ||j¡}||krV| ¡}z t|ƒWn&tyPtd|›d|›�ƒ‚Yn0|St | ||j |j¡¡S)zSParses `version` option value. :param value: :rtype: str zVersion loaded from z does not comply with PEP 440: ) r§r¥r‹rrrrrØrªrM)rqrGrØr-r-r.rÙ9s  ÿÿ z$ConfigMetadataHandler._parse_version)r|rÇrÈrErkZ strict_moder4ÚcurdirrËÚboolrrKr rCrÎrrrÍr~rÙÚ __classcell__r-r-rÕr.rHs(ü ùù  rHrcs¦eZdZdZdeeejdœ‡fdd„ Ze dd„ƒZ dd „Z e e d œd d „Z ed d„ƒZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Z‡ZS)!rIrSr )r=rSr)rRcs$tƒ ||||¡|j|_i|_dSrl)rÔrrrOr¥rMrprÕr-r.rrVszConfigOptionsHandler.__init__cCs|j|dd�S)Nú;)r’)r“rœr-r-r.Ú_parse_list_semicolonasz*ConfigOptionsHandler._parse_list_semicoloncCs|j||jd�S)Nr¤)r§r¥)rqrGr-r-r.Ú_parse_file_in_rootesz(ConfigOptionsHandler._parse_file_in_root)rUrGcCs*| | |¡¡}t|||ƒdd„|DƒS)NcSsg|]}| d¡s|‘qS)ú#rZ)r\r–r-r-r.r�nr_zAConfigOptionsHandler._parse_requirements_list..)ràrárj)rqrUrGrWr-r-r.Ú_parse_requirements_lisths z-ConfigOptionsHandler._parse_requirements_listcCsT|j}|j}|j}|j}||||||| |d¡t|jdƒ|j|j|j|j |t |dœS)ryzeThe namespace_packages parameter is deprecated, consider using implicit namespaces instead (PEP 420).Úinstall_requires)Zzip_safeZinclude_package_datarMZscriptsZeager_resourcesZdependency_linksZnamespace_packagesräZsetup_requiresZ tests_requireZpackagesÚ entry_pointsZ py_modulesZpython_requiresÚcmdclass) r“r�r˜Ú_parse_cmdclassrÆrrãràÚ_parse_packagesrár)rqrÚZ parse_boolrÛZparse_cmdclassr-r-r.r~ps2þÿêzConfigOptionsHandler.parserscCs|jj}t | |¡||j¡Srl)rRrMrrær˜r¥)rqrGrMr-r-r.rç‘sz$ConfigOptionsHandler._parse_cmdclasscCsbddg}| ¡}||vr"| |¡S| |j di¡¡}|j||dk|j|jd�tj fi|¤ŽS)zTParses `packages` option value. :param value: :rtype: list zfind:zfind_namespace:z packages.findr)Z namespacesr¥Zfill_package_dir) r‹r“Úparse_section_packages__findrnr�rQr¥rMrZ find_packages)rqrGZfind_directivesZ trimmed_valueÚ find_kwargsr-r-r.rè•s  ÿ ýz$ConfigOptionsHandler._parse_packagescsR| ||j¡}gd¢‰t‡fdd„| ¡Dƒƒ}| d¡}|durN|d|d<|S)zœParses `packages.find` configuration file section. To be used in conjunction with _parse_packages(). :param dict section_options: )ÚwhereZincludeZexcludecs$g|]\}}|ˆvr|r||f‘qSr-r-)r\Úkr´©Z valid_keysr-r.r�ºr_zEConfigOptionsHandler.parse_section_packages__find..rëNr)r·r“rCrtr�)rqr¯Z section_datarêrër-rír.ré®sÿ  z1ConfigOptionsHandler.parse_section_packages__findcCs| ||j¡}||d<dS)z`Parses `entry_points` configuration file section. :param dict section_options: råN)r·r“©rqr¯rWr-r-r.Úparse_section_entry_pointsÃsz/ConfigOptionsHandler.parse_section_entry_pointscCs| ||j¡}t |¡Srl)r·r“rZcanonic_package_data)rqr¯Ú package_datar-r-r.Ú_parse_package_dataËsz(ConfigOptionsHandler._parse_package_datacCs| |¡|d<dS)z`Parses `package_data` configuration file section. :param dict section_options: rðN©rñ©rqr¯r-r-r.Úparse_section_package_dataÏsz/ConfigOptionsHandler.parse_section_package_datacCs| |¡|d<dS)zhParses `exclude_package_data` configuration file section. :param dict section_options: Zexclude_package_dataNròrór-r-r.Ú"parse_section_exclude_package_dataÖsz7ConfigOptionsHandler.parse_section_exclude_package_datacs ˆ |‡fdd„¡}|ˆd<dS)zbParses `extras_require` configuration file section. :param dict section_options: csˆ d|›d�|¡S)Nzextras_require[r¼)rã)rìr´r}r-r.r€är_zCConfigOptionsHandler.parse_section_extras_require..Zextras_requireNr¶rîr-r}r.Úparse_section_extras_requireÝs  þz1ConfigOptionsHandler.parse_section_extras_requirecCs$| ||j¡}t ||j¡|d<dS)z^Parses `data_files` configuration file section. :param dict section_options: Z data_filesN)r·r“rZcanonic_data_filesr¥rîr-r-r.Úparse_section_data_filesész-ConfigOptionsHandler.parse_section_data_files)r|rÇrÈrErËrÝrrKrrrÌràrár!rãrÍr~rçrèrérïrñrôrõrör÷rÞr-r-rÕr.rISs*û    rIc@s$eZdZdZdZdZedd„ƒZdS)rdzAmbiguous requirement marker.zá One of the parsed requirements in `{field}` looks like a valid environment marker: {req!r} Please make sure that the configuration file is correct. You can use dangling lines to avoid this problem. z'userguide/declarative_config.html#opt-2cKs"d|j›�}|j|j|j||d�S)Nz%https://setuptools.pypa.io/en/latest/)Zsee_urlZ format_args)Ú _SEE_DOCSÚ_formatÚ_SUMMARYÚ_DETAILS)rwrÄZdocsr-r-r.rgs z_AmbiguousMarker.messageN)r|rÇrÈrúrûrørÌrgr-r-r-r.rdòs rdc@seZdZdZdS)r¿z!userguide/declarative_config.htmlN)r|rÇrÈrør-r-r-r.r¿sr¿)FF)r-F)F)@rÉr¸r?r4Ú collectionsrrrÚtypingrrrr r r r r rrrrÚerrorsrrZextern.packaging.markersrraZextern.packaging.requirementsrrZextern.packaging.specifiersrZextern.packaging.versionrrÚwarningsrr¨rZdistutils.distrr&r r!ÚPathLikerÎZSingleCommandOptionsrËr"rCr/r0rÝr'rBr(r;r�rjr1rHrIrdr¿r-r-r-r.Úsj    8       ÿþ  üû  ýü . #M