a `S@sddlZddlZddlZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddl Z ddl m Z mZddlmZmZddlmZGdd d Ze jd d Zdd dZddZddZdddZGdddZGdddeZGdddeZdS)N) defaultdict)partialwraps)DistutilsOptionErrorDistutilsFileError) LegacyVersionparse) SpecifierSetc@s eZdZdZddZddZdS) StaticModulez0 Attempt to load the module by the name cCs`tj|}t|j}|}Wdn1s40Yt|}t| t |` dSN) importlibutil find_specopenoriginreadastr varsupdatelocalsself)rnamespecZstrmsrcmoduler3/usr/lib/python3/dist-packages/setuptools/config.py__init__s   & zStaticModule.__init__c s^ztfdd|jjDWStyX}z$tdjfit|WYd}~n d}~00dS)Nc3sH|]@}t|tjr|jD](}t|tjr|jkrt|jVqqdSr ) isinstancerZAssigntargetsNameidZ literal_evalvalue).0Z statementtargetattrrr !s   z+StaticModule.__getattr__..z#{self.name} has no attribute {attr})nextrbody ExceptionAttributeErrorformatr)rr'err&r __getattr__s  zStaticModule.__getattr__N)__name__ __module__ __qualname____doc__rr/rrrrr sr c cs8z$tjd|dVWtj|ntj|0dS)zH Add path to front of sys.path for the duration of the context. rN)syspathinsertremove)r5rrr patch_path.sr8Fc Csddlm}m}tj|}tj|s4td|t}t tj |zT|}|rb| ng}||vrx| ||j ||dt||j|d}Wt |n t |0t|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.distr9r:osr5abspathisfilergetcwdchdirdirnameZfind_config_filesappendZparse_config_filesparse_configurationcommand_optionsconfiguration_to_dict) filepathZ find_othersr<r9r:Zcurrent_directoryZdistr;handlersrrrread_configuration:s(   rIcCs2djfit}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})r-r functoolsrgetattr) target_objkeyZ getter_nameZ by_attributegetterrrr _get_optionis rOcCs<tt}|D]*}|jD]}t|j|}|||j|<qq |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_optionsrOrLsection_prefix)rHZ config_dictZhandlerZoptionr#rrrrFus   rFcCs6t|||}|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 )ConfigOptionsHandlerr ConfigMetadataHandlermetadata package_dir)Z distributionrEr<optionsmetarrrrDsrDc@seZdZdZdZiZd%ddZeddZdd Z e d&d d Z e d dZ e ddZ e ddZe ddZeddZeddZe d'ddZe ddZe d(ddZdd Zd!d"Zd#d$ZdS)) ConfigHandlerz1Handles metadata supplied in configuration files.NFcCs^i}|j}|D].\}}||s&q||dd}|||<q||_||_||_g|_dS)N.) rRitems startswithreplacestripr<rLsectionsrQ)rrLrWr<r`rR section_namesection_optionsrrrrs  zConfigHandler.__init__cCstd|jjdS).Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)NotImplementedError __class__r0)rrrrparserss zConfigHandler.parsersc Cst}|j}|j||}t|||}||ur6t||r>dSd}|j|}|r~z ||}Wnty|d}|jsxYn0|rdSt|d|d}|durt |||n|||j |dS)NFTzset_%s) tuplerLaliasesgetrKKeyErrorrfr+r<setattrrQrC) rZ option_namer#unknownrLZ current_valueZ skip_optionparsersetterrrr __setitem__s0    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)r_)r$chunkrrr z-ConfigHandler._parse_list..)rlist splitlinessplit)clsr# separatorrrr _parse_lists   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)rz partitionrr_)rxr#ryresultlinerMsepvalrrr _parse_dictszConfigHandler._parse_dictcCs|}|dvS)zQRepresents value as boolean. :param value: :rtype: bool )1trueZyes)lower)rxr#rrr _parse_boolszConfigHandler._parse_boolcsfdd}|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)r] ValueErrorr-)r#Zexclude_directiverMrrrm)s z3ConfigHandler._exclude_files_parser..parserr)rxrMrmrrr_exclude_files_parsers 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 )r=r5r>r_r$r5rrrr(Irtz,ConfigHandler._parse_file..rprqc3s.|]&}|stj|r|VqdS)TN) _assert_localr=r5r? _read_filerrxrrr(Js  )rstrr]lenrwjoin)rxr#Zinclude_directiverZ filepathsrrr _parse_file2s  zConfigHandler._parse_filecCs|tstd|dS)Nz#`file:` directive can not access %s)r]r=r@r)rGrrrrQszConfigHandler._assert_localcCs:tj|dd}|WdS1s,0YdS)Nzutf-8)encoding)iorr)rGfrrrrWszConfigHandler._read_filec Cs4d}||s|S||dd}|}d|}|p@d}t}|r|d|vr||d}|dd} t | dkrtj t| d}| d}q|}nd|vrtj t|d}t |Nzt t ||WWdStyt|} Yn0Wdn1s 0Yt | |S) zRepresents value as a module attribute. Examples: attr: package.attr attr: package.module.attr :param str value: :rtype: str zattr:rZr[rr/N)r]r^r_rwpoprr=r@rsplitrr5r8rKr r+r import_module) rxr#rVZattr_directiveZ attrs_pathZ attr_nameZ module_name parent_pathZ custom_pathpartsrrrr _parse_attr\s0         0zConfigHandler._parse_attrcsfdd}|S)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_methodsrrr s z1ConfigHandler._get_parser_compound..parser)rxrr rrr_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)rrrrrtz6ConfigHandler._parse_section_to_dict..)r\)rxrbZ values_parserr#rM_rrrr_parse_section_to_dicts  z$ConfigHandler._parse_section_to_dictc Cs:|D],\}\}}z |||<Wqty2Yq0qdS)zQParses configuration file section. :param dict section_options: N)r\rj)rrbrrr#rrr parse_sections   zConfigHandler.parse_sectioncCsb|jD]R\}}d}|r"d|}t|d|ddd}|durTtd|j|f||q dS)zTParses configuration file items from one or more related sections. rZz_%szparse_section%sr[__Nz0Unsupported distribution option section: [%s.%s])r`r\rKr^rrR)rrarbZmethod_postfixZsection_parser_methodrrrr s zConfigHandler.parsecstfdd}|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|i|Sr )warningswarn)argskwargsfuncmsg warning_classrrconfig_handlers z@ConfigHandler._deprecated_config_handler..config_handlerr)rrrrrrrr_deprecated_config_handlersz(ConfigHandler._deprecated_config_handler)F)rp)N)N)r0r1r2r3rRrhrpropertyrfro classmethodrzrrrr staticmethodrrrrrrr rrrrrrYs<  &        -   rYcsHeZdZdZdddddZdZdfd d Zed d Zd dZ Z S)rTrUZurl description classifiers platforms)Z home_pageZsummaryZ classifierplatformFNcstt||||||_dSr )superrTrrV)rrLrWr<rVrerrrszConfigMetadataHandler.__init__c CsN|j}|j}|j}|j}|||||dt|||||d||||j|d S)rcz[The requires parameter is deprecated, please use install_requires for runtime dependencies.license) rkeywordsZprovidesZrequiresZ obsoletesrrZ license_filesrZlong_descriptionversionZ project_urls)rzrrrrDeprecationWarningr_parse_version)r parse_listZ parse_file parse_dictZexclude_files_parserrrrrfs* zConfigMetadataHandler.parserscCs||}||krF|}tt|trBd}t|jfit|S|||j }t |rb|}t|t st |drd tt |}nd|}|S)zSParses `version` option value. :param value: :rtype: str zCVersion loaded from {value} does not comply with PEP 440: {version}__iter__r[z%s)rr_rr rrr-rrrVcallablerhasattrrmap)rr#rZtmplrrrrs    z$ConfigMetadataHandler._parse_version)FN) r0r1r2rRrhZ strict_moderrrfr __classcell__rrrrrTs rTc@s\eZdZdZeddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ dS)rSrWcCsN|j}t|jdd}|j}|j}|||||||||||||||j|j|tdS)rc;ry)Zzip_safeZuse_2to3Zinclude_package_datarVZuse_2to3_fixersZuse_2to3_exclude_fixersZconvert_2to3_doctestsZscriptsZeager_resourcesZdependency_linksZnamespace_packagesZinstall_requiresZsetup_requiresZ tests_requireZpackages entry_pointsZ py_modulesZpython_requires)rzrrr_parse_packagesrr )rrZparse_list_semicolonZ parse_boolrrrrrf:s.zConfigOptionsHandler.parserscCsnddg}|}||vr"||S||dk}||jdi}|rTddlm}n ddlm}|fi|S)zTParses `packages` option value. :param value: :rtype: list zfind:zfind_namespace:rz packages.findr)find_namespace_packages) find_packages)r_rzparse_section_packages__findr`riZ setuptoolsrr)rr#Zfind_directivesZ trimmed_valueZfindns find_kwargsrrrrrWs    z$ConfigOptionsHandler._parse_packagescsR|||j}gdtfdd|D}|d}|durN|d|d<|S)zParses `packages.find` configuration file section. To be used in conjunction with _parse_packages(). :param dict section_options: )whereZincludeZexcludecs$g|]\}}|vr|r||fqSrrr$kvZ valid_keysrrrs}rtzEConfigOptionsHandler.parse_section_packages__find..rNr)rrzrPr\ri)rrbZ section_datarrrrrrps  z1ConfigOptionsHandler.parse_section_packages__findcCs|||j}||d<dS)z`Parses `entry_points` configuration file section. :param dict section_options: rN)rrzrrbrrrrparse_section_entry_pointssz/ConfigOptionsHandler.parse_section_entry_pointscCs.|||j}|d}|r*||d<|d=|S)N*rZ)rrzri)rrbrrootrrr_parse_package_datas  z(ConfigOptionsHandler._parse_package_datacCs|||d<dS)z`Parses `package_data` configuration file section. :param dict section_options: Z package_dataNrrrbrrrparse_section_package_datasz/ConfigOptionsHandler.parse_section_package_datacCs|||d<dS)zhParses `exclude_package_data` configuration file section. :param dict section_options: Zexclude_package_dataNrrrrr"parse_section_exclude_package_datasz7ConfigOptionsHandler.parse_section_exclude_package_datacCs"t|jdd}||||d<dS)zbParses `extras_require` configuration file section. :param dict section_options: rrZextras_requireN)rrzr)rrbrrrrparse_section_extras_requiresz1ConfigOptionsHandler.parse_section_extras_requirecCs(|||j}dd|D|d<dS)z^Parses `data_files` configuration file section. :param dict section_options: cSsg|]\}}||fqSrrrrrrrsrtzAConfigOptionsHandler.parse_section_data_files..Z data_filesN)rrzr\rrrrparse_section_data_filessz-ConfigOptionsHandler.parse_section_data_filesN)r0r1r2rRrrfrrrrrrrrrrrrrS6s   rS)FF)F)rrr=r4rrJr collectionsrrr contextlibZdistutils.errorsrrZ#setuptools.extern.packaging.versionrr Z&setuptools.extern.packaging.specifiersr r contextmanagerr8rIrOrFrDrYrTrSrrrrs6     /  @V