a
    6Rhg                     @  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 ddl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mZ ddl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.e/e0e/ef f Z1de2d< e.e/e1f Z3de2d< edddZ4dEdddddd d!Z5dddd"d#d$Z6dFddd&dd'd(d)d*Z7d+d,d-d.d/Z8d0dd1d2d3Z9dGdddd'd4d5d6Z:d,d,d7d8d9d:Z;G d;d< d<ee4 Z<G d=d> d>e<d Z=G d?d@ d@e<d Z>G dAdB dBe&Z?G dCdD dDe&Z@dS )Ha<  
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)IterableIterator)partialwraps)TYPE_CHECKINGAnyCallableClassVarGenericTypeVarcast)default_environment)InvalidRequirementRequirement)InvalidVersionVersion   )_static)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 r0   P/opt/python-3.9.24/usr/lib/python3.9/site-packages/setuptools/config/setupcfg.pyread_configuration2   s
    r2   )r-   r%   r(   c                 C  s   t | | |   | S )z`Apply the configuration from a ``setup.cfg`` file into an existing
    distribution object.
    )r+   Z_finalize_requires)r-   r%   r0   r0   r1   apply_configurationL   s    
r3   r0   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	| g ||}z>|j
| ttt |d t| | j|d}|   W t| nt| 0 |S )zHRead configuration from ``filepath`` and applies to the ``dist`` object.r   )_DistributionzConfiguration file z does not exist.)r.   )r'   )r)   r5   ospathabspathisfiler   getcwdchdirdirnameparse_config_filesr   liststrparse_configurationcommand_optionsZ_finalize_license_files)r-   r%   r4   r'   r5   Zcurrent_directoryr.   r/   r0   r0   r1   r+   U   s    
r+   z#Distribution | DistributionMetadatar?   )
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)rB   rC   Zgetter_nameZby_attributegetterr0   r0   r1   _get_optiont   s    
rH   zKIterable[ConfigHandler[Distribution] | ConfigHandler[DistributionMetadata]])r/   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_optionsrH   rB   section_prefix)r/   Zconfig_dicthandleroptionvaluer0   r0   r1   r,      s    
r,   )distributionrA   r'   r(   c                 C  s   t | f}t| |||}|  | js0|j| _t| j|||| j| j}|  | j	|j|j W d   n1 sv0    Y  ||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
    N)
r   ZEnsurePackagesDiscoveredConfigOptionsHandlerparsepackage_dirConfigMetadataHandlermetadatasrc_root_referenced_filesupdate)rN   rA   r'   ensure_discoveredoptionsmetar0   r0   r1   r@      s.    "r@   r>   )label
orig_valueparsedc              
     s   d|v st  dkrdS t  }z,t d }|j|v rLtj|  d d W nV ty } z>t fdd|D rtj	|  d d}t||W Y d}~n
d}~0 0 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\   r0   r1   	<genexpr>       z8_warn_accidental_env_marker_misconfig.<locals>.<genexpr>)
len
marker_envkeysr   name_AmbiguousMarkeremitr   anymessage)rZ   r[   r\   markersr_   exmsgr0   rd   r1   %_warn_accidental_env_marker_misconfig   s    

rr   c                   @  s   e Zd ZU dZded< i Zded< 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d-d.Zd	dd/d0Zd1d2 Zd*S )5ConfigHandlerz1Handles metadata supplied in configuration files.r?   rJ   zClassVar[dict[str, str]]aliasesr"   r!   expand.EnsurePackagesDiscoveredNone)rB   rX   rW   r(   c                 C  s8   || _ || _t| || _g | _|| _tt  | _	d S N)
r'   rB   r$   _section_optionssectionsrI   rW   setr?   rU   selfrB   rX   r'   rW   r0   r0   r1   __init__   s    zConfigHandler.__init__z*Iterator[tuple[str, SingleCommandOptions]])rX   r(   c                 c  s>   |  D ]0\}}|| j\}}}|r(q|d|fV  qd S )N.)items	partitionrJ   lstrip)clsrX   Z	full_namerM   preZ_seprj   r0   r0   r1   rx     s
    zConfigHandler._section_optionsc                 C  s   t | jj ddS ).Metadata item name to parser function mapping.z must provide .parsers propertyN)NotImplementedError	__class____name__r|   r0   r0   r1   parsers  s    zConfigHandler.parsersr(   c           	   
   C  s   | j }| j||}zt||}W n. tyP } zt||W Y d }~n
d }~0 0 |rZd S z| j|dd |}W n tf| j y   Y d S 0 t	
|j|}t|d| |}|| | j| d S )Nc                 S  s   | S rw   r0   )xr0   r0   r1   <lambda>&  rf   z+ConfigHandler.__setitem__.<locals>.<lambda>set_)rB   rt   getrF   AttributeErrorKeyErrorr   	Exceptionr'   rE   r   __setattr__rI   append)	r|   Zoption_namerM   rB   current_valueer\   Zsimple_settersetterr0   r0   r1   __setitem__  s      zConfigHandler.__setitem__,c                 C  s8   t |tr|S d|v 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
        r]   c                 S  s   g | ]}|  r|  qS r0   strip)rb   chunkr0   r0   r1   
<listcomp>B  rf   z-ConfigHandler._parse_list.<locals>.<listcomp>)
isinstancer>   
splitlinessplit)r   rM   	separatorr0   r0   r1   _parse_list0  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   rM   r   resultlinerC   sepvalr0   r0   r1   _parse_dictD  s    zConfigHandler._parse_dictc                 C  s   |  }|dv S )zQRepresents value as boolean.

        :param value:
        :rtype: bool
        )1trueyes)lowerr   rM   r0   r0   r1   _parse_boolU  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t| S )Nfile:z"Only strings are accepted for the z field, files are not accepted)ra   
ValueErrorr   Str)rM   Zexclude_directiverC   r0   r1   parserk  s    

z3ConfigHandler._exclude_files_parser.<locals>.parserr0   )r   rC   r   r0   r   r1   _exclude_files_parser_  s    	z#ConfigHandler._exclude_files_parserStrPath | Noneroot_dirc                 C  sh   d}t |ts|S ||s&t|S |t|d }dd |dD }| j| t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 r0   r   )rb   r7   r0   r0   r1   r     rf   z-ConfigHandler._parse_file.<locals>.<listcomp>r   )r   r?   ra   r   r   rg   r   rU   rV   r   Z
read_files)r|   rM   r   Zinclude_directivespecZ	filepathsr0   r0   r1   _parse_filev  s    


zConfigHandler._parse_filer   c                 C  s@   d}| |st|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: )	ra   r   r   replacerV   rW   rQ   r   Z	read_attr)r|   rM   rQ   r   Zattr_directiveZ	attr_descr0   r0   r1   _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 rw   r0   )rM   r\   methodparse_methodsr0   r1   rP     s    
z1ConfigHandler._get_parser_compound.<locals>.parser0   )r   r   rP   r0   r   r1   _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_parserrM   rC   _r   r0   r0   r1   _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 rw   r0   r   vr   r0   r1   r     rf   z6ConfigHandler._parse_section_to_dict.<locals>.<lambda>c                 S  s   |S rw   r0   r   r0   r0   r1   r     rf   )r   )r   r   r   r   r0   r   r1   _parse_section_to_dict  s    
z$ConfigHandler._parse_section_to_dictc              	   C  sL   |  D ]>\}\}}tt || |< W d   q1 s<0    Y  qdS )zQParses configuration file section.

        :param dict section_options:
        N)r   
contextlibsuppressr   )r|   r   rj   r   rM   r0   r0   r1   parse_section  s    zConfigHandler.parse_sectionc                 C  sl   | j  D ]\\}}d}|r$d| }t| d| ddd}|du 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: [])ry   r   rF   r   r   rJ   )r|   section_namer   Zmethod_postfixZsection_parser_methodr0   r0   r1   rP     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i   | i |S )N
stacklevelr   z Deprecated config in `setup.cfg`)
setdefault_DeprecatedConfigrl   )argskwargsfunckwrq   r0   r1   config_handler  s    z@ConfigHandler._deprecated_config_handler.<locals>.config_handler)r   )r|   r   rq   r   r   r0   r   r1   _deprecated_config_handler  s    z(ConfigHandler._deprecated_config_handler)r   )N)r   
__module____qualname____doc____annotations__rt   r}   classmethodrx   propertyr   r   r   r   r   r   r   r   r   r   r   r   rP   r   r0   r0   r0   r1   rs      s8   
	


	



rs   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d fddZe	dd Z
dd Z  ZS )rR   rS   urldescriptionclassifiers	platforms)Z	home_pagesummary
classifierplatformFNr   r!   r#   ru   zdict | Noner   rv   )rB   rX   r'   rW   rQ   r   r(   c                   s"   t  |||| || _|| _d S rw   )superr}   rQ   r   )r|   rB   rX   r'   rW   rQ   r   r   r0   r1   r}     s    	zConfigMetadataHandler.__init__c                 C  sx   |  | jtj}|  | jtj}t| j| jd}| j	}tj
tj
tj
tj
|||||  |||d|||tj
| jtj
|dS )r   r   license)authorauthor_email
maintainermaintainer_emailr   keywordsprovides	obsoletesr   r   Zlicense_filesr   long_descriptionZlong_description_content_typeversionr   Zproject_urls)r   r   r   Listr   Dictr   r   r   r   r   _parse_version)r|   Zparse_list_staticZparse_dict_static
parse_fileZexclude_files_parserr0   r0   r1   r   %  s,    
zConfigMetadataHandler.parsersc              
   C  s   |  || j}||krj| }zt| W n: tyd } z"td| d| |W Y d}~n
d}~0 0 |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   rQ   )r|   rM   r   r   r0   r0   r1   r   A  s    z$ConfigMetadataHandler._parse_version)r   r   r   rJ   rt   Zstrict_moder6   curdirr}   r   r   r   __classcell__r0   r0   r   r1   rR     s    
rR   c                      s   e Zd ZdZd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ddZdd Zdddd Zddd!d"Zddd#d$Zddd%d&Z  ZS )'rO   rX   r   r!   r#   ru   rv   )rB   rX   r'   rW   r(   c                   s$   t  |||| |j| _i | _d S rw   )r   r}   rT   r   rQ   r{   r   r0   r1   r}   ^  s    zConfigOptionsHandler.__init__c                 C  s   | j |ddS )N;)r   )r   r   r0   r0   r1   _parse_list_semicoloni  s    z*ConfigOptionsHandler._parse_list_semicolonc                 C  s   | j || jdS )Nr   )r   r   )r|   rM   r0   r0   r1   _parse_file_in_rootm  s    z(ConfigOptionsHandler._parse_file_in_rootr?   )rZ   rM   c                 C  s0   |  | |}t||| tdd |D S )Nc                 s  s   | ]}| d s|V  qdS )#Nr`   )rb   r   r0   r0   r1   re   v  rf   z@ConfigOptionsHandler._parse_requirements_list.<locals>.<genexpr>)r   r   rr   r   r   )r|   rZ   rM   r\   r0   r0   r1   _parse_requirements_listp  s    z-ConfigOptionsHandler._parse_requirements_listc                 C  sN   | j }| j}| j}||| j|||| |dt| jd| j| j| j	|t
j|dS )r   zeThe namespace_packages parameter is deprecated, consider using implicit namespaces instead (PEP 420).install_requires)Zzip_safeZinclude_package_datarQ   scriptsZeager_resourcesZdependency_linksnamespace_packagesr   Zsetup_requirespackagesentry_points
py_modulesZpython_requirescmdclass)r   r   _parse_cmdclassr   r   r   r   r   _parse_packagesr   r   SpecifierSet)r|   Z
parse_listZ
parse_boolZparse_cmdclassr0   r0   r1   r   y  s.    zConfigOptionsHandler.parsersc                 C  s   | j j}t| ||| jS rw   )rW   rQ   r   r  r   r   )r|   rM   rQ   r0   r0   r1   r    s    z$ConfigOptionsHandler._parse_cmdclassc                 C  sb   ddg}|  }||vr"| |S | | jdi }|j||d k| j| jd tj	f i |S )zTParses `packages` option value.

        :param value:
        :rtype: list
        zfind:zfind_namespace:zpackages.findr   )
namespacesr   Zfill_package_dir)
r   r   parse_section_packages__findry   r   rV   r   rQ   r   Zfind_packages)r|   rM   Zfind_directivesZtrimmed_valuefind_kwargsr0   r0   r1   r    s    

z$ConfigOptionsHandler._parse_packagesc                   sN   |  || j}g d  fdd| D }|d}|durJ|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 | ]\}}| v r|r||qS r0   r0   )rb   kr   Z
valid_keysr0   r1   
<dictcomp>  rf   zEConfigOptionsHandler.parse_section_packages__find.<locals>.<dictcomp>r	  Nr   )r   r   r   r   )r|   r   Zsection_datar  r	  r0   r  r1   r    s    
z1ConfigOptionsHandler.parse_section_packages__findr   c                 C  s   |  || j}|| d< dS )z`Parses `entry_points` configuration file section.

        :param dict section_options:
        r   N)r   r   r|   r   r\   r0   r0   r1   parse_section_entry_points  s    z/ConfigOptionsHandler.parse_section_entry_pointsc                 C  s   |  || j}t|S rw   )r   r   r   Zcanonic_package_data)r|   r   package_datar0   r0   r1   _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   r0   r0   r1   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_dataNr  r  r0   r0   r1   "parse_section_exclude_package_data  s    z7ConfigOptionsHandler.parse_section_exclude_package_datac                   s&     | fdd}t| 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   r0   r1   r     rf   zCConfigOptionsHandler.parse_section_extras_require.<locals>.<lambda>Zextras_requireN)r   r   r   r  r0   r   r1   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  r0   r0   r1   parse_section_data_files  s    z-ConfigOptionsHandler.parse_section_data_files)r   r   r   rJ   r}   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r   r0   r0   r   r1   rO   [  s"   
	
rO   c                   @  s$   e Zd ZdZdZdZedd ZdS )rk   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/)Zsee_urlZformat_args)	_SEE_DOCS_format_SUMMARY_DETAILS)r   r   docsr0   r0   r1   rn     s    z_AmbiguousMarker.messageN)r   r   r   r  r  r  r   rn   r0   r0   r0   r1   rk     s
   rk   c                   @  s   e Zd ZdZdS )r   z!userguide/declarative_config.htmlN)r   r   r   r  r0   r0   r0   r1   r     s   r   )FF)r0   F)F)Ar   
__future__r   r   rE   r6   collectionsr   collections.abcr   r   r   r   typingr   r	   r
   r   r   r   r   Zpackaging.markersr   rh   Zpackaging.requirementsr   r   Zpackaging.versionr   r   r   r   _pathr   errorsr   r   warningsr   r   Ztyping_extensionsr   r)   r   distutils.distr   r$   r?   tupler    r   r!   r"   r2   r3   r+   rH   r,   r@   rr   rs   rR   rO   rk   r   r0   r0   r0   r1   <module>   sT   $    .   &S 