3 (\O@sddlmZmZddlZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddl m Z ddlmZmZddlmZmZdd lmZmZeZdd d Zd dZddZdddZGdddZGdddeZGdddeZdS))absolute_importunicode_literalsN) defaultdict)partial)wraps) import_module)DistutilsOptionErrorDistutilsFileError) LegacyVersionparse) string_typesPY3Fc 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.distrrospathabspathisfiler getcwdchdirdirnamefind_config_filesappendparse_config_filesparse_configurationcommand_optionsconfiguration_to_dict) filepathZ find_othersrrrZcurrent_directorydistrhandlersr"m/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-rm6ck8ia/setuptools/setuptools/config.pyread_configurations$      r$cCs.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})formatlocals functoolsrgetattr) target_objkeyZ getter_nameZ by_attributegetterr"r"r# _get_optionDs r,cCsDtt}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_optionsr,r)section_prefix)r!Z config_dicthandleroptionvaluer"r"r#rPs    rcCs6t|||}|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 )ConfigOptionsHandlerr ConfigMetadataHandlermetadata package_dir) distributionrroptionsmetar"r"r#rbs rc@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.NFcCsbi}|j}x:|jD].\}}|j|s(q|j|djd}|||<qW||_||_||_g|_dS)N.) r/items startswithreplacestriprr)sectionsr.)selfr)r8rrAr/ section_namesection_optionsr"r"r#__init__s  zConfigHandler.__init__cCstd|jjdS)z.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)NotImplementedError __class____name__)rBr"r"r#parsersszConfigHandler.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) tupler)aliasesgetr(KeyErrorrI Exceptionrsetattrr.r) rBZ option_namer2unknownr)Z current_valueZ skip_optionparsersetterr"r"r# __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")r@).0chunkr"r"r# sz-ConfigHandler._parse_list..) isinstancelist splitlinessplit)clsr2 separatorr"r"r# _parse_lists   zConfigHandler._parse_listcCsTd}i}xF|j|D]8}|j|\}}}||kr ValueErrorr%)r2Zexclude_directive)r*r"r#rQs  z3ConfigHandler._exclude_files_parser..parserr")r]r*rQr")r*r#_exclude_files_parsers 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)rrrr@)rVrr"r"r# $sz,ConfigHandler._parse_file..rTrUc3s2|]*}j|sdrtjj|rj|VqdS)TN) _assert_localrrr _read_file)rVr)r]r"r#rn&s)rYr r>lenr\join)r]r2Zinclude_directivespecZ filepathsr")r]r# _parse_file s   zConfigHandler._parse_filecCs|jtjstd|dS)Nz#`file:` directive can not access %s)r>rrr)rr"r"r#ro,szConfigHandler._assert_localc Cs"tj|dd }|jSQRXdS)Nzutf-8)encoding)ioopenread)rfr"r"r#rp2szConfigHandler._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 j j d|zt |} t| |}Wdt j ddt _ X|S) zRepresents value as a module attribute. Examples: attr: package.attr attr: package.module.attr :param str value: :rtype: str zattr:r;r<rEr/N)r>r?r@r\poprrrrrsplitrqrsysinsertrr() r]r2r6Zattr_directiveZ attrs_path attr_name module_name parent_pathZ custom_pathpartsmoduler"r"r# _parse_attr7s0        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")r2parsedmethod) parse_methodsr"r#r ms  z1ConfigHandler._get_parser_compound..parser")r]rr r")rr#_get_parser_compoundds 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")rer"r"r#sz6ConfigHandler._parse_section_to_dict..)r=)r]rDZ values_parserr2r*_rer"r"r#_parse_section_to_dictws  z$ConfigHandler._parse_section_to_dictc Cs@x:|jD].\}\}}y |||<Wq tk r6Yq Xq WdS)zQParses configuration file section. :param dict section_options: N)r=rM)rBrDnamerr2r"r"r# 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%sr<__Nz0Unsupported distribution option section: [%s.%s])rAr=r(r?rr/)rBrCrDZmethod_postfixZsection_parser_methodr"r"r#r szConfigHandler.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 cstj||S)N)warningswarn)argskwargs)funcmsg warning_classr"r#config_handlers z@ConfigHandler._deprecated_config_handler..config_handler)r)rBrrrrr")rrrr#_deprecated_config_handlersz(ConfigHandler._deprecated_config_handler)F)rT)N)N)rH __module__ __qualname____doc__r/rKrEpropertyrIrS classmethodr_rfrkrmrt staticmethodrorprrrrr rr"r"r"r#r:}s,  &       ,   r:csHeZdZdZdddddZdZdfd d Zed d Zd dZ Z S)r4r5url description classifiers platforms)Z home_pagesummary classifierplatformFNcstt|j|||||_dS)N)superr4rEr6)rBr)r8rr6)rGr"r#rEszConfigMetadataHandler.__init__c CsL|j}|j}|j}|j}||||j|dt||j|||d|||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) rkeywordsprovidesrequires obsoletesrrrlong_descriptionversionZ project_urls)r_rtrfrmrDeprecationWarningr_parse_version)rB parse_listZ parse_file parse_dictZexclude_files_parserr"r"r#rIs$ zConfigMetadataHandler.parserscCs|j|}||krB|j}tt|tr>d}t|jft|S|j||j }t |r^|}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__r<z%s)rtr@rYr r rr%r&rr6callabler hasattrrrmapstr)rBr2rtmplr"r"r#rs   z$ConfigMetadataHandler._parse_version)FN) rHrrr/rKZ strict_moderErrIr __classcell__r"r")rGr#r4s r4c@s\eZdZdZeddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ dS)r3r8cCsL|j}t|jdd}|j}|j}|||||||||||||||j|j|dS)z.Metadata item name to parser function mapping.;)r^)Zzip_safeZuse_2to3Zinclude_package_datar6Zuse_2to3_fixersZuse_2to3_exclude_fixersZconvert_2to3_doctestsscriptsZeager_resourcesZdependency_linksZnamespace_packagesZinstall_requiresZsetup_requiresZ tests_requirepackages entry_points py_modules)r_rrkrf_parse_packagesrt)rBrZparse_list_semicolonZ parse_boolrr"r"r#rIs*zConfigOptionsHandler.parserscCs|ddg}|j}||kr"|j|S||dk}|r@t r@td|j|jjdi}|rfddlm}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_r rparse_section_packages__findrArL setuptoolsrr)rBr2Zfind_directivesZ trimmed_valueZfindns find_kwargsrr"r"r#r/s    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||fqSr"r")rVkv) valid_keysr"r#rXXszEConfigOptionsHandler.parse_section_packages__find..Nr)rr_r-r=rL)rBrDZ section_datarrr")rr#rKs    z1ConfigOptionsHandler.parse_section_packages__findcCs|j||j}||d<dS)z`Parses `entry_points` configuration file section. :param dict section_options: rN)rr_)rBrDrr"r"r#parse_section_entry_points`sz/ConfigOptionsHandler.parse_section_entry_pointscCs.|j||j}|jd}|r*||d<|d=|S)N*r;)rr_rL)rBrDrrootr"r"r#_parse_package_datahs  z(ConfigOptionsHandler._parse_package_datacCs|j||d<dS)z`Parses `package_data` configuration file section. :param dict section_options: package_dataN)r)rBrDr"r"r#parse_section_package_datarsz/ConfigOptionsHandler.parse_section_package_datacCs|j||d<dS)zhParses `exclude_package_data` configuration file section. :param dict section_options: Zexclude_package_dataN)r)rBrDr"r"r#"parse_section_exclude_package_dataysz7ConfigOptionsHandler.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)rBrDrr"r"r#parse_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|]\}}||fqSr"r")rVrrr"r"r#rXszAConfigOptionsHandler.parse_section_data_files.. data_filesN)rr_r=)rBrDrr"r"r#parse_section_data_filessz-ConfigOptionsHandler.parse_section_data_filesN)rHrrr/rrIrrrrrrrrr"r"r"r#r3s   r3)FF)F) __future__rrrvrr~rr' collectionsrrr importlibrdistutils.errorsrr Z#setuptools.extern.packaging.versionr r Zsetuptools.extern.sixr r type __metaclass__r$r,rrr:r4r3r"r"r"r#s,     .  ?U