3

Q'ícý?ã@s¸ddlmZmZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
mZddlmZdd	d
„Zdd„Zdd
d„ZGdd„deƒZGdd„deƒZGdd„deƒZdS)é)Úabsolute_importÚunicode_literalsN)Údefaultdict)Úpartial)Ú
import_module)ÚDistutilsOptionErrorÚDistutilsFileError)Ústring_typesFc	Cs®ddlm}m}tjj|ƒ}tjj|ƒs4td|ƒ‚tjƒ}tj	tjj
|ƒƒzJ|ƒ}|rb|jƒng}||krx|j|ƒ|j
||dt||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ÚosÚpathÚabspathÚisfilerÚgetcwdÚchdirÚdirnameÚfind_config_filesÚappendÚparse_config_filesÚparse_configurationÚcommand_optionsÚconfiguration_to_dict)	ÚfilepathZfind_othersr
r
rZcurrent_directoryÚdistrÚhandlers©rú7/tmp/pip-build-l_bcah40/setuptools/setuptools/config.pyÚread_configuration
s$

r cCslttƒ}x^|D]V}|j}|j}xD|jD]:}t|d|dƒ}|dkrNt||ƒ}n|ƒ}||||<q&WqW|S)z»Returns configuration data gathered by given handlers as a dict.

    :param list[ConfigHandler] handlers: Handlers list,
        usually from parse_configuration()

    :rtype: dict
    zget_%sN)rÚdictÚsection_prefixÚ
target_objÚset_optionsÚgetattr)rZconfig_dictÚhandlerZ	obj_aliasr#ÚoptionÚgetterÚvaluerrrr<s
rcCs2t|j||ƒ}|jƒt|||ƒ}|jƒ||fS)aÒPerforms 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
    )ÚConfigMetadataHandlerÚmetadataÚparseÚConfigOptionsHandler)Údistributionrr
ÚmetaÚoptionsrrrrYs
rc@s¶eZdZdZdZiZd!dd„Zedd„ƒZdd	„Z	e
d"dd„ƒZe
d
d„ƒZe
dd„ƒZ
e
dd„ƒZedd„ƒZedd„ƒZe
dd„ƒZe
dd„ƒZe
d#dd„ƒZdd„Zdd „ZdS)$Ú
ConfigHandlerz1Handles metadata supplied in configuration files.NFcCsbi}|j}x:|jƒD].\}}|j|ƒs(q|j|dƒjdƒ}|||<qW||_||_||_g|_dS)NÚÚ.)	r"ÚitemsÚ
startswithÚreplaceÚstripr
r#Úsectionsr$)Úselfr#r0r
r8r"Úsection_nameÚsection_optionsrrrÚ__init__ƒs
zConfigHandler.__init__cCstd|jjƒ‚dS)z.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)ÚNotImplementedErrorÚ	__class__Ú__name__)r9rrrÚparsers“szConfigHandler.parsersc	CsÆtƒ}|j}|jj||ƒ}t|||ƒ}||kr6t|ƒ‚|r>dSd}|jj|ƒ}|r€y||ƒ}Wn tk
r~d}|jsz‚YnX|rˆdSt|d|dƒ}|dkr®t	|||ƒn||ƒ|j
j|ƒdS)NFTzset_%s)Útupler#ÚaliasesÚgetr%ÚKeyErrorr@Ú	Exceptionr
Úsetattrr$r)	r9Zoption_namer)Úunknownr#Z
current_valueZskip_optionÚparserÚsetterrrrÚ__setitem__™s0zConfigHandler.__setitem__ú,cCs8t|tƒr|Sd|kr |jƒ}n
|j|ƒ}dd„|DƒS)z×Represents 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|]}|jƒr|jƒ‘qSr)r7)Ú.0Úchunkrrrú
<listcomp>Ñsz-ConfigHandler._parse_list.<locals>.<listcomp>)Ú
isinstanceÚlistÚ
splitlinesÚsplit)Úclsr)Ú	separatorrrrÚ_parse_list¿s



zConfigHandler._parse_listcCsTd}i}xF|j|ƒD]8}|j|ƒ\}}}||kr<td|ƒ‚|jƒ||jƒ<qW|S)zPRepresents value as a dict.

        :param value:
        :rtype: dict
        ú=z(Unable to parse option value to dict: %s)rVÚ	partitionrr7)rTr)rUÚresultÚlineÚkeyÚsepÚvalrrrÚ_parse_dictÓs
zConfigHandler._parse_dictcCs|jƒ}|dkS)zQRepresents value as boolean.

        :param value:
        :rtype: bool
        Ú1ÚtrueÚyes)r_r`ra)Úlower)rTr)rrrÚ_parse_boolåszConfigHandler._parse_boolcs\d}t|tƒs|S|j|ƒs |S|t|ƒd…}dd„|jdƒDƒ}dj‡fdd„|DƒƒS)aiRepresents 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: LICENSE
            file: README.rst, CHANGELOG.md, src/file.txt

        :param str value:
        :rtype: str
        zfile:Ncss|]}tjj|jƒƒVqdS)N)rrrr7)rMrrrrú	<genexpr>sz,ConfigHandler._parse_file.<locals>.<genexpr>rKrLc3s2|]*}ˆj|ƒsdrtjj|ƒrˆj|ƒVqdS)TN)Ú
_assert_localrrrÚ
_read_file)rMr)rTrrrd	s)rPr	r5ÚlenrSÚjoin)rTr)Zinclude_directiveÚspecZ	filepathsr)rTrÚ_parse_fileïs


zConfigHandler._parse_filecCs|jtjƒƒstd|ƒ‚dS)Nz#`file:` directive can not access %s)r5rrr)rrrrreszConfigHandler._assert_localc	Cs"tj|dd
}|jƒSQRXdS)Nzutf-8)Úencoding)ÚioÚopenÚread)rÚfrrrrfszConfigHandler._read_filecCs‚d}|j|ƒs|S|j|dƒjƒjdƒ}|jƒ}dj|ƒ}|p@d}tjjdt	j
ƒƒzt|ƒ}t||ƒ}Wdtjdd…t_X|S)z·Represents value as a module attribute.

        Examples:
            attr: package.attr
            attr: package.module.attr

        :param str value:
        :rtype: str
        zattr:r2r3r<rNé)
r5r6r7rSÚpoprhÚsysrÚinsertrrrr%)rTr)Zattr_directiveZ
attrs_pathÚ	attr_nameÚmodule_nameÚmodulerrrÚ_parse_attrs

zConfigHandler._parse_attrcs‡fdd„}|S)z¹Returns parser function to represents value as a list.

        Parses a value applying given methods one after another.

        :param parse_methods:
        :rtype: callable
        cs|}xˆD]}||ƒ}q
W|S)Nr)r)ÚparsedÚmethod)Ú
parse_methodsrrr,Bs
z1ConfigHandler._get_parser_compound.<locals>.parser)rTrzr,r)rzrÚ_get_parser_compound9s	z"ConfigHandler._get_parser_compoundcCs:i}|pdd„}x$|jƒD]\}\}}||ƒ||<qW|S)zÊParses 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]rrrÚ<lambda>Wsz6ConfigHandler._parse_section_to_dict.<locals>.<lambda>)r4)rTr;Z
values_parserr)r[Ú_r]rrrÚ_parse_section_to_dictLs

z$ConfigHandler._parse_section_to_dictcCs@x:|jƒD].\}\}}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`|jjƒD]R\}}d}|r$d|}t|d|jddƒdƒ}|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~r€r,rrrrr1ss&
&
 r1c@s6eZdZdZdddddœZdZedd	„ƒZd
d„ZdS)
r*r+ÚurlÚdescriptionÚclassifiersÚ	platforms)Z	home_pageÚsummaryÚ
classifierÚplatformFcCs8|j}|j}|j}||||||j||ƒ||||j|dœS)z.Metadata item name to parser function mapping.)r‹ÚkeywordsÚprovidesÚrequiresÚ	obsoletesrŠÚlicenser‰Úlong_descriptionÚversionZproject_urls)rVrjr^r{Ú_parse_version)r9Ú
parse_listZ
parse_fileÚ
parse_dictrrrr@’s
zConfigMetadataHandler.parserscCsJ|j|ƒ}t|ƒr|ƒ}t|tƒsFt|dƒr>djtt|ƒƒ}nd|}|S)zSParses `version` option value.

        :param value:
        :rtype: str

        Ú__iter__r3z%s)rwÚcallablerPr	ÚhasattrrhÚmapÚstr)r9r)r•rrrr–§s


z$ConfigMetadataHandler._parse_versionN)	r?r‚rƒr"rBZstrict_moder…r@r–rrrrr*sr*c@sTeZdZdZedd„ƒZdd„Zdd„Zdd	„Zd
d„Z	dd
„Z
dd„Zdd„ZdS)r-r0cCsL|j}t|jdd}|j}|j}|||||||||||||||j|j|dœS)z.Metadata item name to parser function mapping.ú;)rU)Zzip_safeZuse_2to3Zinclude_package_dataÚpackage_dirZuse_2to3_fixersZuse_2to3_exclude_fixersZconvert_2to3_doctestsÚscriptsZeager_resourcesÚdependency_linksZnamespace_packagesZinstall_requiresZsetup_requiresZ
tests_requireÚpackagesÚentry_pointsÚ
py_modules)rVrrcr^Ú_parse_packagesrj)r9r—Zparse_list_semicolonZ
parse_boolr˜rrrr@À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)r5rVÚparse_section_packages__findr8rCÚ
setuptoolsr¦)r9r)Zfind_directiveÚfind_kwargsr¦rrrr¥Üs

z$ConfigOptionsHandler._parse_packagescsT|j||jƒ}dddg‰t‡fdd„|jƒDƒƒ}|jdƒ}|dk	rP|d|d<|S)zœParses `packages.find` configuration file section.

        To be used in conjunction with _parse_packages().

        :param dict section_options:
        ÚwhereÚincludeÚexcludecs$g|]\}}|ˆkr|r||f‘qSrr)rMÚkÚv)Ú
valid_keysrrrOüszEConfigOptionsHandler.parse_section_packages__find.<locals>.<listcomp>Nr)r~rVr!r4rC)r9r;Zsection_datar©rªr)r¯rr§ïs


z1ConfigOptionsHandler.parse_section_packages__findcCs|j||jƒ}||d<dS)z`Parses `entry_points` configuration file section.

        :param dict section_options:
        r£N)r~rV)r9r;rxrrrÚparse_section_entry_pointssz/ConfigOptionsHandler.parse_section_entry_pointscCs.|j||jƒ}|jdƒ}|r*||d<|d=|S)NÚ*r2)r~rVrC)r9r;rxÚrootrrrÚ_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;rrrÚparse_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;r—rrrÚparse_section_extras_require%sz1ConfigOptionsHandler.parse_section_extras_requireN)
r?r‚rƒr"r…r@r¥r§r°r³rµr¶r·rrrrr-¼s
r-)FF)F)Ú
__future__rrrlrrrÚcollectionsrÚ	functoolsrÚ	importlibrZdistutils.errorsrrZsetuptools.extern.sixr	r rrÚobjectr1r*r-rrrrÚ<module>s 
.
;