a
    åYEg_P  ã                   @   sþ   d dl mZmZ d dlZd dl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 d dlmZmZ d dlmZmZ d d	lmZ d d
lmZmZ eZddd„Z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©Úwraps)Úimport_module)ÚDistutilsOptionErrorÚDistutilsFileError)ÚLegacyVersionÚparse)ÚSpecifierSet)Ústring_typesÚPY3Fc           	   	   C   s¸   ddl m}m} tj | ¡} tj | ¡s4td|  ƒ‚t ¡ }t 	tj 
| ¡¡ zT|ƒ }|rb| ¡ ng }| |vrx| | ¡ |j||d� t||j|d�}W t 	|¡ nt 	|¡ 0 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_errors)Ú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%   úJ/var/www/sistema_ama/venv/lib/python3.9/site-packages/setuptools/config.pyÚread_configuration   s(    ÿ
þr'   c                 C   s2   dj f i tƒ ¤Ž}t t| |¡}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})ÚformatÚlocalsÚ	functoolsr   Úgetattr)Ú
target_objÚkeyZgetter_nameZby_attributeÚgetterr%   r%   r&   Ú_get_optionE   s    r/   c                 C   s<   t tƒ}| D ]*}|jD ]}t|j|ƒ}|||j |< qq|S )z»Returns configuration data gathered by given handlers as a dict.

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

    :rtype: dict
    )r   ÚdictÚset_optionsr/   r,   Úsection_prefix)r$   Zconfig_dictÚhandlerÚoptionÚvaluer%   r%   r&   r!   Q   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   c   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„ ƒZe
d'dd„ƒZe
dd„ ƒZe
d(dd„ƒZdd „ Zd!d"„ Zd#d$„ ZdS ))ÚConfigHandlerz1Handles metadata supplied in configuration files.NFc                 C   s^   i }| j }| ¡ D ].\}}| |¡s&q| |d¡ d¡}|||< q|| _|| _|| _g | _d S )NÚ Ú.)	r2   ÚitemsÚ
startswithÚreplaceÚstripr   r,   Úsectionsr1   )Úselfr,   r;   r   rD   r2   Úsection_nameÚsection_optionsr%   r%   r&   Ú__init__Ž   s    

zConfigHandler.__init__c                 C   s   t d| jj ƒ‚dS )ú.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)ÚNotImplementedErrorÚ	__class__Ú__name__)rE   r%   r%   r&   Úparsersž   s    
ÿzConfigHandler.parsersc           	      C   sÄ   t ƒ }| j}| j ||¡}t|||ƒ}||u r6t|ƒ‚|r>d S d}| j |¡}|r~z||ƒ}W n ty|   d}| jsx‚ Y n0 |r†d S t|d| d ƒ}|d u r¬t	|||ƒ n||ƒ | j
 |¡ d S )NFTzset_%s)Útupler,   ÚaliasesÚgetr+   ÚKeyErrorrM   Ú	Exceptionr   Úsetattrr1   r   )	rE   Zoption_namer5   Úunknownr,   Zcurrent_valueZskip_optionÚparserÚsetterr%   r%   r&   Ú__setitem__¤   s0    zConfigHandler.__setitem__ú,c                 C   s8   t |tƒr|S d|v 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%   )rC   )Ú.0Úchunkr%   r%   r&   Ú
<listcomp>Ü   ó    z-ConfigHandler._parse_list.<locals>.<listcomp>)Ú
isinstanceÚlistÚ
splitlinesÚsplit)Úclsr5   Ú	separatorr%   r%   r&   Ú_parse_listÊ   s    

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

        :param value:
        :rtype: dict
        ú=z(Unable to parse option value to dict: %s)rd   Ú	partitionr	   rC   )rb   r5   rc   ÚresultÚliner-   ÚsepÚvalr%   r%   r&   Ú_parse_dictÞ   s    ÿzConfigHandler._parse_dictc                 C   s   |  ¡ }|dv S )zQRepresents value as boolean.

        :param value:
        :rtype: bool
        )Ú1ÚtrueÚyes)Úlower)rb   r5   r%   r%   r&   Ú_parse_boolð   s    zConfigHandler._parse_boolc                    s   ‡ fdd„}|S )zßReturns a parser function to make sure field inputs
        are not files.

        Parses a value after getting the key so error messages are
        more informative.

        :param key:
        :rtype: callable
        c                    s    d}|   |¡rtd ˆ ¡ƒ‚| S )Núfile:zCOnly strings are accepted for the {0} field, files are not accepted)rA   Ú
ValueErrorr(   )r5   Zexclude_directive©r-   r%   r&   rU     s    
ÿÿz3ConfigHandler._exclude_files_parser.<locals>.parserr%   )rb   r-   rU   r%   rs   r&   Ú_exclude_files_parserú   s    z#ConfigHandler._exclude_files_parserc                    s\   d}t |tƒs|S | |¡s |S |t|ƒd… }dd„ | d¡D ƒ}d ‡ fdd„|D ƒ¡S )aO  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: README.rst, CHANGELOG.md, src/file.txt

        :param str value:
        :rtype: str
        rq   Nc                 s   s   | ]}t j | ¡ ¡V  qd S ©N)r   r   r   rC   ©rZ   r   r%   r%   r&   Ú	<genexpr>%  r]   z,ConfigHandler._parse_file.<locals>.<genexpr>rX   rY   c                 3   s.   | ]&}ˆ   |¡stj |¡rˆ  |¡V  qdS )TN)Ú_assert_localr   r   r   Ú
_read_filerv   ©rb   r%   r&   rw   &  s   
ý)r^   r   rA   Úlenra   Újoin)rb   r5   Zinclude_directiveÚspecZ	filepathsr%   rz   r&   Ú_parse_file  s    

þzConfigHandler._parse_filec                 C   s   |   t ¡ ¡std|  ƒ‚d S )Nz#`file:` directive can not access %s)rA   r   r   r	   )r"   r%   r%   r&   rx   -  s    ÿzConfigHandler._assert_localc                 C   s:   t j| dd��}| ¡ W  d   ƒ S 1 s,0    Y  d S )Nzutf-8)Úencoding)ÚioÚopenÚread)r"   Úfr%   r%   r&   ry   3  s    zConfigHandler._read_filec              	   C   s  d}|  |¡s|S | |d¡ ¡  d¡}| ¡ }d |¡}|p@d}t ¡ }|rÂ|d |v r¤||d  }| dd¡}	t	|	ƒdkržtj
 t ¡ |	d ¡}|	d }qÂ|}nd|v rÂtj
 t ¡ |d ¡}tj
 d|¡ z&t|ƒ}
t|
|ƒ}W tj
dd… t_
ntj
dd… t_
0 |S )	z·Represents value as a module attribute.

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

        :param str value:
        :rtype: str
        zattr:r>   r?   rH   r   ú/é   N)rA   rB   rC   ra   Úpopr|   r   r   Úrsplitr{   r   ÚsysÚinsertr   r+   )rb   r5   r9   Zattr_directiveZ
attrs_pathÚ	attr_nameÚmodule_nameÚparent_pathZcustom_pathÚpartsÚmoduler%   r%   r&   Ú_parse_attr8  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   | }ˆ D ]}||ƒ}q|S ru   r%   )r5   ÚparsedÚmethod©Úparse_methodsr%   r&   r   n  s    
z1ConfigHandler._get_parser_compound.<locals>.parser%   )rb   r“   r   r%   r’   r&   Ú_get_parser_compounde  s    	z"ConfigHandler._get_parser_compoundc                 C   s6   i }|pdd„ }|  ¡ D ]\}\}}||ƒ||< q|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 ru   r%   )rj   r%   r%   r&   Ú<lambda>ƒ  r]   z6ConfigHandler._parse_section_to_dict.<locals>.<lambda>)r@   )rb   rG   Zvalues_parserr5   r-   Ú_rj   r%   r%   r&   Ú_parse_section_to_dictx  s
    
z$ConfigHandler._parse_section_to_dictc              	   C   s:   |  ¡ D ],\}\}}z|| |< W q ty2   Y q0 qdS )zQParses configuration file section.

        :param dict section_options:
        N)r@   rQ   )rE   rG   Únamer–   r5   r%   r%   r&   Úparse_sectionˆ  s
    zConfigHandler.parse_sectionc                 C   sb   | j  ¡ D ]R\}}d}|r"d| }t| d|  dd¡dƒ}|du rTtd| j|f ƒ‚||ƒ q
dS )zTParses configuration file items from one
        or more related sections.

        r>   z_%szparse_section%sr?   Ú__Nz0Unsupported distribution option section: [%s.%s])rD   r@   r+   rB   r	   r2   )rE   rF   rG   Zmethod_postfixZsection_parser_methodr%   r%   r&   r   ”  s     üÿÿzConfigHandler.parsec                    s   t ˆ ƒ‡ ‡‡fdd„ƒ}|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
        c                     s   t  ˆˆ¡ ˆ | i |¤ŽS ru   )ÚwarningsÚwarn)ÚargsÚkwargs©ÚfuncÚmsgÚwarning_classr%   r&   Úconfig_handler³  s    z@ConfigHandler._deprecated_config_handler.<locals>.config_handlerr   )rE   r    r¡   r¢   r£   r%   rŸ   r&   Ú_deprecated_config_handler¬  s    z(ConfigHandler._deprecated_config_handler)F)rX   )N)N)rL   Ú
__module__Ú__qualname__Ú__doc__r2   rO   rH   ÚpropertyrM   rW   Úclassmethodrd   rk   rp   rt   r~   Ústaticmethodrx   ry   r�   r”   r—   r™   r   r¤   r%   r%   r%   r&   r=   ~   s<   

&

	



,
r=   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 )r7   r8   ÚurlÚdescriptionÚclassifiersÚ	platforms)Z	home_pageÚsummaryÚ
classifierÚplatformFNc                    s   t t| ƒ |||¡ || _d S ru   )Úsuperr7   rH   r9   )rE   r,   r;   r   r9   ©rK   r%   r&   rH   Ì  s    ÿzConfigMetadataHandler.__init__c                 C   sN   | j }| j}| j}| j}||||  |dt¡||  ||¡|dƒ|||| j|dœS )rI   z[The requires parameter is deprecated, please use install_requires for runtime dependencies.Úlicense)r®   ÚkeywordsÚprovidesÚrequiresÚ	obsoletesr­   r´   Úlicense_filesr¬   Úlong_descriptionÚversionÚproject_urls)rd   r~   rk   rt   r¤   ÚDeprecationWarningr”   Ú_parse_version)rE   Ú
parse_listZ
parse_fileÚ
parse_dictZexclude_files_parserr%   r%   r&   rM   Ò  s*    ü
ðzConfigMetadataHandler.parsersc                 C   s”   |   |¡}||krF| ¡ }tt|ƒtƒrBd}t|jf i tƒ ¤Žƒ‚|S |  || j	¡}t
|ƒrb|ƒ }t|tƒs�t|dƒrˆd tt|ƒ¡}nd| }|S )zSParses `version` option value.

        :param value:
        :rtype: str

        zCVersion loaded from {value} does not comply with PEP 440: {version}Ú__iter__r?   z%s)r~   rC   r^   r   r   r	   r(   r)   r�   r9   Úcallabler   Úhasattrr|   ÚmapÚstr)rE   r5   r»   Útmplr%   r%   r&   r¾   í  s     
ÿ

z$ConfigMetadataHandler._parse_version)FN)rL   r¥   r¦   r2   rO   Zstrict_moderH   r¨   rM   r¾   Ú__classcell__r%   r%   r³   r&   r7   »  s   ü  ÿ
r7   c                   @   s\   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d„ ZdS )r6   r;   c                 C   sN   | j }t| j dd�}| j}| j}||||||||||||||| j| j|tdœS )rI   ú;©rc   )Zzip_safeZuse_2to3Zinclude_package_datar9   Zuse_2to3_fixersZuse_2to3_exclude_fixersÚconvert_2to3_doctestsÚscriptsZeager_resourcesÚdependency_linksZnamespace_packagesÚinstall_requiresÚsetup_requiresZtests_requireÚpackagesÚentry_pointsÚ
py_modulesÚpython_requires)rd   r   rp   rk   Ú_parse_packagesr~   r   )rE   r¿   Zparse_list_semicolonZ
parse_boolrÀ   r%   r%   r&   rM     s.    îzConfigOptionsHandler.parsersc                 C   s~   ddg}|  ¡ }||vr"|  |¡S ||d k}|r>ts>tdƒ‚|  | j di ¡¡}|rdddlm} nddlm	} |f i |¤ŽS )	zTParses `packages` option value.

        :param value:
        :rtype: list
        zfind:zfind_namespace:r…   z8find_namespace: directive is unsupported on Python < 3.3zpackages.findr   )Úfind_namespace_packages)Úfind_packages)
rC   rd   r   r	   Úparse_section_packages__findrD   rP   Ú
setuptoolsrÔ   rÕ   )rE   r5   Zfind_directivesZtrimmed_valueZfindnsÚfind_kwargsrÕ   r%   r%   r&   rÓ   2  s     
ÿÿz$ConfigOptionsHandler._parse_packagesc                    sR   |   || j¡}g d¢‰ t‡ fdd„| ¡ D ƒƒ}| d¡}|durN|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 | ]\}}|ˆ v r|r||f‘qS r%   r%   ©rZ   ÚkÚv©Z
valid_keysr%   r&   r\   [  r]   zEConfigOptionsHandler.parse_section_packages__find.<locals>.<listcomp>rÙ   Nr   )r—   rd   r0   r@   rP   )rE   rG   Zsection_datarØ   rÙ   r%   rß   r&   rÖ   N  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—   rd   ©rE   rG   r�   r%   r%   r&   Úparse_section_entry_pointsc  s    z/ConfigOptionsHandler.parse_section_entry_pointsc                 C   s.   |   || j¡}| d¡}|r*||d< |d= |S )NÚ*r>   )r—   rd   rP   )rE   rG   r�   Úrootr%   r%   r&   Ú_parse_package_datak  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ä   ©rE   rG   r%   r%   r&   Úparse_section_package_datau  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_dataNræ   rç   r%   r%   r&   Ú"parse_section_exclude_package_data|  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È   rÉ   Úextras_requireN)r   rd   r—   )rE   rG   r¿   r%   r%   r&   Úparse_section_extras_require„  s    ÿz1ConfigOptionsHandler.parse_section_extras_requirec                 C   s(   |   || j¡}dd„ | ¡ D ƒ| d< dS )z^Parses `data_files` configuration file section.

        :param dict section_options:
        c                 S   s   g | ]\}}||f‘qS r%   r%   rÜ   r%   r%   r&   r\   “  r]   zAConfigOptionsHandler.parse_section_data_files.<locals>.<listcomp>Ú
data_filesN)r—   rd   r@   rà   r%   r%   r&   Úparse_section_data_files�  s    z-ConfigOptionsHandler.parse_section_data_filesN)rL   r¥   r¦   r2   r¨   rM   rÓ   rÖ   rá   rä   rè   ré   rë   rí   r%   r%   r%   r&   r6     s   

	r6   )FF)F)"Ú
__future__r   r   r€   r   rˆ   r›   r*   Úcollectionsr   r   r   Ú	importlibr   Údistutils.errorsr	   r
   Z#setuptools.extern.packaging.versionr   r   Z&setuptools.extern.packaging.specifiersr   Úsetuptools.extern.sixr   r   ÚtypeÚ__metaclass__r'   r/   r!   r   r=   r7   r6   r%   r%   r%   r&   Ú<module>   s2    ÿ
/ ÿ
  ?V