3 ]?@sddlmZmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZddlmZdd d Zd d Zdd dZGdddeZGdddeZGdddeZdS))absolute_importunicode_literalsN) defaultdict)partial) import_module)DistutilsOptionErrorDistutilsFileError) string_typesFc 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.distr r ospathabspathisfilergetcwdchdirdirnamefind_config_filesappendparse_config_filesparse_configurationcommand_optionsconfiguration_to_dict) filepathZ find_othersr r r Zcurrent_directorydistr handlersr7/tmp/pip-build-8jg9gmni/setuptools/setuptools/config.pyread_configuration s$      r cCsltt}x^|D]V}|j}|j}xD|jD]:}t|d|d}|dkrNt||}n|}||||<q&WqW|S)zReturns configuration data gathered by given handlers as a dict. :param list[ConfigHandler] handlers: Handlers list, usually from parse_configuration() :rtype: dict zget_%sN)rdictsection_prefix target_obj set_optionsgetattr)rZ config_dicthandlerZ obj_aliasr#optiongettervaluerrrr<s   rcCs2t|j||}|jt|||}|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 )ConfigMetadataHandlermetadataparseConfigOptionsHandler) distributionrr metaoptionsrrrrYs  rc@seZdZdZdZiZd!ddZeddZdd Z e d"d d Z e d dZ e ddZ e ddZeddZeddZe ddZe ddZe d#ddZddZdd ZdS)$ ConfigHandlerz1Handles metadata supplied in configuration files.NFcCsbi}|j}x:|jD].\}}|j|s(q|j|djd}|||<qW||_||_||_g|_dS)N.) r"items startswithreplacestripr r#sectionsr$)selfr#r0r r8r" section_namesection_optionsrrr__init__s  zConfigHandler.__init__cCstd|jjdS)z.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)NotImplementedError __class____name__)r9rrrparsersszConfigHandler.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%KeyErrorr@ Exceptionr setattrr$r) r9Z option_namer)unknownr#Z 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)r7).0chunkrrr sz-ConfigHandler._parse_list..) isinstancelist splitlinessplit)clsr) separatorrrr _parse_lists   zConfigHandler._parse_listcCsTd}i}xF|j|D]8}|j|\}}}||krsz,ConfigHandler._parse_file..rKrLc3s2|]*}j|sdrtjj|rj|VqdS)TN) _assert_localrrr _read_file)rMr)rTrrrd s)rPr r5lenrSjoin)rTr)Zinclude_directivespecZ filepathsr)rTr _parse_files   zConfigHandler._parse_filecCs|jtjstd|dS)Nz#`file:` directive can not access %s)r5rrr)rrrrreszConfigHandler._assert_localc Cs"tj|dd }|jSQRXdS)Nzutf-8)encoding)ioopenread)rfrrrrfszConfigHandler._read_filec Csd}|j|s|S|j|djjd}|j}dj|}|p@d}tjjdt j zt |}t ||}Wdtjddt_X|S)zRepresents value as a module attribute. Examples: attr: package.attr attr: package.module.attr :param str value: :rtype: str zattr:r2r3r<rN) r5r6r7rSpoprhsysrinsertrrrr%)rTr)Zattr_directiveZ attrs_path attr_name module_namemodulerrr _parse_attrs   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_methodsrrr,Bs  z1ConfigHandler._get_parser_compound..parser)rTrzr,r)rzr_get_parser_compound9s 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)r]rrrWsz6ConfigHandler._parse_section_to_dict..)r4)rTr;Z values_parserr)r[_r]rrr_parse_section_to_dictLs  z$ConfigHandler._parse_section_to_dictc Cs@x:|jD].\}\}}y |||<Wq tk r6Yq Xq WdS)zQParses configuration file section. :param dict section_options: N)r4rD)r9r;namer}r)rrr parse_section\s  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. r2z_%szparse_section%sr3__Nz0Unsupported distribution option section: [%s.%s])r8r4r%r6rr")r9r:r;Zmethod_postfixZsection_parser_methodrrrr,hszConfigHandler.parse)F)rK)N)r? __module__ __qualname____doc__r"rBr<propertyr@rJ classmethodrVr^rcrj staticmethodrerfrwr{r~rr,rrrrr1ss&  &        r1c@s6eZdZdZdddddZdZedd Zd d Zd S) r*r+url description classifiers platforms)Z home_pagesummary classifierplatformFc Cs8|j}|j}|j}||||||j||||||j|d S)z.Metadata item name to parser function mapping.) rkeywordsprovidesrequires obsoletesrlicenserlong_descriptionversionZ project_urls)rVrjr^r{_parse_version)r9 parse_listZ parse_file parse_dictrrrr@s zConfigMetadataHandler.parserscCsJ|j|}t|r|}t|tsFt|dr>djtt|}nd|}|S)zSParses `version` option value. :param value: :rtype: str __iter__r3z%s)rwcallablerPr hasattrrhmapstr)r9r)rrrrrs   z$ConfigMetadataHandler._parse_versionN) r?rrr"rBZ strict_moderr@rrrrrr*s r*c@sTeZdZdZeddZddZddZdd Zd d Z d d Z ddZ ddZ dS)r-r0cCsL|j}t|jdd}|j}|j}|||||||||||||||j|j|dS)z.Metadata item name to parser function mapping.;)rU)Zzip_safeZuse_2to3Zinclude_package_data package_dirZuse_2to3_fixersZuse_2to3_exclude_fixersZconvert_2to3_doctestsscriptsZeager_resourcesdependency_linksZnamespace_packagesZinstall_requiresZsetup_requiresZ tests_requirepackages entry_points py_modules)rVrrcr^_parse_packagesrj)r9rZparse_list_semicolonZ parse_boolrrrrr@s*zConfigOptionsHandler.parserscCsBd}|j|s|j|S|j|jjdi}ddlm}|f|S)zTParses `packages` option value. :param value: :rtype: list zfind:z packages.findr) find_packages)r5rVparse_section_packages__findr8rC setuptoolsr)r9r)Zfind_directive 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)rMkv) valid_keysrrrOszEConfigOptionsHandler.parse_section_packages__find..Nr)r~rVr!r4rC)r9r;Z section_datarrr)rrrs    z1ConfigOptionsHandler.parse_section_packages__findcCs|j||j}||d<dS)z`Parses `entry_points` configuration file section. :param dict section_options: rN)r~rV)r9r;rxrrrparse_section_entry_pointssz/ConfigOptionsHandler.parse_section_entry_pointscCs.|j||j}|jd}|r*||d<|d=|S)N*r2)r~rVrC)r9r;rxrootrrr_parse_package_data s  z(ConfigOptionsHandler._parse_package_datacCs|j||d<dS)z`Parses `package_data` configuration file section. :param dict section_options: package_dataN)r)r9r;rrrparse_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)r9r;rrr"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)rUZextras_requireN)rrVr~)r9r;rrrrparse_section_extras_require%sz1ConfigOptionsHandler.parse_section_extras_requireN) r?rrr"rr@rrrrrrrrrrrr-s  r-)FF)F) __future__rrrlrrr collectionsr functoolsr importlibrZdistutils.errorsrrZsetuptools.extern.sixr r rrobjectr1r*r-rrrrs      . ;