U âQab6Pã@sþddlmZmZddlZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddl m Z ddlmZmZddlmZmZdd lmZdd lmZmZeZdd d „Zdd„Zdd„Zddd„ZGdd„dƒZGdd„deƒZ Gdd„deƒZ!dS)é)Úabsolute_importÚunicode_literalsN)Ú defaultdict)Úpartial©Úwraps)Ú import_module)ÚDistutilsOptionErrorÚDistutilsFileError)Ú LegacyVersionÚparse)Ú SpecifierSet)Ú string_typesÚPY3Fc Cs®ddlm}m}tj |¡}tj |¡s4td|ƒ‚t ¡}t  tj  |¡¡zJ|ƒ}|rb|  ¡ng}||krx|  |¡|j ||d�t||j|d�}W5t  |¡Xt|ƒ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 r)Ú DistributionÚ _Distributionz%Configuration file %s does not exist.)Ú filenames)Úignore_option_errors)Zsetuptools.distrrÚosÚpathÚabspathÚisfiler ÚgetcwdÚchdirÚdirnameZfind_config_filesÚappendZparse_config_filesÚparse_configurationÚcommand_optionsÚconfiguration_to_dict) ÚfilepathZ find_othersrrrZcurrent_directoryZdistrÚhandlers©r!ú5/usr/lib/python3.8/site-packages/setuptools/config.pyÚread_configurations*  ÿ þ  r#cCs.djftƒŽ}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. z get_{key})ÚformatÚlocalsÚ functoolsrÚgetattr)Ú target_objÚkeyZ getter_nameZ by_attributeÚgetterr!r!r"Ú _get_optionEs 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_optionsr+r(Úsection_prefix)r Z config_dictZhandlerZoptionÚvaluer!r!r"rQs   rcCs6t|||ƒ}| ¡t|j|||jƒ}| ¡||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 )ÚConfigOptionsHandlerr ÚConfigMetadataHandlerÚmetadataÚ package_dir)Z distributionrrÚoptionsÚmetar!r!r"rcsÿþrc@sÌeZdZdZdZiZd%dd„Zedd„ƒZdd „Z e d&d d „ƒZ e d d„ƒZ e dd„ƒZ e dd„ƒZe dd„ƒZedd„ƒZedd„ƒZe d'dd„ƒZe dd„ƒZe d(dd„ƒZdd „Zd!d"„Zd#d$„ZdS))Ú ConfigHandlerz1Handles metadata supplied in configuration files.NFcCs^i}|j}| ¡D].\}}| |¡s&q| |d¡ d¡}|||<q||_||_||_g|_dS)NÚÚ.) r.ÚitemsÚ startswithÚreplaceÚstriprr(Úsectionsr-)Úselfr(r4rr=r.Ú section_nameÚsection_optionsr!r!r"Ú__init__Žs  zConfigHandler.__init__cCstd|jjƒ‚dS)ú.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)ÚNotImplementedErrorÚ __class__Ú__name__)r>r!r!r"Úparsersžs ÿzConfigHandler.parsersc CsÆtƒ}|j}|j ||¡}t|||ƒ}||kr6t|ƒ‚|r>dSd}|j |¡}|r€z ||ƒ}Wn tk r~d}|jsz‚YnX|rˆdSt|d|dƒ}|dkr®t |||ƒn||ƒ|j   |¡dS)NFTzset_%s) Útupler(ÚaliasesÚgetr'ÚKeyErrorrFÚ ExceptionrÚsetattrr-r) r>Z option_namer/Úunknownr(Z current_valueZ skip_optionÚparserÚsetterr!r!r"Ú __setitem__¤s0   zConfigHandler.__setitem__ú,cCs8t|tƒr|Sd|kr | ¡}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 Ú cSsg|]}| ¡r| ¡‘qSr!)r<)Ú.0Úchunkr!r!r"Ú Üsz-ConfigHandler._parse_list..)Ú isinstanceÚlistÚ splitlinesÚsplit)Úclsr/Ú separatorr!r!r"Ú _parse_listÊs   zConfigHandler._parse_listcCsPd}i}| |¡D]8}| |¡\}}}||kr:td|ƒ‚| ¡|| ¡<q|S)zPRepresents value as a dict. :param value: :rtype: dict ú=z(Unable to parse option value to dict: %s)r\Ú partitionr r<)rZr/r[ÚresultÚliner)ÚsepÚvalr!r!r"Ú _parse_dictÞsÿzConfigHandler._parse_dictcCs| ¡}|dkS)zQRepresents value as boolean. :param value: :rtype: bool )Ú1ÚtrueZyes)Úlower)rZr/r!r!r"Ú _parse_boolðszConfigHandler._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:Ú ValueErrorr$)r/Zexclude_directive©r)r!r"rNs ÿÿz3ConfigHandler._exclude_files_parser..parserr!)rZr)rNr!rjr"Ú_exclude_files_parserús z#ConfigHandler._exclude_files_parsercs\d}t|tƒs|S| |¡s |S|t|ƒd…}dd„| d¡Dƒ}d ‡fdd„|Dƒ¡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 rhNcss|]}tj | ¡¡VqdS©N)rrrr<©rSrr!r!r"Ú %sz,ConfigHandler._parse_file..rQrRc3s.|]&}ˆ |¡stj |¡rˆ |¡VqdS)TN)Ú _assert_localrrrÚ _read_filerm©rZr!r"rn&s   ý)rVrr:ÚlenrYÚjoin)rZr/Zinclude_directiveÚspecZ filepathsr!rqr"Ú _parse_files  þzConfigHandler._parse_filecCs| t ¡¡std|ƒ‚dS)Nz#`file:` directive can not access %s)r:rrr )rr!r!r"ro-sÿzConfigHandler._assert_localc Cs.tj|dd��}| ¡W5QR£SQRXdS)Nzutf-8)Úencoding)ÚioÚopenÚread)rÚfr!r!r"rp3szConfigHandler._read_filec Csþd}| |¡s|S| |d¡ ¡ d¡}| ¡}d |¡}|p@d}t ¡}|rÂ|d|kr¤||d}| dd¡} t | ƒdkržtj  t ¡| d¡}| d}qÂ|}nd|krÂtj  t ¡|d¡}t j   d|¡zt |ƒ} t| |ƒ}W5t j dd…t _ X|S) z·Represents value as a module attribute. Examples: attr: package.attr attr: package.module.attr :param str value: :rtype: str zattr:r7r8rArú/éN)r:r;r<rYÚpoprsrrÚrsplitrrrÚsysÚinsertrr') rZr/r3Zattr_directiveZ attrs_pathZ attr_nameZ module_nameÚ parent_pathZ custom_pathÚpartsÚmoduler!r!r"Ú _parse_attr8s0        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!)r/ÚparsedÚmethod©Ú parse_methodsr!r"r ns z1ConfigHandler._get_parser_compound..parser!)rZrˆr r!r‡r"Ú_get_parser_compoundes z"ConfigHandler._get_parser_compoundcCs6i}|pdd„}| ¡D]\}\}}||ƒ||<q|S)zÊParses section options into a dictionary. Optionally applies a given parser to values. :param dict section_options: :param callable values_parser: :rtype: dict cSs|Srlr!)rbr!r!r"Úƒóz6ConfigHandler._parse_section_to_dict..)r9)rZr@Z values_parserr/r)Ú_rbr!r!r"Ú_parse_section_to_dictxs  z$ConfigHandler._parse_section_to_dictc Cs<| ¡D].\}\}}z |||<Wqtk r4YqXqdS)zQParses configuration file section. :param dict section_options: N)r9rJ)r>r@ÚnamerŒr/r!r!r"Ú parse_sectionˆs  zConfigHandler.parse_sectioncCsb|j ¡D]R\}}d}|r"d|}t|d| dd¡dƒ}|dkrTtd|j|fƒ‚||ƒq dS)zTParses configuration file items from one or more related sections. r7z_%szparse_section%sr8Ú__Nz0Unsupported distribution option section: [%s.%s])r=r9r'r;r r.)r>r?r@Zmethod_postfixZsection_parser_methodr!r!r"r ”s"üÿÿzConfigHandler.parsecstˆƒ‡‡‡fdd„ƒ}|S)zé this function will wrap around parameters that are deprecated :param msg: deprecation message :param warning_class: class of warning exception to be raised :param func: function to be wrapped around cst ˆˆ¡ˆ||ŽSrl)ÚwarningsÚwarn)ÚargsÚkwargs©ÚfuncÚmsgÚ warning_classr!r"Úconfig_handler³s z@ConfigHandler._deprecated_config_handler..config_handlerr)r>r–r—r˜r™r!r•r"Ú_deprecated_config_handler¬sz(ConfigHandler._deprecated_config_handler)F)rQ)N)N)rEÚ __module__Ú __qualname__Ú__doc__r.rHrAÚpropertyrFrPÚ classmethodr\rcrgrkruÚ staticmethodrorpr„r‰r�r�r ršr!r!r!r"r6~s<  &        ,   r6csHeZdZdZdddddœZdZd‡fd d „ Zed d „ƒZd d„Z ‡Z S)r1r2ZurlÚ descriptionÚ classifiersÚ platforms)Z home_pageZsummaryZ classifierÚplatformFNcstt|ƒ |||¡||_dSrl)Úsuperr1rAr3)r>r(r4rr3©rDr!r"rAÌsÿzConfigMetadataHandler.__init__c CsL|j}|j}|j}|j}|||| |dt¡|| ||¡|dƒ|||j|dœ S)rBz[The requires parameter is deprecated, please use install_requires for runtime dependencies.Úlicense) r£ÚkeywordsZprovidesZrequiresZ obsoletesr¢r§r¡Zlong_descriptionÚversionZ project_urls)r\rurcrkršÚDeprecationWarningr‰Ú_parse_version)r>Ú parse_listZ parse_fileÚ parse_dictZexclude_files_parserr!r!r"rFÒs(ü ñzConfigMetadataHandler.parserscCs�| |¡}||krB| ¡}tt|ƒtƒr>d}t|jftƒŽƒ‚|S| ||j ¡}t |ƒr^|ƒ}t|t ƒsŒt |dƒr„d  tt|ƒ¡}nd|}|S)zSParses `version` option value. :param value: :rtype: str zCVersion loaded from {value} does not comply with PEP 440: {version}Ú__iter__r8z%s)rur<rVr r r r$r%r„r3ÚcallablerÚhasattrrsÚmapÚstr)r>r/r©Ztmplr!r!r"r«ìs  ÿ  z$ConfigMetadataHandler._parse_version)FN) rEr›rœr.rHZ strict_moderAržrFr«Ú __classcell__r!r!r¦r"r1»süÿ r1c@s\eZdZdZedd„ƒZdd„Zdd„Zdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dS)r0r4cCsN|j}t|jdd�}|j}|j}|||||||||||||||j|j|tdœS)rBú;©r[)Zzip_safeZuse_2to3Zinclude_package_datar3Zuse_2to3_fixersZuse_2to3_exclude_fixersZconvert_2to3_doctestsZscriptsZeager_resourcesZdependency_linksZnamespace_packagesZinstall_requiresZsetup_requiresZ tests_requireZpackagesÚ entry_pointsZ py_modulesZpython_requires)r\rrgrcÚ_parse_packagesrur )r>r¬Zparse_list_semicolonZ parse_boolr­r!r!r"rFs.îzConfigOptionsHandler.parserscCszddg}| ¡}||kr"| |¡S||dk}|r>ts>tdƒ‚| |j di¡¡}|rdddlm}n ddlm }|f|ŽS) zTParses `packages` option value. :param value: :rtype: list zfind:zfind_namespace:r|z8find_namespace: directive is unsupported on Python < 3.3z packages.findr)Úfind_namespace_packages)Ú find_packages) r<r\rr Úparse_section_packages__findr=rIZ setuptoolsr¸r¹)r>r/Zfind_directivesZ trimmed_valueZfindnsÚ find_kwargsr¹r!r!r"r·1s   ÿ ÿ z$ConfigOptionsHandler._parse_packagescsT| ||j¡}dddg‰t‡fdd„| ¡Dƒƒ}| d¡}|dk rP|d|d<|S)zœParses `packages.find` configuration file section. To be used in conjunction with _parse_packages(). :param dict section_options: ÚwhereZincludeÚexcludecs$g|]\}}|ˆkr|r||f‘qSr!r!©rSÚkÚv©Z valid_keysr!r"rUZszEConfigOptionsHandler.parse_section_packages__find..Nr)r�r\r,r9rI)r>r@Z section_datar»r¼r!rÁr"rºMsÿ ÿ  z1ConfigOptionsHandler.parse_section_packages__findcCs| ||j¡}||d<dS)z`Parses `entry_points` configuration file section. :param dict section_options: r¶N)r�r\©r>r@r…r!r!r"Úparse_section_entry_pointsbsz/ConfigOptionsHandler.parse_section_entry_pointscCs.| ||j¡}| d¡}|r*||d<|d=|S)NÚ*r7)r�r\rI)r>r@r…Úrootr!r!r"Ú_parse_package_datajs  z(ConfigOptionsHandler._parse_package_datacCs| |¡|d<dS)z`Parses `package_data` configuration file section. :param dict section_options: Z package_dataN©rÆ©r>r@r!r!r"Úparse_section_package_datatsz/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{sÿz7ConfigOptionsHandler.parse_section_exclude_package_datacCs"t|jdd�}| ||¡|d<dS)zbParses `extras_require` configuration file section. :param dict section_options: r´rµZextras_requireN)rr\r�)r>r@r¬r!r!r"Úparse_section_extras_requireƒs ÿz1ConfigOptionsHandler.parse_section_extras_requirecCs(| ||j¡}dd„| ¡Dƒ|d<dS)z^Parses `data_files` configuration file section. :param dict section_options: cSsg|]\}}||f‘qSr!r!r¾r!r!r"rU’szAConfigOptionsHandler.parse_section_data_files..Z data_filesN)r�r\r9rÂr!r!r"Úparse_section_data_filesŒsz-ConfigOptionsHandler.parse_section_data_filesN)rEr›rœr.ržrFr·rºrÃrÆrÉrÊrËrÌr!r!r!r"r0s   r0)FF)F)"Z __future__rrrwrrr‘r&Ú collectionsrrrÚ importlibrZdistutils.errorsr r Z#setuptools.extern.packaging.versionr r Z&setuptools.extern.packaging.specifiersr Zsetuptools.extern.sixrrÚtypeZ __metaclass__r#r+rrr6r1r0r!r!r!r"Ús4     ÿ / ÿ ?U