B
    =)H[eF  ã               @   sÊ   d dl mZmZ d dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZmZ d dlmZ eZdd
d„Zdd„ Zddd„ZG dd„ dƒZG dd„ deƒZG dd„ deƒZdS )é    )Úabsolute_importÚunicode_literalsN)Údefaultdict)Úpartial)Úimport_module)ÚDistutilsOptionErrorÚDistutilsFileError)ÚLegacyVersionÚparse)Ústring_typesFc       	   	   C   s®   ddl m}m} tj | ¡} tj | ¡s4td|  ƒ‚t ¡ }t 	tj 
| ¡¡ zJ|ƒ }|rb| ¡ ng }| |krx| | ¡ |j||d� t||j|d�}W dt 	|¡ X t|ƒ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)Zsetuptools.distr   r   ÚosÚpathÚabspathÚisfiler   ÚgetcwdÚchdirÚdirnameÚfind_config_filesÚappendÚparse_config_filesÚparse_configurationÚcommand_optionsÚconfiguration_to_dict)	ÚfilepathZfind_othersr   r   r   Zcurrent_directoryÚdistr   Úhandlers© r    úYC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\setuptools\setuptools\config.pyÚread_configuration   s$    

r"   c             C   sl   t tƒ}x^| D ]V}|j}|j}xD|jD ]:}t|d| dƒ}|dkrNt||ƒ}n|ƒ }||| |< q&W qW |S )z»Returns configuration data gathered by given handlers as a dict.

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

    :rtype: dict
    zget_%sN)r   ÚdictÚsection_prefixÚ
target_objÚset_optionsÚgetattr)r   Zconfig_dictÚhandlerZ	obj_aliasr%   ÚoptionÚgetterÚvaluer    r    r!   r   @   s    
r   c             C   s6   t | ||ƒ}| ¡  t| j||| jƒ}| ¡  ||fS )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
    )ÚConfigOptionsHandlerr
   ÚConfigMetadataHandlerÚmetadataÚpackage_dir)Údistributionr   r   ÚoptionsÚmetar    r    r!   r   ]   s    
r   c               @   s¸   e Zd ZdZdZi Zd!dd„Zedd„ ƒZdd	„ Z	e
d"dd„ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZedd„ ƒZedd„ ƒZe
d#dd„ƒZe
dd„ ƒZe
d$dd„ƒZdd„ Zdd „ ZdS )%ÚConfigHandlerz1Handles metadata supplied in configuration files.NFc             C   sb   i }| j }x:| ¡ D ].\}}| |¡s(q| |d¡ d¡}|||< qW || _|| _|| _g | _d S )NÚ Ú.)	r$   ÚitemsÚ
startswithÚreplaceÚstripr   r%   Úsectionsr&   )Úselfr%   r1   r   r:   r$   Úsection_nameÚsection_optionsr    r    r!   Ú__init__‡   s    
zConfigHandler.__init__c             C   s   t d| jj ƒ‚dS )z.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)ÚNotImplementedErrorÚ	__class__Ú__name__)r;   r    r    r!   Úparsers—   s    zConfigHandler.parsersc       	      C   sÆ   t ƒ }| j}| j ||¡}t|||ƒ}||kr6t|ƒ‚|r>d S d}| j |¡}|r€y||ƒ}W n  tk
r~   d}| jsz‚ Y nX |rˆd S t|d| d ƒ}|d kr®t	|||ƒ n||ƒ | j
 |¡ d S )NFTzset_%s)Útupler%   ÚaliasesÚgetr'   ÚKeyErrorrB   Ú	Exceptionr   Úsetattrr&   r   )	r;   Zoption_namer+   Úunknownr%   Zcurrent_valueZskip_optionÚparserÚsetterr    r    r!   Ú__setitem__�   s0    zConfigHandler.__setitem__ú,c             C   s8   t |tƒr|S d|kr | ¡ }n
| |¡}dd„ |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
        Ú
c             S   s   g | ]}|  ¡ r|  ¡ ‘qS r    )r9   )Ú.0Úchunkr    r    r!   ú
<listcomp>Õ   s    z-ConfigHandler._parse_list.<locals>.<listcomp>)Ú
isinstanceÚlistÚ
splitlinesÚsplit)Úclsr+   Ú	separatorr    r    r!   Ú_parse_listÃ   s    



zConfigHandler._parse_listc             C   sT   d}i }xF|   |¡D ]8}| |¡\}}}||kr<td| ƒ‚| ¡ || ¡ < qW |S )zPRepresents value as a dict.

        :param value:
        :rtype: dict
        ú=z(Unable to parse option value to dict: %s)rX   Ú	partitionr   r9   )rV   r+   rW   ÚresultÚlineÚkeyÚsepÚvalr    r    r!   Ú_parse_dict×   s    
zConfigHandler._parse_dictc             C   s   |  ¡ }|dkS )zQRepresents value as boolean.

        :param value:
        :rtype: bool
        )Ú1ÚtrueÚyes)Úlower)rV   r+   r    r    r!   Ú_parse_boolé   s    zConfigHandler._parse_boolc                s\   d}t |tƒs|S | |¡s |S |t|ƒd… }dd„ | d¡D ƒ}d ‡ fdd„|D ƒ¡S )ai  Represents 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
        zfile:Nc             s   s   | ]}t j | ¡ ¡V  qd S )N)r   r   r   r9   )rO   r   r    r    r!   ú	<genexpr>  s    z,ConfigHandler._parse_file.<locals>.<genexpr>rM   rN   c             3   s.   | ]&}ˆ   |¡stj |¡rˆ  |¡V  qdS )TN)Ú_assert_localr   r   r   Ú
_read_file)rO   r   )rV   r    r!   rf     s   
)rR   r   r7   ÚlenrU   Újoin)rV   r+   Zinclude_directiveÚspecZ	filepathsr    )rV   r!   Ú_parse_fileó   s    


zConfigHandler._parse_filec             C   s   |   t ¡ ¡std|  ƒ‚d S )Nz#`file:` directive can not access %s)r7   r   r   r   )r   r    r    r!   rg     s    zConfigHandler._assert_localc          	   C   s"   t j| dd��
}| ¡ S Q R X d S )Nzutf-8)Úencoding)ÚioÚopenÚread)r   Úfr    r    r!   rh     s    zConfigHandler._read_filec          	   C   sþ   d}|  |¡s|S | |d¡ ¡  d¡}| ¡ }d |¡}|p@d}t ¡ }|rÂ|d |kr¤||d  }| dd¡}	t	|	ƒdkržtj
 t ¡ |	d ¡}|	d }qÂ|}nd|krÂtj
 t ¡ |d ¡}tj
 d|¡ zt|ƒ}
t|
|ƒ}W dtj
dd… t_
X |S )	z·Represents value as a module attribute.

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

        :param str value:
        :rtype: str
        zattr:r4   r5   r>   r   ú/é   N)r7   r8   r9   rU   Úpoprj   r   r   Úrsplitri   r   ÚsysÚinsertr   r'   )rV   r+   r/   Zattr_directiveZ
attrs_pathÚ	attr_nameÚmodule_nameÚparent_pathZcustom_pathÚpartsÚmoduler    r    r!   Ú_parse_attr  s0    


zConfigHandler._parse_attrc                s   ‡ fdd„}|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
        c                s   | }xˆ D ]}||ƒ}q
W |S )Nr    )r+   ÚparsedÚmethod)Úparse_methodsr    r!   r
   T  s    
z1ConfigHandler._get_parser_compound.<locals>.parser    )rV   r€   r
   r    )r€   r!   Ú_get_parser_compoundK  s    	z"ConfigHandler._get_parser_compoundc             C   s:   i }|pdd„ }x$|  ¡ D ]\}\}}||ƒ||< qW |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
        c             S   s   | S )Nr    )r_   r    r    r!   Ú<lambda>i  s    z6ConfigHandler._parse_section_to_dict.<locals>.<lambda>)r6   )rV   r=   Zvalues_parserr+   r]   Ú_r_   r    r    r!   Ú_parse_section_to_dict^  s
    
z$ConfigHandler._parse_section_to_dictc          	   C   s@   x:|  ¡ D ].\}\}}y|| |< W q
 tk
r6   Y q
X q
W dS )zQParses configuration file section.

        :param dict section_options:
        N)r6   rF   )r;   r=   Únamerƒ   r+   r    r    r!   Úparse_sectionn  s
    zConfigHandler.parse_sectionc             C   sf   x`| j  ¡ D ]R\}}d}|r$d| }t| d|  dd¡dƒ}|dkrVtd| j|f ƒ‚||ƒ qW dS )zTParses configuration file items from one
        or more related sections.

        r4   z_%szparse_section%sr5   Ú__Nz0Unsupported distribution option section: [%s.%s])r:   r6   r'   r8   r   r$   )r;   r<   r=   Zmethod_postfixZsection_parser_methodr    r    r!   r
   z  s    zConfigHandler.parse)F)rM   )N)N)rA   Ú
__module__Ú__qualname__Ú__doc__r$   rD   r>   ÚpropertyrB   rL   ÚclassmethodrX   r`   re   rl   Ústaticmethodrg   rh   r}   r�   r„   r†   r
   r    r    r    r!   r3   w   s(   
&
 ,r3   c                   sH   e Zd ZdZdddddœZdZd‡ fd	d
„	Zedd„ ƒZdd„ Z	‡  Z
S )r-   r.   ÚurlÚdescriptionÚclassifiersÚ	platforms)Z	home_pageÚsummaryÚ
classifierÚplatformFNc                s   t t| ƒ |||¡ || _d S )N)Úsuperr-   r>   r/   )r;   r%   r1   r   r/   )r@   r    r!   r>   ¤  s    zConfigMetadataHandler.__init__c             C   s8   | 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)rX   rl   r`   r�   Ú_parse_version)r;   Ú
parse_listZ
parse_fileÚ
parse_dictr    r    r!   rB   ª  s    
zConfigMetadataHandler.parsersc             C   sŠ   |   |¡}||kr<| ¡ }tt|ƒtƒr8td||f ƒ‚|S |  || j¡}t|ƒrX|ƒ }t|t	ƒs†t
|dƒr~d tt|ƒ¡}nd| }|S )zSParses `version` option value.

        :param value:
        :rtype: str

        z7Version loaded from %s does not comply with PEP 440: %sÚ__iter__r5   z%s)rl   r9   rR   r
   r	   r   r}   r/   Úcallabler   Úhasattrrj   ÚmapÚstr)r;   r+   rœ   r    r    r!   r�   ¿  s    


z$ConfigMetadataHandler._parse_version)FN)rA   rˆ   r‰   r$   rD   Zstrict_moder>   r‹   rB   r�   Ú__classcell__r    r    )r@   r!   r-   “  s    r-   c               @   sT   e Zd ZdZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ ZdS )r,   r1   c             C   sL   | j }t| j dd�}| j}| j}||||||||||||||| j| j|dœS )z.Metadata item name to parser function mapping.ú;)rW   )Zzip_safeZuse_2to3Zinclude_package_datar/   Zuse_2to3_fixersZuse_2to3_exclude_fixersZconvert_2to3_doctestsÚscriptsZeager_resourcesÚdependency_linksZnamespace_packagesZinstall_requiresZsetup_requiresZtests_requireÚpackagesÚentry_pointsÚ
py_modules)rX   r   re   r`   Ú_parse_packagesrl   )r;   rž   Zparse_list_semicolonZ
parse_boolrŸ   r    r    r!   rB   ä  s*    zConfigOptionsHandler.parsersc             C   sB   d}|  |¡s|  |¡S |  | j di ¡¡}ddlm} |f |ŽS )zTParses `packages` option value.

        :param value:
        :rtype: list
        zfind:zpackages.findr   )Úfind_packages)r7   rX   Úparse_section_packages__findr:   rE   Ú
setuptoolsr­   )r;   r+   Zfind_directiveÚfind_kwargsr­   r    r    r!   r¬      s    

z$ConfigOptionsHandler._parse_packagesc                sT   |   || j¡}dddg‰ t‡ fdd„| ¡ D ƒƒ}| d¡}|dk	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Úexcludec                s$   g | ]\}}|ˆ kr|r||f‘qS r    r    )rO   ÚkÚv)Ú
valid_keysr    r!   rQ      s    zEConfigOptionsHandler.parse_section_packages__find.<locals>.<listcomp>Nr   )r„   rX   r#   r6   rE   )r;   r=   Zsection_datar°   r±   r    )r¶   r!   r®     s    


z1ConfigOptionsHandler.parse_section_packages__findc             C   s   |   || j¡}|| d< dS )z`Parses `entry_points` configuration file section.

        :param dict section_options:
        rª   N)r„   rX   )r;   r=   r~   r    r    r!   Úparse_section_entry_points(  s    z/ConfigOptionsHandler.parse_section_entry_pointsc             C   s.   |   || j¡}| d¡}|r*||d< |d= |S )NÚ*r4   )r„   rX   rE   )r;   r=   r~   Úrootr    r    r!   Ú_parse_package_data0  s    
z(ConfigOptionsHandler._parse_package_datac             C   s   |   |¡| d< dS )z`Parses `package_data` configuration file section.

        :param dict section_options:
        Úpackage_dataN)rº   )r;   r=   r    r    r!   Úparse_section_package_data:  s    z/ConfigOptionsHandler.parse_section_package_datac             C   s   |   |¡| d< dS )zhParses `exclude_package_data` configuration file section.

        :param dict section_options:
        Zexclude_package_dataN)rº   )r;   r=   r    r    r!   Ú"parse_section_exclude_package_dataA  s    z7ConfigOptionsHandler.parse_section_exclude_package_datac             C   s"   t | jdd�}|  ||¡| d< dS )zbParses `extras_require` configuration file section.

        :param dict section_options:
        r¦   )rW   Zextras_requireN)r   rX   r„   )r;   r=   rž   r    r    r!   Úparse_section_extras_requireI  s    z1ConfigOptionsHandler.parse_section_extras_requireN)rA   rˆ   r‰   r$   r‹   rB   r¬   r®   r·   rº   r¼   r½   r¾   r    r    r    r!   r,   à  s   
r,   )FF)F)Ú
__future__r   r   rn   r   rv   Úcollectionsr   Ú	functoolsr   Ú	importlibr   Údistutils.errorsr   r   Z#setuptools.extern.packaging.versionr	   r
   Zsetuptools.extern.sixr   ÚtypeZ__metaclass__r"   r   r   r3   r-   r,   r    r    r    r!   Ú<module>   s$   
.
  M