o
    5‘ðibI  ã                   @  sr  d Z ddlm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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mZ erdddl m!Z! ddl"m#Z# e $e%¡Z&d8dd„Z'd9dd„Z(	d:d;d d!„Z)	"		d<d=d&d'„Z*			d>d?d*d+„Z+G d,d-„ d-ƒZ,d.d/„ Z-ed@d0d1„ƒZ.G d2d3„ d3ej/ƒZ0G d4d5„ d5eƒZ1G d6d7„ d7eƒZ2dS )Aac  
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``.
é    )ÚannotationsN)ÚMapping)Úcontextmanager)Úpartial)ÚTracebackType)ÚTYPE_CHECKINGÚAnyÚCallableé   )ÚStrPath)Ú	FileErrorÚInvalidConfigError)ÚSetuptoolsWarningé   )Úexpand)Ú_PREVIOUSLY_DEFINEDÚ_MissingDynamicÚapply)ÚSelf©ÚDistributionÚfilepathr   ÚreturnÚdictc                 C  sD   ddl m} t| dƒ�}| |¡W  d   ƒ S 1 sw   Y  d S )Nr
   )ÚtomllibÚrb)Úcompat.py310r   ÚopenÚload)r   r   Úfile© r    ú^/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.pyÚ	load_file$   s   $ÿr"   ÚconfigÚboolc              
   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%   ÚFORMAT_FUNCTIONSÚgetÚhasattrr&   ÚvalidateÚValidationErrorÚsummaryÚnameÚstripÚ_loggerÚdebugÚdetailsÚ
ValueError)r#   r   Ú	validatorÚtrove_classifierÚexr1   Úerrorr    r    r!   r/   +   s   

€ør/   FÚdistr   Úignore_option_errorsc                 C  s   t |d|| ƒ}t| ||ƒS )zeApply the configuration from a ``pyproject.toml`` file into an existing
    distribution object.
    T)Úread_configurationÚ_apply)r<   r   r=   r#   r    r    r!   Úapply_configuration@   s   r@   Tr   úDistribution | Noneúdict[str, Any]c                   sv  t j | ¡} t j | ¡std| ›d�ƒ‚t| ƒpi }| di ¡}| di ¡}| di ¡}|r2|s4|s4i S d| di ¡v r@t ¡  d|v rJt	jdd	� |rY|j
d
urY| d|j
¡ n| dd¡ ||d< ||d< d|v rqt	jdd	� d}|| dg ¡f‰ t‡ fdd„|D ƒƒrŠtdƒ‚t|ƒ� |d|idœ}	t|	| ƒ W d
  ƒ n1 s¥w   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ÚtoolsÚ	distutilsz[tool.distutils])ÚsubjectNzinclude-package-dataTzext-modulesz[tool.setuptools.ext-modules])zimport-nameszimport-namespacesÚdynamicc                 3  s"   � | ]}ˆ D ]}||v V  qqd S ©Nr    )Ú.0ÚfieldÚplace©Úplacesr    r!   Ú	<genexpr>‹   s   €  z%read_configuration.<locals>.<genexpr>zÁSetuptools does not support `import-names` and `import-namespaces` in `pyproject.toml` yet. If your are interested in this feature,  please consider submitting a contribution via pull requests.)r(   rC   )ÚosÚpathÚabspathÚisfiler   r"   r-   Ú_ToolsTypoInMetadataÚemitÚ_ExperimentalConfigurationÚinclude_package_dataÚ
setdefaultÚanyÚNotImplementedErrorÚ_ignore_errorsr/   ÚdirnameÚexpand_configuration)r   r   r=   r<   ÚasdictÚproject_tableÚ
tool_tableÚsetuptools_tableÚfieldsÚsubsetÚroot_dirr    rM   r!   r>   L   sD   ÿ
ýr>   rd   úStrPath | Nonec                 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#   rd   r=   r<   r    r    r!   r]   ž   s   r]   c                   @  sÂ   e Zd Z			d=d>dd„Zd?dd„Zd@dd„ZdAdd„Zdd„ Zdd„ Zd d!„ Z	dBd$d%„Z
dCd&d'„ZdDd(d)„ZdEd+d,„ZdFd-d.„ZdCd/d0„ZdGd2d3„ZdHd5d6„ZdId7d8„ZdId9d:„ZdId;d<„ZdS )Jrf   NFr#   r   rd   re   r=   r$   r<   rA   r   ÚNonec                 C  st   || _ |pt ¡ | _| di ¡| _| j dg ¡| _| di ¡ di ¡| _| j di ¡| _|| _	|| _
tt ƒ | _d S )Nr(   rH   rC   rD   )r#   rP   Úgetcwdrd   r-   Úproject_cfgrH   Úsetuptools_cfgÚdynamic_cfgr=   Ú_distÚsetÚstrÚ_referenced_files)Úselfr#   rd   r=   r<   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   r2   )Úsrc_rootr2   )Úsetuptools.distr   rd   ri   r-   rl   )rp   r   Úattrsr    r    r!   Ú_ensure_distÇ   s   z_ConfigExpander._ensure_distÚ	containerrK   rn   Úfnr	   c                 C  sL   ||v r$t | jƒ� ||| ƒ||< W d   ƒ d S 1 sw   Y  d S d S rI   )r[   r=   )rp   rv   rK   rw   r    r    r!   Ú_process_fieldÍ   s
   "ÿÿz_ConfigExpander._process_fieldúpackage-datac                 C  s   | j  |i ¡}t |¡S rI   )rj   r-   Ú_expandÚcanonic_package_data)rp   rK   Ú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_packagesr}   ru   Ú_EnsurePackagesDiscoveredri   rj   Úpackage_dirÚ_expand_data_filesÚ_expand_cmdclassÚ_expand_all_dynamicro   Úupdater#   )rp   r<   ÚctxÚensure_discoveredr€   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Úfindrd   úpackage-dirÚfill_package_dirr    )rj   r-   Ú
isinstanceÚlistÚtupler   rd   rX   r[   r=   rz   Úfind_packages)rp   r‡   rˆ   r    r    r!   r~   ç   s   


"ÿýz _ConfigExpander._expand_packagesc                 C  s$   t tj| jd�}|  | jd|¡ d S )N)rd   z
data-files)r   rz   Úcanonic_data_filesrd   rx   rj   )rp   Ú
data_filesr    r    r!   r�   ó   s   z"_ConfigExpander._expand_data_filesr€   úMapping[str, str]c                 C  s*   | j }ttj||d�}|  | jd|¡ d S )N)r€   rd   Úcmdclass)rd   r   rz   r’   rx   rj   )rp   r€   rd   r’   r    r    r!   r‚   ÷   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©rJ   rK   ©r<   r€   rp   Úspecialr    r!   Ú
<dictcomp>  s
    þz7_ConfigExpander._expand_all_dynamic.<locals>.<dictcomp>)r“   r”   r˜   r™   Úoptional_dependenciesc                 S  s   i | ]\}}|d ur||“qS rI   r    )rJ   ÚkÚvr    r    r!   rŸ     s    )
rH   r„   Ú_obtain_entry_pointsÚ_obtain_versionÚ_obtain_readmeÚ_obtain_classifiersÚ_obtain_dependenciesÚ_obtain_optional_dependenciesÚitemsri   )rp   r<   r€   Úobtained_dynamicÚupdatesr    r�   r!   rƒ   ü   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   r=   r   )rp   r<   rK   Ú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`: )Úmore_itertoolsr°   r[   r=   rd   ro   r„   rz   Ú
read_filesÚ	read_attrr7   )rp   r¯   Ú	directiver€   r°   rd   r    r    r!   Ú_expand_directive$  s   üúùz!_ConfigExpander._expand_directivec                 C  s4   || j v r|  d|› �| j | |¡S |  ||¡ d S )Nztool.setuptools.dynamic.)rk   r¶   r®   )rp   r<   rK   r€   r    r    r!   r›   3  s   
ýz_ConfigExpander._obtainc                 C  s,   d| j v rd| jv rt |  |d|¡¡S d S )Nr“   )rH   rk   rz   r“   r›   )rp   r<   r€   r    r    r!   r¤   =  s
   þz_ConfigExpander._obtain_versionúdict[str, str] | Nonec                 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¸   )rH   rk   r›   r-   r®   )rp   r<   rk   r    r    r!   r¥   F  s   
ýz_ConfigExpander._obtain_readmeú dict[str, dict[str, Any]] | Nonec                   st   d}t ‡fdd„|D ƒƒsd S ˆ |d|¡}|d u rd S t |¡‰dˆi‰ d‡ ‡‡fdd	„}|d
dƒ |ddƒ ˆ S )N)r•   r–   r—   c                 3  s   � | ]}|ˆ j v V  qd S rI   )rH   rœ   ©rp   r    r!   rO   Y  s   € z7_ConfigExpander._obtain_entry_points.<locals>.<genexpr>r•   rK   rn   Úgroupc                   s<   |ˆv rˆ  |¡}| ˆjvrtt | |¡ƒ‚|ˆ | < d S d S rI   )ÚpoprH   r   r   r6   )rK   r¼   Úvalue©ÚexpandedÚgroupsrp   r    r!   Ú_set_scriptsd  s   

üz:_ConfigExpander._obtain_entry_points.<locals>._set_scriptsr–   Úconsole_scriptsr—   Úgui_scripts)rK   rn   r¼   rn   )rY   r›   rz   Úentry_points)rp   r<   r€   rb   r¹   rÂ   r    r¿   r!   r£   U  s   


z$_ConfigExpander._obtain_entry_pointsc                 C  s(   d| j v r|  |di ¡}|r| ¡ S d S )Nr˜   )rH   r›   Ú
splitlines©rp   r<   r¾   r    r    r!   r¦   p  ó
   
z#_ConfigExpander._obtain_classifiersc                 C  s(   d| j v r|  |di ¡}|rt|ƒS d S )Nr™   )rH   r›   Ú_parse_requirements_listrÇ   r    r    r!   r§   w  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¶   )rJ   r¼   rµ   r»   r    r!   rŸ   „  s    ùýÿÿzA_ConfigExpander._obtain_optional_dependencies.<locals>.<dictcomp>)rH   rk   r‹   r   r©   r®   )rp   r<   Úoptional_dependencies_mapr    r»   r!   r¨   ~  s   



ø
z-_ConfigExpander._obtain_optional_dependencies©NFN)
r#   r   rd   re   r=   r$   r<   rA   r   rg   )r   r   )rv   r   rK   rn   rw   r	   )ry   )r€   r‘   )r<   r   r€   r‘   )r<   r   rK   rn   )r¯   rn   r€   r‘   )r<   r   rK   rn   r€   r‘   )r<   r   r   r·   )r<   r   r€   r‘   r   rº   )r<   r   )Ú__name__Ú
__module__Ú__qualname__rq   ru   rx   r}   r   r~   r�   r‚   rƒ   r®   r¶   r›   r¤   r¥   r£   r¦   r§   r¨   r    r    r    r!   rf   µ   s,    û











	


rf   c                 C  s   dd„ |   ¡ D ƒS )Nc                 S  s&   g | ]}|  ¡ r|  ¡  d ¡s|‘qS )ú#)r3   Ú
startswith)rJ   Úliner    r    r!   Ú
<listcomp>“  s    ýýÿz,_parse_requirements_list.<locals>.<listcomp>)rÆ   )r¾   r    r    r!   rÉ   ’  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 - )Ú	Exceptionr4   r5   Ú	__class__rÌ   )r=   r:   r    r    r!   r[   š  s   €(€ÿr[   c                      s:   e Zd Zd‡ fdd	„Zd‡ fdd„Zd‡ fdd„Z‡  ZS )r   Údistributionr   ri   r   rj   r   rg   c                   s   t ƒ  |¡ || _|| _d S rI   )Úsuperrq   Ú_project_cfgÚ_setuptools_cfg)rp   rÕ   ri   rj   ©rÔ   r    r!   rq   §  s   
z"_EnsurePackagesDiscovered.__init__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``.
        r‰   Nr2   ú
py-modulesr‡   )rl   rØ   rX   r„   r€   Úset_defaultsÚ_ignore_ext_modulesÚmetadatar2   r×   r-   Ú
py_modulesr‡   rÖ   Ú	__enter__)rp   r<   Úcfgr€   rÙ   r    r!   rß   ®  s   



z#_EnsurePackagesDiscovered.__enter__Úexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackúTracebackType | Nonec                   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``.
        r‡   rÚ   )rØ   rX   rl   r‡   rÞ   rÖ   Ú__exit__)rp   rá   rã   rå   rÙ   r    r!   rç   Ä  s   
z"_EnsurePackagesDiscovered.__exit__)rÕ   r   ri   r   rj   r   r   rg   )r   r   )rá   râ   rã   rä   rå   ræ   r   rg   )rÌ   rÍ   rÎ   rq   rß   rç   Ú__classcell__r    r    rÙ   r!   r   ¦  s    r   c                   @  ó   e Zd ZdZdS )rV   z``{subject}` in `pyproject.toml` is still *experimental* and likely to change in future releases.N©rÌ   rÍ   rÎ   Ú_SUMMARYr    r    r    r!   rV   Ó  ó    ÿrV   c                   @  ré   )rT   zNIgnoring [tools.setuptools] in pyproject.toml, did you mean [tool.setuptools]?Nrê   r    r    r    r!   rT   Ú  rì   rT   )r   r   r   r   )r#   r   r   r   r   r$   )F)r<   r   r   r   r=   r$   r   r   )TFN)
r   r   r   r$   r=   r$   r<   rA   r   rB   rË   )
r#   r   rd   re   r=   r$   r<   rA   r   r   )r=   r$   )3Ú__doc__Ú
__future__r   ÚloggingrP   Úcollections.abcr   Ú
contextlibr   Ú	functoolsr   Útypesr   Útypingr   r   r	   Ú_pathr   Úerrorsr   r   Úwarningsr   r+   r   rz   Ú_apply_pyprojecttomlr   r   r   r?   Útyping_extensionsr   rs   r   Ú	getLoggerrÌ   r4   r"   r/   r@   r>   r]   rf   rÉ   r[   ÚEnsurePackagesDiscoveredr   rV   rT   r    r    r    r!   Ú<module>   sL    


ýüTü ^-