3 eqZ@sddlZddlZddlZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddl m Z ddl Z ddlmZmZddlmZmZddlmZGd d d Ze jd d ZdddZddZddZdddZGdddZGdddeZGdddeZdS)N) defaultdict)partial)wraps)iglob)DistutilsOptionErrorDistutilsFileError)VersionInvalidVersion) SpecifierSetc@s eZdZdZddZddZdS) StaticModulez0 Attempt to load the module by the name c CsLtjj|}t|j}|j}WdQRXtj|}t|j t |` dS)N) importlibutil find_specopenoriginreadastparsevarsupdatelocalsself)rnamespecstrmsrcmoduler7/tmp/pip-build-vlmub77e/setuptools/setuptools/config.py__init__s    zStaticModule.__init__csVytfdd|jjDStk rP}ztdjft|WYdd}~XnXdS)Nc3sH|]@}t|tjr|jD](}t|tjr|jkrtj|jVqqdS)N) isinstancerZAssigntargetsNameidZ literal_evalvalue).0Z statementtarget)attrrr $s  z+StaticModule.__getattr__..z#{self.name} has no attribute {attr})nextrbody ExceptionAttributeErrorformatr)rr'er)r'r __getattr__!s zStaticModule.__getattr__N)__name__ __module__ __qualname____doc__rr/rrrrr sr c cs,ztjjd|dVWdtjj|XdS)zH Add path to front of sys.path for the duration of the context. rN)syspathinsertremove)r5rrr patch_path0s r8Fc Csddlm}m}tjj|}tjj|s4td|tj}tj tjj |zJ|}|rb|j ng}||krx|j ||j ||dt||j|d}Wdtj |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_errorsN)Zsetuptools.distr9r:osr5abspathisfilergetcwdchdirdirnamefind_config_filesappendparse_config_filesparse_configurationcommand_optionsconfiguration_to_dict) filepathZ find_othersr<r9r:Zcurrent_directorydistr;handlersrrrread_configuration<s      rLcCs.djft}tjt||}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 rRcCsDtt}x6|D].}x(|jD]}t|j|}|||j|<qWqW|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_optionsrRrOsection_prefix)rKZ config_dicthandleroptionr$rrrrHus    rHcCs6t|||}|jt|j|||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) distributionrGr<optionsmetarrrrFs rFc@seZdZdZdZiZd'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.NFcCsbi}|j}x:|jD].\}}|j|s(q|j|djd}|||<qW||_||_||_g|_dS)N.) rUitems startswithreplacestripr<rOsectionsrT)rrOr]r<rfrU section_namesection_optionsrrrrs  zConfigHandler.__init__cCstd|jjdS)z.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)NotImplementedError __class__r0)rrrrparsersszConfigHandler.parsersc Cst}|j}|jj||}t|||}||kr6t||r>dSd}|jj|}|ry ||}Wn tk r~d}|jszYnX|rdSt|d|d}|dkrt |||n|||j j |dS)NFTzset_%s) tuplerOaliasesgetrNKeyErrorrkr+r<setattrrTrD) rZ option_namer$unknownrOZ current_valueZ skip_optionparsersetterrrr __setitem__s0   zConfigHandler.__setitem__,cCs8t|tr|Sd|kr |j}n |j|}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|]}|jr|jqSr)re)r%chunkrrr sz-ConfigHandler._parse_list..)r list splitlinessplit)clsr$ separatorrrr _parse_lists   zConfigHandler._parse_listcsnd }|j|d}g}xR|D]Jtfdd |Dr\|jtd d ttjjDq|jqW|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 *?[]{})r}c3s|]}|kVqdS)Nr)r%char)r$rrr(sz1ConfigHandler._parse_list_glob..css |]}tjj|tjVqdS)N)r=r5relpathr@)r%r5rrrr(s)rrrrrr) r~anyextendsortedrr=r5r>rD)r|r$r}Zglob_charactersvaluesZexpanded_valuesr)r$r_parse_list_globs  zConfigHandler._parse_list_globcCsTd}i}xF|j|D]8}|j|\}}}||kr.parserr)r|rPrrr)rPr_exclude_files_parser=s z#ConfigHandler._exclude_files_parsercs\d}t|ts|S|j|s |S|t|d}dd|jdD}djfdd|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 zfile:Ncss|]}tjj|jVqdS)N)r=r5r>re)r%r5rrrr(ksz,ConfigHandler._parse_file..rurvc3s2|]*}j|sdrtjj|rj|VqdS)TN) _assert_localr=r5r? _read_file)r%r5)r|rrr(ms)r strrclenr{join)r|r$Zinclude_directiverZ filepathsr)r|r _parse_fileTs   zConfigHandler._parse_filecCs|jtjstd|dS)Nz#`file:` directive can not access %s)rcr=r@r)rIrrrrrszConfigHandler._assert_localc Cs"tj|dd }|jSQRXdS)Nzutf-8)encoding)iorr)rIfrrrrwszConfigHandler._read_filec Csd}|j|s|S|j|djjd}|j}dj|}|p@d}tj}|r|d|kr||d}|jdd} t | dkrtj jtj| d}| d}q|}nd|krtj jtj|d}t |4yt t ||Stk rtj|} YnXWdQRXt | |S) zRepresents value as a module attribute. Examples: attr: package.attr attr: package.module.attr :param str value: :rtype: str zattr:r`rarr/N)rcrdrer{poprr=r@rsplitrr5r8rNr r+r import_module) r|r$r[Zattr_directiveZ attrs_path attr_name module_name parent_pathZ custom_pathpartsrrrr _parse_attr|s0         zConfigHandler._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|}xD] }||}q W|S)Nr)r$parsedmethod) parse_methodsrrrs  z1ConfigHandler._get_parser_compound..parser)r|rrr)rr_get_parser_compounds z"ConfigHandler._get_parser_compoundcCs:i}|pdd}x$|jD]\}\}}||||<qW|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|S)Nr)rrrrsz6ConfigHandler._parse_section_to_dict..)rb)r|rhZ values_parserr$rP_rrrr_parse_section_to_dicts  z$ConfigHandler._parse_section_to_dictc Cs@x:|jD].\}\}}y |||<Wq tk r6Yq Xq WdS)zQParses configuration file section. :param dict section_options: N)rbro)rrhrrr$rrr parse_sections  zConfigHandler.parse_sectioncCsfx`|jjD]R\}}d}|r$d|}t|d|jddd}|dkrVtd|j|f||q WdS)zTParses configuration file items from one or more related sections. r`z_%szparse_section%sra__Nz0Unsupported distribution option section: [%s.%s])rfrbrNrdrrU)rrgrhZmethod_postfixZsection_parser_methodrrrrszConfigHandler.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 cstj||S)N)warningswarn)argskwargs)funcmsg warning_classrrconfig_handlers z@ConfigHandler._deprecated_config_handler..config_handler)r)rrrrrr)rrrr_deprecated_config_handlersz(ConfigHandler._deprecated_config_handler)F)ru)ru)N)N)r0r1r2r3rUrmrpropertyrkrt classmethodr~rrrrr staticmethodrrrrrrrrrrrrr_s0  &        -   r_csHeZdZdZdddddZdZdfd d Zed d Zd dZ Z S)rYrZurl description classifiers platforms)Z home_pagesummary classifierplatformFNcstt|j|||||_dS)N)superrYrr[)rrOr]r<r[)rjrrrs  zConfigMetadataHandler.__init__cCs^|j}|j}|j}|j}||||j|dt||j|||d|j|ddt||||j|d S)z.Metadata item name to parser function mapping.z[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 obsoletesrrrZ license_filesrlong_descriptionversionZ project_urls)r~rrrrDeprecationWarningr_parse_version)r parse_listZ parse_file parse_dictZexclude_files_parserrrrrks. zConfigMetadataHandler.parsersc Cs|j|}||krV|j}y t|Wn*tk rPd}t|jftYnX|S|j||j}t |rr|}t |t st |drdj tt |}nd|}|S)zSParses `version` option value. :param value: :rtype: str zCVersion loaded from {value} does not comply with PEP 440: {version}__iter__raz%s)rrerr rr-rrr[callabler rhasattrrmap)rr$rtmplrrrr?s"    z$ConfigMetadataHandler._parse_version)FN) r0r1r2rUrmZ strict_moderrrkr __classcell__rr)rjrrYs "rYc@sdeZdZdZeddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZdS)rXr]cCsN|j}t|jdd}|j}|j}|j}|||||||||||j|j|t|dS)z.Metadata item name to parser function mapping.;)r})Zzip_safeZinclude_package_datar[scriptsZeager_resourcesdependency_linksZnamespace_packagesZinstall_requiresZsetup_requiresZ tests_requirepackages entry_points py_modulesZpython_requirescmdclass)r~rrr_parse_cmdclass_parse_packagesrr )rrZparse_list_semicolonZ parse_boolrZparse_cmdclassrrrrkis(zConfigOptionsHandler.parserscs$ddfdd|j|jDS)NcSs8|jd}||dd}|d|}t|}t||S)Nrar)rfind __import__rN)Zqualified_class_nameidx class_namepkg_namerrrr resolve_classs   z;ConfigOptionsHandler._parse_cmdclass..resolve_classcsi|]\}}||qSrr)r%kv)rrr sz8ConfigOptionsHandler._parse_cmdclass..)rrb)rr$r)rrrs z$ConfigOptionsHandler._parse_cmdclasscCsjddg}|j}||kr"|j|S||dk}|j|jjdi}|rTddlm}n ddlm}|f|S)zTParses `packages` option value. :param value: :rtype: list zfind:zfind_namespace:rz packages.findr)find_namespace_packages) find_packages)rer~parse_section_packages__findrfrn setuptoolsrr)rr$Zfind_directivesZ trimmed_valueZfindns find_kwargsrrrrrs   z$ConfigOptionsHandler._parse_packagescsT|j||j}dddgtfdd|jD}|jd}|dk rP|d|d<|S)zParses `packages.find` configuration file section. To be used in conjunction with _parse_packages(). :param dict section_options: whereincludeexcludecs$g|]\}}|kr|r||fqSrr)r%rr) valid_keysrrrxszEConfigOptionsHandler.parse_section_packages__find..Nr)rr~rSrbrn)rrhZ section_datarrr)rrrs   z1ConfigOptionsHandler.parse_section_packages__findcCs|j||j}||d<dS)z`Parses `entry_points` configuration file section. :param dict section_options: rN)rr~)rrhrrrrparse_section_entry_pointssz/ConfigOptionsHandler.parse_section_entry_pointscCs.|j||j}|jd}|r*||d<|d=|S)Nrr`)rr~rn)rrhrrootrrr_parse_package_datas  z(ConfigOptionsHandler._parse_package_datacCs|j||d<dS)z`Parses `package_data` configuration file section. :param dict section_options: package_dataN)r)rrhrrrparse_section_package_datasz/ConfigOptionsHandler.parse_section_package_datacCs|j||d<dS)zhParses `exclude_package_data` configuration file section. :param dict section_options: Zexclude_package_dataN)r)rrhrrr"parse_section_exclude_package_datasz7ConfigOptionsHandler.parse_section_exclude_package_datacCs"t|jdd}|j|||d<dS)zbParses `extras_require` configuration file section. :param dict section_options: r)r}Zextras_requireN)rr~r)rrhrrrrparse_section_extras_requiresz1ConfigOptionsHandler.parse_section_extras_requirecCs(|j||j}dd|jD|d<dS)z^Parses `data_files` configuration file section. :param dict section_options: cSsg|]\}}||fqSrr)r%rrrrrrxszAConfigOptionsHandler.parse_section_data_files.. data_filesN)rrrb)rrhrrrrparse_section_data_filessz-ConfigOptionsHandler.parse_section_data_filesN)r0r1r2rUrrkrrrrrrrrrrrrrrXes    rX)FF)F) rrr=r4rrMr collectionsrrrglobr contextlibZdistutils.errorsrrZ#setuptools.extern.packaging.versionrr Z&setuptools.extern.packaging.specifiersr r contextmanagerr8rLrRrHrFr_rYrXrrrrs2      -  ca