U
    X7hd                     @  s4  U d Z ddlmZ ddlZddlZddlZddlmZ ddlmZm	Z	 ddl
mZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZm Z  ddl!m"Z" ddl#m$Z$m%Z% ddl&m'Z' ddl(m)Z) erddl*m+Z+ ddl,m-Z- ddl.m/Z/ ee0ee0ef f Z1de2d< ee0e1f Z3de2d< edddZ4dDddddddd Z5dddd!d"d#Z6dEddd%dd&d'd(d)Z7d*d+d,d-d.Z8d/dd0d1d2Z9dFdddd&d3d4d5Z:d+d+d6d7d8d9Z;G d:d; d;ee4 Z<G d<d= d=e<d Z=G d>d? d?e<d Z>G d@dA dAe'Z?G dBdC dCe'Z@dS )Ga<  
Load setuptools configuration from ``setup.cfg`` files.

**API will be made private in the future**

To read project metadata, consider using
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
For simple scenarios, you can also try parsing the file directly
with the help of ``configparser``.
    )annotationsN)defaultdict)partialwraps)TYPE_CHECKINGAnyCallableDictGenericIterableIteratorListTupleTypeVarcast)default_environment)InvalidRequirementRequirement)SpecifierSet)InvalidVersionVersion   )StrPath)	FileErrorOptionError)SetuptoolsDeprecationWarning   )expand)	TypeAliasDistribution)DistributionMetadatar   SingleCommandOptionsAllCommandOptionsTargetr    r!   Fr   booldict)filepathfind_othersignore_option_errorsreturnc                 C  s8   ddl m} | }|r| ng }t|| ||}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   r   )setuptools.distr    find_config_files_applyconfiguration_to_dict)r'   r(   r)   r    dist	filenameshandlers r2   T/var/www/formularioweb/env/lib/python3.8/site-packages/setuptools/config/setupcfg.pyread_configuration=   s
    r4   )r/   r'   r*   c                 C  s   t | | |   | S )z`Apply the configuration from a ``setup.cfg`` file into an existing
    distribution object.
    )r-   _finalize_requires)r/   r'   r2   r2   r3   apply_configurationW   s    
r6   r2   zIterable[StrPath]z2tuple[ConfigMetadataHandler, ConfigOptionsHandler])r/   r'   other_filesr)   r*   c              	   C  s   ddl m} tj|}tj|s4td| dt }ttj	| ||f}z4|j
| ttt |d t| | j|d}|   W 5 t| X |S )zHRead configuration from ``filepath`` and applies to the ``dist`` object.r   )_DistributionzConfiguration file z does not exist.)r0   )r)   )r+   r8   ospathabspathisfiler   getcwdchdirdirnameparse_config_filesr   r   strparse_configurationcommand_options_finalize_license_files)r/   r'   r7   r)   r8   Zcurrent_directoryr0   r1   r2   r2   r3   r-   `   s"    
  r-   z#Distribution | DistributionMetadatarA   )
target_objkeyc                 C  s*   d| }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.
    get_)	functoolsr   getattr)rE   rF   Zgetter_nameZby_attributegetterr2   r2   r3   _get_option   s    
rK   zKIterable[ConfigHandler[Distribution] | ConfigHandler[DistributionMetadata]])r1   r*   c                 C  s<   t t}| D ]*}|jD ]}t|j|}|||j |< qq|S )zReturns configuration data gathered by given handlers as a dict.

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

    :rtype: dict
    )r   r&   set_optionsrK   rE   section_prefix)r1   Zconfig_dicthandleroptionvaluer2   r2   r3   r.      s    
r.   )distributionrC   r)   r*   c              	   C  st   t | \}t| |||}|  | js0|j| _t| j|||| j| j}|  | j	|j|j W 5 Q R X ||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
    )
r   ZEnsurePackagesDiscoveredConfigOptionsHandlerparsepackage_dirConfigMetadataHandlermetadatasrc_root_referenced_filesupdate)rQ   rC   r)   ensure_discoveredoptionsmetar2   r2   r3   rB      s0     rB   list)label
orig_valueparsedc              
     s   d|kst  dkrdS t  }z,t d }|j|krLtj|  d d W nT tk
r } z6t fdd|D rtj	|  d d}t||W 5 d}~X Y nX dS )am  Because users sometimes misinterpret this configuration:

    [options.extras_require]
    foo = bar;python_version<"4"

    It looks like one requirement with an environment marker
    but because there is no newline, it's parsed as two requirements
    with a semicolon as separator.

    Therefore, if:
        * input string does not contain a newline AND
        * parsed result contains two requirements AND
        * parsing of the two parts from the result ("<first>;<second>")
        leads in a valid Requirement with a valid marker
    a UserWarning is shown to inform the user about the possible problem.
    
r   Nr   )fieldreqc                 3  s   | ]} d   |V  qdS )r   N
startswith).0markerr`   r2   r3   	<genexpr>   s     z8_warn_accidental_env_marker_misconfig.<locals>.<genexpr>)
len
marker_envkeysr   name_AmbiguousMarkeremitr   anymessage)r^   r_   r`   markersrc   exmsgr2   rh   r3   %_warn_accidental_env_marker_misconfig   s    

ru   c                   @  s   e Zd ZU dZded< i Zded< dddd	d
dZedddddZe	dd Z
ddddZed3ddZedd Zedd Zedd Zdd d!d"Zd#d d$d%Zed&d' Zed(d) Zed4d+d,Zd-d. Zddd/d0Zd1d2 Zd*S )5ConfigHandlerz1Handles metadata supplied in configuration files.rA   rM   zdict[str, str]aliasesr$   r#   expand.EnsurePackagesDiscovered)rE   r[   rZ   c                 C  s4   || _ || _t| || _g | _|| _t | _d S N)	r)   rE   r&   _section_optionssectionsrL   rZ   setrX   selfrE   r[   r)   rZ   r2   r2   r3   __init__   s    zConfigHandler.__init__z*Iterator[tuple[str, SingleCommandOptions]])r[   r*   c                 c  s>   |  D ]0\}}|| j\}}}|r(q|d|fV  qd S )N.)items	partitionrM   lstrip)clsr[   	full_namerP   preseprm   r2   r2   r3   rz     s
    zConfigHandler._section_optionsc                 C  s   t d| jj dS ).Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)NotImplementedError	__class____name__r~   r2   r2   r3   parsers  s    
zConfigHandler.parsersNone)r*   c           	   
   C  s   | j }| j||}zt||}W n, tk
rN } zt||W 5 d }~X Y nX |rXd S z| j|dd |}W n tf| j k
r   Y d S X t	
|j|}t|d| |}|| | j| d S )Nc                 S  s   | S ry   r2   )xr2   r2   r3   <lambda>1      z+ConfigHandler.__setitem__.<locals>.<lambda>set_)rE   rw   getrI   AttributeErrorKeyErrorr   	Exceptionr)   rH   r   __setattr__rL   append)	r~   Zoption_namerP   rE   Zcurrent_valueer`   Zsimple_settersetterr2   r2   r3   __setitem__!  s     zConfigHandler.__setitem__,c                 C  s8   t |tr|S d|kr | }n
||}dd |D S )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
        ra   c                 S  s   g | ]}|  r|  qS r2   strip)rf   chunkr2   r2   r3   
<listcomp>M  s      z-ConfigHandler._parse_list.<locals>.<listcomp>)
isinstancer]   
splitlinessplit)r   rP   	separatorr2   r2   r3   _parse_list;  s    

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

        :param value:
        :rtype: dict
        =z&Unable to parse option value to dict: )r   r   r   r   )r   rP   r   resultlinerF   r   valr2   r2   r3   _parse_dictO  s    zConfigHandler._parse_dictc                 C  s   |  }|dkS )zQRepresents value as boolean.

        :param value:
        :rtype: bool
        )1trueyes)lowerr   rP   r2   r2   r3   _parse_bool`  s    zConfigHandler._parse_boolc                   s    fdd}|S )zReturns 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  d| S )Nfile:z"Only strings are accepted for the z field, files are not accepted)re   
ValueError)rP   Zexclude_directiverF   r2   r3   parserv  s    

z3ConfigHandler._exclude_files_parser.<locals>.parserr2   )r   rF   r   r2   r   r3   _exclude_files_parserj  s    	z#ConfigHandler._exclude_files_parserStrPath | Noneroot_dirc                 C  s\   d}t |ts|S ||s |S |t|d }dd |dD }| j| t||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
        r   Nc                 S  s   g | ]}|  qS r2   r   )rf   r:   r2   r2   r3   r     s     z-ConfigHandler._parse_file.<locals>.<listcomp>r   )	r   rA   re   rj   r   rX   rY   r   Z
read_files)r~   rP   r   Zinclude_directivespecZ	filepathsr2   r2   r3   _parse_file  s    

zConfigHandler._parse_filer   c                 C  s:   d}| |s|S ||d}|| jj t|||S )zRepresents value as a module attribute.

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

        :param str value:
        :rtype: str
        zattr: )re   replacerY   rZ   rT   r   Z	read_attr)r~   rP   rT   r   Zattr_directiveZ	attr_descr2   r2   r3   _parse_attr  s    

zConfigHandler._parse_attrc                   s    fdd}|S )zReturns 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 ry   r2   )rP   r`   methodparse_methodsr2   r3   rS     s    
z1ConfigHandler._get_parser_compound.<locals>.parser2   )r   r   rS   r2   r   r3   _get_parser_compound  s    
z"ConfigHandler._get_parser_compoundc                 C  s,   i }|  D ]\}\}}|||||< q|S )a  Parses section options into a dictionary.

        Applies a given parser to each option in a section.

        :param dict section_options:
        :param callable values_parser: function with 2 args corresponding to key, value
        :rtype: dict
        )r   )r   section_optionsvalues_parserrP   rF   _r   r2   r2   r3   _parse_section_to_dict_with_key  s    
z-ConfigHandler._parse_section_to_dict_with_keyNc                   s$    r fddndd }|  ||S )a   Parses section options into a dictionary.

        Optionally applies a given parser to each value.

        :param dict section_options:
        :param callable values_parser: function with 1 arg corresponding to option value
        :rtype: dict
        c                   s    |S ry   r2   r   vr   r2   r3   r     r   z6ConfigHandler._parse_section_to_dict.<locals>.<lambda>c                 S  s   |S ry   r2   r   r2   r2   r3   r     r   r   )r   r   r   r   r2   r   r3   _parse_section_to_dict  s    
z$ConfigHandler._parse_section_to_dictc              
   C  s8   |  D ]*\}\}}tt || |< W 5 Q R X qdS )zQParses configuration file section.

        :param dict section_options:
        N)r   
contextlibsuppressr   )r~   r   rm   r   rP   r2   r2   r3   parse_section  s    zConfigHandler.parse_sectionc                 C  sl   | j  D ]\\}}d}|r$d| }t| d| ddd}|dkr^td| j d| d|| q
dS )	zTParses configuration file items from one
        or more related sections.

        r   r   r   r   __Nz*Unsupported distribution option section: [])r{   r   rI   r   r   rM   )r~   Zsection_namer   Zmethod_postfixZsection_parser_methodr2   r2   r3   rS     s    
zConfigHandler.parsec                   s   t   fdd}|S )zthis function will wrap around parameters that are deprecated

        :param msg: deprecation message
        :param func: function to be wrapped around
        c                    s&    dd tjdf  | |S )N
stacklevelr   z Deprecated config in `setup.cfg`)
setdefault_DeprecatedConfigro   )argskwargsfunckwrt   r2   r3   config_handler	  s    z@ConfigHandler._deprecated_config_handler.<locals>.config_handler)r   )r~   r   rt   r   r   r2   r   r3   _deprecated_config_handler  s    z(ConfigHandler._deprecated_config_handler)r   )N)r   
__module____qualname____doc____annotations__rw   r   classmethodrz   propertyr   r   r   r   r   r   r   r   r   r   r   r   rS   r   r2   r2   r2   r3   rv      s8   
	


	



rv   c                      s^   e Zd ZdZdddddZdZdejfd	d
ddddd fddZe	dd Z
dd Z  ZS )rU   rV   urldescriptionclassifiers	platforms)Z	home_pagesummary
classifierplatformFNr!   r#   r%   rx   zdict | Noner   )rE   r[   r)   rZ   rT   r   c                   s"   t  |||| || _|| _d S ry   )superr   rT   r   )r~   rE   r[   r)   rZ   rT   r   r   r2   r3   r   "  s    	zConfigMetadataHandler.__init__c                 C  sL   | j }t| j| jd}| j}| j}||||| |||d|||| j|dS )r   r   license)r   keywordsprovides	obsoletesr   r   license_filesr   long_descriptionversionproject_urls)r   r   r   r   r   r   r   _parse_version)r~   
parse_listZ
parse_file
parse_dictZexclude_files_parserr2   r2   r3   r   /  s     
zConfigMetadataHandler.parsersc              
   C  s   |  || j}||krh| }zt| W n8 tk
rb } ztd| d| |W 5 d}~X Y nX |S t| || j	| jS )zSParses `version` option value.

        :param value:
        :rtype: str

        zVersion loaded from z does not comply with PEP 440: N)
r   r   r   r   r   r   r   r   r   rT   )r~   rP   r   r   r2   r2   r3   r   E  s    z$ConfigMetadataHandler._parse_version)r   r   r   rM   rw   Zstrict_moder9   curdirr   r   r   r   __classcell__r2   r2   r   r3   rU     s   
rU   c                      s   e Zd ZdZddddd fddZed	d
 Zdd Zdddd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#d$ Z  ZS )%rR   r[   r    r#   r%   rx   )rE   r[   r)   rZ   c                   s$   t  |||| |j| _i | _d S ry   )r   r   rW   r   rT   r}   r   r2   r3   r   b  s    zConfigOptionsHandler.__init__c                 C  s   | j |ddS )N;)r   )r   r   r2   r2   r3   _parse_list_semicolonm  s    z*ConfigOptionsHandler._parse_list_semicolonc                 C  s   | j || jdS )Nr   )r   r   )r~   rP   r2   r2   r3   _parse_file_in_rootq  s    z(ConfigOptionsHandler._parse_file_in_rootrA   )r^   rP   c                 C  s*   |  | |}t||| dd |D S )Nc                 S  s   g | ]}| d s|qS )#rd   )rf   r   r2   r2   r3   r   z  s     
 zAConfigOptionsHandler._parse_requirements_list.<locals>.<listcomp>)r   r   ru   )r~   r^   rP   r`   r2   r2   r3   _parse_requirements_listt  s    z-ConfigOptionsHandler._parse_requirements_listc                 C  sP   | j }| j}| j}| j}||||||| |dt| jd| j| j| j	|t
|dS )r   zeThe namespace_packages parameter is deprecated, consider using implicit namespaces instead (PEP 420).install_requires)Zzip_safeinclude_package_datarT   scriptsZeager_resourcesdependency_linksnamespace_packagesr   setup_requirespackagesentry_points
py_modulespython_requirescmdclass)r   r   r   _parse_cmdclassr   r   r   r   _parse_packagesr   r   )r~   r   Z
parse_boolr   Zparse_cmdclassr2   r2   r3   r   |  s2     zConfigOptionsHandler.parsersc                 C  s   | j j}t| ||| jS ry   )rZ   rT   r   r  r   r   )r~   rP   rT   r2   r2   r3   r    s    z$ConfigOptionsHandler._parse_cmdclassc                 C  s^   ddg}|  }||kr"| |S | | jdi }|j||d k| j| jd tj	f |S )zTParses `packages` option value.

        :param value:
        :rtype: list
        zfind:zfind_namespace:zpackages.findr   )Z
namespacesr   Zfill_package_dir)
r   r   parse_section_packages__findr{   r   rY   r   rT   r   find_packages)r~   rP   Zfind_directivesZtrimmed_valuefind_kwargsr2   r2   r3   r    s    

z$ConfigOptionsHandler._parse_packagesc                   sP   |  || j}dddg  fdd| D }|d}|dk	rL|d |d< |S )zParses `packages.find` configuration file section.

        To be used in conjunction with _parse_packages().

        :param dict section_options:
        whereincludeexcludec                   s"   i | ]\}}| kr|r||qS r2   r2   )rf   kr   Z
valid_keysr2   r3   
<dictcomp>  s
        zEConfigOptionsHandler.parse_section_packages__find.<locals>.<dictcomp>Nr   )r   r   r   r   )r~   r   Zsection_datar
  r  r2   r  r3   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   r   r~   r   r`   r2   r2   r3   parse_section_entry_points  s    z/ConfigOptionsHandler.parse_section_entry_pointsc                 C  s   |  || j}t|S ry   )r   r   r   Zcanonic_package_data)r~   r   package_datar2   r2   r3   _parse_package_data  s    z(ConfigOptionsHandler._parse_package_datac                 C  s   |  || d< dS )z`Parses `package_data` configuration file section.

        :param dict section_options:
        r  Nr  r~   r   r2   r2   r3   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:
        exclude_package_dataNr  r  r2   r2   r3   "parse_section_exclude_package_data  s    z7ConfigOptionsHandler.parse_section_exclude_package_datac                   s      | fdd}| d< dS )zbParses `extras_require` configuration file section.

        :param dict section_options:
        c                   s     d|  d|S )Nzextras_require[r   )r   )r  r   r   r2   r3   r     r   zCConfigOptionsHandler.parse_section_extras_require.<locals>.<lambda>extras_requireNr   r  r2   r   r3   parse_section_extras_require  s
    
z1ConfigOptionsHandler.parse_section_extras_requirec                 C  s$   |  || j}t|| j| d< dS )z^Parses `data_files` configuration file section.

        :param dict section_options:
        
data_filesN)r   r   r   Zcanonic_data_filesr   r  r2   r2   r3   parse_section_data_files  s    z-ConfigOptionsHandler.parse_section_data_files)r   r   r   rM   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r   r2   r2   r   r3   rR   _  s"   

rR   c                   @  s$   e Zd ZdZdZdZedd ZdS )rn   zAmbiguous requirement marker.z
    One of the parsed requirements in `{field}` looks like a valid environment marker:

        {req!r}

    Please make sure that the configuration file is correct.
    You can use dangling lines to avoid this problem.
    z'userguide/declarative_config.html#opt-2c                 K  s"   d| j  }| j| j| j||dS )Nz%https://setuptools.pypa.io/en/latest/)see_urlformat_args)	_SEE_DOCS_format_SUMMARY_DETAILS)r   r   docsr2   r2   r3   rq     s    z_AmbiguousMarker.messageN)r   r   r   r"  r#  r   r   rq   r2   r2   r2   r3   rn     s
   rn   c                   @  s   e Zd ZdZdS )r   z!userguide/declarative_config.htmlN)r   r   r   r   r2   r2   r2   r3   r     s   r   )FF)r2   F)F)Ar   
__future__r   r   rH   r9   collectionsr   r   r   typingr   r   r   r	   r
   r   r   r   r   r   r   packaging.markersr   rk   packaging.requirementsr   r   packaging.specifiersr   packaging.versionr   r   _pathr   errorsr   r   warningsr   r   r   typing_extensionsr   r+   r    distutils.distr!   rA   r"   r   r#   r$   r4   r6   r-   rK   r.   rB   ru   rv   rU   rR   rn   r   r2   r2   r2   r3   <module>   sT   4      .   %M 