o
    4ôjçC  ã                   @   sž  d Z ddlZddlZddlmZ ddlmZ ddl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 d
dlmZmZ d
dlmZ er\ddlmZ ddlm Z  e !e"¡Z#dede$fdd„Z%de$dede&fdd„Z'	d-dddeddfdd„Z(			d.deded fdd„Z)			d/de$dee d e&ded de$f
d!d"„Z*G d#d$„ d$ƒZ+d%d&„ Z,ed e&fd'd(„ƒZ-G d)d*„ d*ej.ƒZ/G d+d,„ d,eƒZ0dS )0ac  
Load setuptools configuration from ``pyproject.toml`` files.

**PRIVATE MODULE**: API reserved for setuptools internal usage only.

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 ``tomllib`` or ``tomli``.
é    N)Úcontextmanager)Úpartial)ÚTYPE_CHECKINGÚCallableÚDictÚMappingÚOptionalÚSeté   )ÚStrPath)Ú	FileErrorÚInvalidConfigError)ÚSetuptoolsWarningé   )Úexpand)Ú_PREVIOUSLY_DEFINEDÚ_MissingDynamic)Úapply©ÚDistribution)ÚSelfÚfilepathÚreturnc                 C   sD   ddl m} t| dƒ�}| |¡W  d   ƒ S 1 sw   Y  d S )Nr
   )ÚtomllibÚrb)Zcompat.py310r   ÚopenÚload)r   r   Úfile© r   úr/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.pyÚ	load_file    s   $ÿr    Úconfigc              
   C   s¦   ddl m} |j d¡}t|dƒr| ¡  z| | ¡W S  |jyR } z*d|j› �}|j	 
d¡dkr=t |¡ t |j¡ d|j	› d	�}t|› d
|› �ƒd ‚d }~ww )Nr   )Ú_validate_pyprojectztrove-classifierÚ_disable_downloadzconfiguration error: ú`Úprojectzinvalid pyproject.toml config: Ú.Ú
)Ú r"   ZFORMAT_FUNCTIONSÚgetÚhasattrr#   ÚvalidateZValidationErrorÚsummaryÚnameÚstripÚ_loggerÚdebugÚdetailsÚ
ValueError)r!   r   Ú	validatorZtrove_classifierÚexr,   Úerrorr   r   r   r+   '   s   

€ør+   FÚdistr   c                 C   s   t |d|| ƒ}t| ||ƒS )zeApply the configuration from a ``pyproject.toml`` file into an existing
    distribution object.
    T)Úread_configurationÚ_apply)r6   r   Úignore_option_errorsr!   r   r   r   Úapply_configuration<   s   r:   Tc           
      C   s  t j | ¡} t j | ¡std| ›d�ƒ‚t| ƒpi }| di ¡}| di ¡}| di ¡}|r2|s4|s4i S d|v r>tjdd� |rPt	|d	d
ƒd
urP| 
d|j¡ n| 
dd¡ ||d< ||d< t|ƒ� |d|idœ}t|| ƒ W d
  ƒ n1 syw   Y  |r�t j | ¡}	t||	||ƒS |S )aÉ  Read given configuration file and returns options from it as a dict.

    :param str|unicode filepath: Path to configuration file in the ``pyproject.toml``
        format.

    :param bool expand: Whether to expand directives and other computed values
        (i.e. post-process the given configuration)

    :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.

    :param Distribution|None: Distribution object to which the configuration refers.
        If not given a dummy object will be created and discarded after the
        configuration is read. This is used for auto-discovery of packages and in the
        case a dynamic configuration (e.g. ``attr`` or ``cmdclass``) is expanded.
        When ``expand=False`` this object is simply ignored.

    :rtype: dict
    zConfiguration file z does not exist.r%   ÚtoolÚ
setuptoolsÚ	distutilsz[tool.distutils])ÚsubjectÚinclude_package_dataNzinclude-package-dataT)r%   r;   )ÚosÚpathÚabspathÚisfiler   r    r)   Ú_ExperimentalConfigurationÚemitÚgetattrÚ
setdefaultr?   Ú_ignore_errorsr+   ÚdirnameÚexpand_configuration)
r   r   r9   r6   ÚasdictZproject_tableZ
tool_tableZsetuptools_tableZsubsetÚroot_dirr   r   r   r7   H   s0   
ýr7   rL   r9   c                 C   s   t | |||ƒ ¡ S )a®  Given a configuration with unresolved fields (e.g. dynamic, cmdclass, ...)
    find their final values.

    :param dict config: Dict containing the configuration for the distribution
    :param str root_dir: Top-level directory for the distribution/project
        (the same directory where ``pyproject.toml`` is place)
    :param bool ignore_option_errors: see :func:`read_configuration`
    :param Distribution|None: Distribution object to which the configuration refers.
        If not given a dummy object will be created and discarded after the
        configuration is read. Used in the case a dynamic configuration
        (e.g. ``attr`` or ``cmdclass``).

    :rtype: dict
    )Ú_ConfigExpanderr   )r!   rL   r9   r6   r   r   r   rJ   Š   s   rJ   c                
   @   sr  e Zd Z			d3dedee deded fdd	„Zd4dd„Zdede	de
fdd„Zd5dd„Zdd„ Zdd„ Zdd„ Zdee	e	f fdd„Zdddee	e	f fdd„Zddde	fd d!„Zd"e	dee	e	f fd#d$„Zddde	dee	e	f fd%d&„Zdddee	e	f fd'd(„Zddd
eee	e	f  fd)d*„Zdddee	e	f d
eee	ef  fd+d,„Zd6d-d.„Zd6d/d0„Zd6d1d2„ZdS )7rM   NFr!   rL   r9   r6   r   c                 C   sp   || _ |pt ¡ | _| di ¡| _| j dg ¡| _| di ¡ di ¡| _| j di ¡| _|| _	|| _
tƒ | _d S )Nr%   Údynamicr;   r<   )r!   r@   ÚgetcwdrL   r)   Úproject_cfgrN   Úsetuptools_cfgÚdynamic_cfgr9   Ú_distÚsetÚ_referenced_files)Úselfr!   rL   r9   r6   r   r   r   Ú__init__¢   s   z_ConfigExpander.__init__r   c                 C   s0   ddl m} | j| j dd ¡dœ}| jp||ƒS )Nr   r   r-   )Úsrc_rootr-   )Úsetuptools.distr   rL   rP   r)   rS   )rV   r   Úattrsr   r   r   Ú_ensure_dist³   s   z_ConfigExpander._ensure_distÚ	containerÚfieldÚfnc                 C   sL   ||v r$t | jƒ� ||| ƒ||< W d   ƒ d S 1 sw   Y  d S d S ©N)rH   r9   )rV   r\   r]   r^   r   r   r   Ú_process_field¹   s
   "ÿÿz_ConfigExpander._process_fieldúpackage-datac                 C   s   | j  |i ¡}t |¡S r_   )rQ   r)   Ú_expandÚcanonic_package_data)rV   r]   Úpackage_datar   r   r   Ú_canonic_package_data¾   s   
z%_ConfigExpander._canonic_package_datac                 C   sŽ   |   ¡  |  ¡  |  d¡ |  ¡ }t|| j| jƒ}|�}|j}|  ¡  |  |¡ |  	||¡ W d   ƒ n1 s8w   Y  |j
 | j
¡ | jS )Nzexclude-package-data)Ú_expand_packagesre   r[   Ú_EnsurePackagesDiscoveredrP   rQ   Úpackage_dirÚ_expand_data_filesÚ_expand_cmdclassÚ_expand_all_dynamicrU   Úupdater!   )rV   r6   ÚctxÚensure_discoveredrh   r   r   r   r   Â   s   

üz_ConfigExpander.expandc                 C   s    | j  d¡}|d u st|ttfƒrd S | d¡}t|tƒrN| j|d< | j  di ¡|d< t| j	ƒ� t
jdi |¤Ž| j d< W d   ƒ d S 1 sGw   Y  d S d S )NÚpackagesÚfindrL   úpackage-dirÚfill_package_dirr   )rQ   r)   Ú
isinstanceÚlistÚtupleÚdictrL   rG   rH   r9   rb   Úfind_packages)rV   ro   rp   r   r   r   rf   Ó   s   


"ÿýz _ConfigExpander._expand_packagesc                 C   s$   t tj| jd�}|  | jd|¡ d S )N)rL   z
data-files)r   rb   Úcanonic_data_filesrL   r`   rQ   )rV   Ú
data_filesr   r   r   ri   ß   s   z"_ConfigExpander._expand_data_filesrh   c                 C   s*   | j }ttj||d�}|  | jd|¡ d S )N)rh   rL   Úcmdclass)rL   r   rb   rz   r`   rQ   )rV   rh   rL   rz   r   r   r   rj   ã   s   z _ConfigExpander._expand_cmdclassc              	      s‚   d‰‡ ‡‡‡fdd„ˆj D ƒ}|jˆ ˆ ˆ¡pi ˆ ˆ ˆ¡ˆ ˆ ¡ˆ ˆ ¡ˆ ˆ ¡ˆ ˆ ¡d� dd„ | ¡ D ƒ}ˆj	 |¡ d S )N)ÚversionÚreadmeúentry-pointsÚscriptsúgui-scriptsÚclassifiersÚdependenciesúoptional-dependenciesc                    s$   i | ]}|ˆvr|ˆ  ˆ |ˆ¡“qS r   )Ú_obtain©Ú.0r]   ©r6   rh   rV   Zspecialr   r   Ú
<dictcomp>ô   s
    þz7_ConfigExpander._expand_all_dynamic.<locals>.<dictcomp>)r{   r|   r€   r�   Zoptional_dependenciesc                 S   s   i | ]\}}|d ur||“qS r_   r   )r…   ÚkÚvr   r   r   r‡     s    )
rN   rl   Ú_obtain_entry_pointsÚ_obtain_versionÚ_obtain_readmeÚ_obtain_classifiersÚ_obtain_dependenciesÚ_obtain_optional_dependenciesÚitemsrP   )rV   r6   rh   Zobtained_dynamicZupdatesr   r†   r   rk   è   s   þ
ú
z#_ConfigExpander._expand_all_dynamicc                 C   s6   t | |ƒ}|d u r| jsd|›d�}t|ƒ‚d S d S )Nz#No configuration found for dynamic z�.
Some dynamic fields need to be specified via `tool.setuptools.dynamic`
others must be specified via the equivalent attribute in `setup.py`.)r   r9   r   )rV   r6   r]   ZpreviousÚmsgr   r   r   Ú_ensure_previously_set  s   
ÿúz&_ConfigExpander._ensure_previously_setÚ	specifierc                 C   s¨   ddl m} t| jƒ�? | j}d|v r,| j ||d ƒ¡ t |d |¡W  d   ƒ S d|v r@t 	|d ||¡W  d   ƒ S t
d|› d|›�ƒ‚1 sMw   Y  d S )Nr   )Úalways_iterabler   Úattrz	invalid `z`: )Ú setuptools.extern.more_itertoolsr”   rH   r9   rL   rU   rl   rb   Ú
read_filesÚ	read_attrr2   )rV   r“   Ú	directiverh   r”   rL   r   r   r   Ú_expand_directive  s   üúùz!_ConfigExpander._expand_directivec                 C   s4   || j v r|  d|› �| j | |¡S |  ||¡ d S )Nztool.setuptools.dynamic.)rR   rš   r’   )rV   r6   r]   rh   r   r   r   rƒ     s   
ýz_ConfigExpander._obtainc                 C   s,   d| j v rd| jv rt |  |d|¡¡S d S )Nr{   )rN   rR   rb   r{   rƒ   )rV   r6   rh   r   r   r   r‹   )  s   z_ConfigExpander._obtain_versionc                 C   sL   d| j vrd S | j}d|v r|  |di ¡|d  dd¡dœS |  |d¡ d S )Nr|   úcontent-typez
text/x-rst)Útextr›   )rN   rR   rƒ   r)   r’   )rV   r6   rR   r   r   r   rŒ   /  s   
þz_ConfigExpander._obtain_readmec                    s|   d}t ‡fdd„|D ƒƒsd S ˆ |d|¡}|d u rd S t |¡‰dˆi‰ dtdtf‡ ‡‡fdd„}|d	d
ƒ |ddƒ ˆ S )N)r}   r~   r   c                 3   s   � | ]}|ˆ j v V  qd S r_   )rN   r„   ©rV   r   r   Ú	<genexpr>A  s   € z7_ConfigExpander._obtain_entry_points.<locals>.<genexpr>r}   r]   Úgroupc                    s<   |ˆv rˆ  |¡}| ˆjvrtt | |¡ƒ‚|ˆ | < d S d S r_   )ÚpoprN   r   r   r1   )r]   rŸ   Úvalue©ZexpandedÚgroupsrV   r   r   Ú_set_scriptsK  s   

üz:_ConfigExpander._obtain_entry_points.<locals>._set_scriptsr~   Zconsole_scriptsr   Zgui_scripts)Úanyrƒ   rb   Úentry_pointsÚstr)rV   r6   rh   Úfieldsrœ   r¤   r   r¢   r   rŠ   =  s   


z$_ConfigExpander._obtain_entry_pointsc                 C   s(   d| j v r|  |di ¡}|r| ¡ S d S )Nr€   )rN   rƒ   Ú
splitlines©rV   r6   r¡   r   r   r   r�   W  ó
   
z#_ConfigExpander._obtain_classifiersc                 C   s(   d| j v r|  |di ¡}|rt|ƒS d S )Nr�   )rN   rƒ   Ú_parse_requirements_listrª   r   r   r   rŽ   ^  r«   z$_ConfigExpander._obtain_dependenciesc                    sV   dˆ j vrd S dˆ jv r#ˆ jd }t|tƒsJ ‚‡ fdd„| ¡ D ƒS ˆ  |d¡ d S )Nr‚   c              	      s*   i | ]\}}|t ˆ  d |› �|i ¡ƒ“qS )z.tool.setuptools.dynamic.optional-dependencies.)r¬   rš   )r…   rŸ   r™   r�   r   r   r‡   k  s    ùýÿÿzA_ConfigExpander._obtain_optional_dependencies.<locals>.<dictcomp>)rN   rR   rs   rv   r�   r’   )rV   r6   Zoptional_dependencies_mapr   r�   r   r�   e  s   



ø
z-_ConfigExpander._obtain_optional_dependencies©NFN)r   r   )ra   )r6   r   )Ú__name__Ú
__module__Ú__qualname__rv   r   r   ÚboolrW   r[   r§   r   r`   re   r   rf   ri   r   rj   rk   r’   rš   rƒ   r‹   r   rŒ   rŠ   r�   rŽ   r�   r   r   r   r   rM   ¡   sP    ûþýü
û


ÿ

ÿ
ÿ
ÿ
þ

rM   c                 C   s   dd„ |   ¡ D ƒS )Nc                 S   s&   g | ]}|  ¡ r|  ¡  d ¡s|‘qS )ú#)r.   Ú
startswith)r…   Úliner   r   r   Ú
<listcomp>z  s    ýýÿz,_parse_requirements_list.<locals>.<listcomp>)r©   )r¡   r   r   r   r¬   y  s   þr¬   c              
   c   s^   � | sd V  d S zd V  W d S  t y. } zt d|jj› d|› �¡ W Y d }~d S d }~ww )Nzignored error: z - )Ú	Exceptionr/   r0   Ú	__class__r®   )r9   r4   r   r   r   rH   �  s   €(€ÿrH   c                       sD   e Zd Zdddedef‡ fdd„Zd‡ fd	d
„Z‡ fdd„Z‡  ZS )rg   Údistributionr   rP   rQ   c                    s   t ƒ  |¡ || _|| _d S r_   )ÚsuperrW   Ú_project_cfgÚ_setuptools_cfg)rV   r¸   rP   rQ   ©r·   r   r   rW   Ž  s   
z"_EnsurePackagesDiscovered.__init__r   r   c                    sŒ   | j | j}}| di ¡}| |jpi ¡ ||_|j ¡  |jjdu r+| j	 
d¡|j_|jdu r6| 
d¡|_|jdu rA| 
d¡|_tƒ  ¡ S )z«When entering the context, the values of ``packages``, ``py_modules`` and
        ``package_dir`` that are missing in ``dist`` are copied from ``setuptools_cfg``.
        rq   Nr-   ú
py-modulesro   )rS   r»   rG   rl   rh   Úset_defaultsÚ_ignore_ext_modulesÚmetadatar-   rº   r)   Ú
py_modulesro   r¹   Ú	__enter__)rV   r6   Úcfgrh   r¼   r   r   rÂ   •  s   



z#_EnsurePackagesDiscovered.__enter__c                    s4   | j  d| jj¡ | j  d| jj¡ tƒ  |||¡S )zŸWhen exiting the context, if values of ``packages``, ``py_modules`` and
        ``package_dir`` are missing in ``setuptools_cfg``, copy from ``dist``.
        ro   r½   )r»   rG   rS   ro   rÁ   r¹   Ú__exit__)rV   Úexc_typeÚ	exc_valueÚ	tracebackr¼   r   r   rÄ   «  s   z"_EnsurePackagesDiscovered.__exit__)r   r   )r®   r¯   r°   rv   rW   rÂ   rÄ   Ú__classcell__r   r   r¼   r   rg   �  s    ÿÿÿrg   c                   @   s   e Zd ZdZdS )rD   z``{subject}` in `pyproject.toml` is still *experimental* and likely to change in future releases.N)r®   r¯   r°   Ú_SUMMARYr   r   r   r   rD   µ  s    ÿrD   )F)TFNr­   )1Ú__doc__Úloggingr@   Ú
contextlibr   Ú	functoolsr   Útypingr   r   r   r   r   r	   Ú_pathr   Úerrorsr   r   Úwarningsr   r(   r   rb   Z_apply_pyprojecttomlr   r   r   r8   rY   r   Útyping_extensionsr   Ú	getLoggerr®   r/   rv   r    r±   r+   r:   r7   rJ   rM   r¬   rH   ÚEnsurePackagesDiscoveredrg   rD   r   r   r   r   Ú<module>   sn     
ýÿþ
üüÿ
üDüÿþýü
û Y(