o _aqZ@sddlZddlZddlZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddl m Z ddl Z ddlmZmZddlmZmZddlmZGd d d Ze jd d ZdddZddZddZdddZGdddZGdddeZGdddeZdS)N) defaultdict)partialwraps)iglob)DistutilsOptionErrorDistutilsFileError)VersionInvalidVersion) SpecifierSetc@s eZdZdZddZddZdS) StaticModulez0 Attempt to load the module by the name cCs`tj|}t|j }|}Wdn1swYt|}t| t |` dSN) importlibutil find_specopenoriginreadastparsevarsupdatelocalsself)rnamespecstrmsrcmoduler3/usr/lib/python3/dist-packages/setuptools/config.py__init__s    zStaticModule.__init__c sNztfdd|jjDWSty&}z tdjdit|d}~ww)Nc3sJ|] }t|tjr"|jD]}t|tjr!|jkr t|jVq qdSr ) isinstancerAssigntargetsNameid literal_evalvalue).0 statementtargetattrrr #s    z+StaticModule.__getattr__..z#{self.name} has no attribute {attr}r)nextrbody ExceptionAttributeErrorformatr)rr-err,r __getattr__!s  zStaticModule.__getattr__N)__name__ __module__ __qualname____doc__r!r5rrrr r s r c cs8ztjd|dVWtj|dStj|w)zH Add path to front of sys.path for the duration of the context. rN)syspathinsertremove)r;rrr patch_path0s r>Fc Csddlm}m}tj|}tj|std|t}t tj |z-|}|r1| ng}||vr<| ||j ||dt||j|d}Wt |t|St |w)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)setuptools.distr?r@osr;abspathisfilergetcwdchdirdirnamefind_config_filesappendparse_config_filesparse_configurationcommand_optionsconfiguration_to_dict) filepath find_othersrBr?r@current_directorydistrAhandlersrrr read_configuration<s$      rUcCs2djdit}tt||}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}Nr)r3r functoolsrgetattr) target_objkey getter_name by_attributegetterrrr _get_optionis r]cCs<tt}|D]}|jD]}t|j|}|||j|<q q|S)zReturns configuration data gathered by given handlers as a dict. :param list[ConfigHandler] handlers: Handlers list, usually from parse_configuration() :rtype: dict )rdict set_optionsr]rXsection_prefix)rT config_dicthandleroptionr(rrr rOus  rOcCs6t|||}|t|j|||j}|||fS)aPerforms 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 )ConfigOptionsHandlerrConfigMetadataHandlermetadata package_dir) distributionrNrBoptionsmetarrr rMs rMc@seZdZdZdZ iZ d'ddZeddZdd Z e d(d d Z e d(d dZ e ddZ e ddZe ddZe ddZeddZeddZe d)ddZe ddZe d)dd Zd!d"Zd#d$Zd%d&ZdS)* ConfigHandlerz1Handles metadata supplied in configuration files.NFcCs^i}|j}|D]\}}||sq ||dd}|||<q ||_||_||_g|_dS)N.) r`items startswithreplacestriprBrXsectionsr_)rrXrirBrrr` section_namesection_optionsrrr r!s   zConfigHandler.__init__cCstd|jj).Metadata item name to parser function mapping.z!%s must provide .parsers property)NotImplementedError __class__r6)rrrr parserss zConfigHandler.parsersc Cst}|j}|j||}t|||}||urt||rdSd}|j|}|r?z||}Wnty>d}|js<Ynw|rCdSt|d|d}|durVt |||n|||j |dS)NFTzset_%s) tuplerXaliasesgetrWKeyErrorrxr1rBsetattrr_rK) r option_namer(unknownrX current_value skip_optionparsersetterrrr __setitem__s4    zConfigHandler.__setitem__,cCs8t|tr|Sd|vr|}n||}dd|DS)zRepresents 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)rq)r)chunkrrr sz-ConfigHandler._parse_list..)r"list splitlinessplit)clsr( separatorrrr _parse_lists   zConfigHandler._parse_listc sjd}|j|d}g}|D]%tfdd|Dr-|tddttjDq |q |S)aEquivalent to _parse_list() but expands any glob patterns using glob(). However, unlike with glob() calls, the results remain relative paths. :param value: :param separator: List items separator character. :rtype: list )*?[]{}rc3s|]}|vVqdSr r)r)charr(rr r.sz1ConfigHandler._parse_list_glob..css"|] }tj|tVqdSr )rDr;relpathrGr)r;rrr r.s  ) ranyextendsortedrrDr;rErK)rr(rglob_charactersvaluesexpanded_valuesrrr _parse_list_globs   zConfigHandler._parse_list_globcCsPd}i}||D]}||\}}}||krtd||||<q |S)zPRepresents value as a dict. :param value: :rtype: dict =z(Unable to parse option value to dict: %s)r partitionrrq)rr(rresultlinerYsepvalrrr _parse_dict szConfigHandler._parse_dictcCs|}|dvS)zQRepresents value as boolean. :param value: :rtype: bool )1trueyes)lower)rr(rrr _parse_bool3szConfigHandler._parse_boolcfdd}|S)zReturns 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)Nfile:zCOnly strings are accepted for the {0} field, files are not accepted)ro ValueErrorr3)r(exclude_directiverYrr rIs z3ConfigHandler._exclude_files_parser..parserr)rrYrrrr _exclude_files_parser=s  z#ConfigHandler._exclude_files_parsercs\d}t|ts |S||s|S|t|d}dd|dD}dfdd|DS)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 rNcss |] }tj|VqdSr )rDr;rErqrrrr r.ksz,ConfigHandler._parse_file..rrc3s4|]}|s tj|r|VqdS)TN) _assert_localrDr;rF _read_filerrrr r.ls  )r"strrolenrjoin)rr(include_directiver filepathsrrr _parse_fileTs  zConfigHandler._parse_filecCs|ts td|dS)Nz#`file:` directive can not access %s)rorDrGr)rPrrr rrs zConfigHandler._assert_localcCs:tj|dd }|WdS1swYdS)Nzutf-8)encoding)iorr)rPfrrr rws$zConfigHandler._read_filec Cs0d}||s |S||dd}|}d|}|p d}t}|ra|d|vrR||d}|dd} t | dkrOtj t| d}| d}n|}nd|vratj t|d}t |&zt t ||WWdStyt|} YnwWdn1swYt | |S) zRepresents value as a module attribute. Examples: attr: package.attr attr: package.module.attr :param str value: :rtype: str zattr:rlrmr!r/N)rorprqrpoprrDrGrsplitrr;r>rWr r1r import_module) rr(rgattr_directive attrs_path attr_name module_name parent_path custom_pathpartsrrrr _parse_attr|s8          zConfigHandler._parse_attrcr)zReturns 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|Sr r)r(parsedmethod parse_methodsrr rs z1ConfigHandler._get_parser_compound..parser)rrrrrr _get_parser_compounds z"ConfigHandler._get_parser_compoundcCs6i}|pdd}|D] \}\}}||||<q |S)zParses section options into a dictionary. Optionally applies a given parser to values. :param dict section_options: :param callable values_parser: :rtype: dict cSs|Sr r)rrrr sz6ConfigHandler._parse_section_to_dict..)rn)rrt values_parserr(rY_rrrr _parse_section_to_dicts  z$ConfigHandler._parse_section_to_dictc Cs8|D]\}\}}z|||<WqtyYqwdS)zQParses configuration file section. :param dict section_options: N)rnr|)rrtrrr(rrr parse_sections  zConfigHandler.parse_sectioncCsb|jD])\}}d}|rd|}t|d|ddd}|dur*td|j|f||qdS)zTParses configuration file items from one or more related sections. rlz_%szparse_section%srm__Nz0Unsupported distribution option section: [%s.%s])rrrnrWrprr`)rrsrtmethod_postfixsection_parser_methodrrr rs" zConfigHandler.parsecstfdd}|S)zthis 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|i|Sr )warningswarn)argskwargsfuncmsg warning_classrr config_handlers z@ConfigHandler._deprecated_config_handler..config_handlerr)rrrrrrrr _deprecated_config_handlersz(ConfigHandler._deprecated_config_handlerF)rr )r6r7r8r9r`rzr!propertyrxr classmethodrrrrrr staticmethodrrrrrrrrrrrr rksF  &         -   rkcsLeZdZdZdddddZdZ dfd d Zed d Zd dZ Z S)rerfurl description classifiers platforms) home_pagesummary classifierplatformFNcstt||||||_dSr )superrer!rg)rrXrirBrgrwrr r!s  zConfigMetadataHandler.__init__cCs^|j}|j}|j}|j}|||||dt|||||d||ddt||||j|d S)ruz[The requires parameter is deprecated, please use install_requires for runtime dependencies.license license_filezDThe license_file parameter is deprecated, use license_files instead.) rkeywordsprovidesrequires obsoletesrrr license_filesrlong_descriptionversion project_urls)rrrrrDeprecationWarningr_parse_version)r parse_list parse_file parse_dictexclude_files_parserrrr rxs4 zConfigMetadataHandler.parserscCs||}||kr)|}zt|W|Sty(d}t|jditw|||j}t |r7|}t |t sOt |drKd tt |}|Sd|}|S)zSParses `version` option value. :param value: :rtype: str zCVersion loaded from {value} does not comply with PEP 440: {version}__iter__rmz%sNr)rrqr r rr3rrrgcallabler"rhasattrrmap)rr(rtmplrrr r?s(      z$ConfigMetadataHandler._parse_version)FN) r6r7r8r`rz strict_moder!rrxr __classcell__rrrr res !rec@sdeZdZdZeddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZdS)rdricCsN|j}t|jdd}|j}|j}|j}|||||||||||j|j|t|dS)ru;r)zip_safeinclude_package_datargscriptseager_resourcesdependency_linksnamespace_packagesinstall_requiressetup_requires tests_requirepackages entry_points py_modulespython_requirescmdclass)rrrr_parse_cmdclass_parse_packagesrr )rrparse_list_semicolon parse_boolrparse_cmdclassrrr rxis*zConfigOptionsHandler.parserscs$ddfdd||DS)NcSs8|d}||dd}|d|}t|}t||S)Nrmr)rfind __import__rW)qualified_class_nameidx class_namepkg_namerrrr resolve_classs   z;ConfigOptionsHandler._parse_cmdclass..resolve_classcsi|] \}}||qSrrr)kvr"rr sz8ConfigOptionsHandler._parse_cmdclass..)rrn)rr(rr&r rs z$ConfigOptionsHandler._parse_cmdclasscCsnddg}|}||vr||S||dk}||jdi}|r*ddlm}nddlm}|d i|S) zTParses `packages` option value. :param value: :rtype: list zfind:zfind_namespace:rz packages.findr)find_namespace_packages) find_packagesNr)rqrparse_section_packages__findrrr{ setuptoolsr(r))rr(find_directives trimmed_valuefindns find_kwargsr)rrr rs    z$ConfigOptionsHandler._parse_packagescsR|||j}gdtfdd|D}|d}|dur'|d|d<|S)zParses `packages.find` configuration file section. To be used in conjunction with _parse_packages(). :param dict section_options: )whereincludeexcludecs$g|]\}}|vr|r||fqSrrr# valid_keysrr rs$zEConfigOptionsHandler.parse_section_packages__find..r0Nr)rrr^rnr{)rrt section_datar/r0rr3r r*s  z1ConfigOptionsHandler.parse_section_packages__findcCs|||j}||d<dS)z`Parses `entry_points` configuration file section. :param dict section_options: rN)rrrrtrrrr parse_section_entry_pointss z/ConfigOptionsHandler.parse_section_entry_pointscCs.|||j}|d}|r||d<|d=|S)Nrrl)rrr{)rrtrrootrrr _parse_package_datas  z(ConfigOptionsHandler._parse_package_datacC|||d<dS)z`Parses `package_data` configuration file section. :param dict section_options: package_dataNr9rrtrrr parse_section_package_dataz/ConfigOptionsHandler.parse_section_package_datacCr:)zhParses `exclude_package_data` configuration file section. :param dict section_options: exclude_package_dataNr<r=rrr "parse_section_exclude_package_datar?z7ConfigOptionsHandler.parse_section_exclude_package_datacCs"t|jdd}||||d<dS)zbParses `extras_require` configuration file section. :param dict section_options: rrextras_requireN)rrr)rrtrrrr parse_section_extras_requires z1ConfigOptionsHandler.parse_section_extras_requirecCs(|||j}dd|D|d<dS)z^Parses `data_files` configuration file section. :param dict section_options: cSsg|]\}}||fqSrrr#rrr rszAConfigOptionsHandler.parse_section_data_files.. data_filesN)rrrnr6rrr parse_section_data_filessz-ConfigOptionsHandler.parse_section_data_filesN)r6r7r8r`rrxrrr*r7r9r>rArCrErrrr rdes    rd)FFr) rrrDr:rrVr collectionsrrrglobr contextlibdistutils.errorsrr#setuptools.extern.packaging.versionr r &setuptools.extern.packaging.specifiersr r contextmanagerr>rUr]rOrMrkrerdrrrr s6       - ca