U
    aÊ¹jG  ã                   @  s�  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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rÀddlm Z  ddl!m"Z" e #e$¡Z%dddœdd„Z&ddddœdd„Z'd6dddddœdd„Z(d7dddd d!d"œd#d$„Z)d8dd%dd dd&œd'd(„Z*G d)d*„ d*ƒZ+d+d,„ Z,edd-œd.d/„ƒZ-G d0d1„ d1ej.ƒZ/G d2d3„ d3eƒZ0G d4d5„ d5eƒZ1dS )9ac  
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)Úcontextmanager)Úpartial)ÚTracebackType)ÚTYPE_CHECKINGÚAnyÚCallableÚMappingé   )ÚStrPath)Ú	FileErrorÚInvalidConfigError)ÚSetuptoolsWarningé   )Úexpand)Ú_PREVIOUSLY_DEFINEDÚ_MissingDynamicÚapply)ÚSelf©ÚDistributionr   Údict)ÚfilepathÚreturnc              
   C  s8   ddl m} t| dƒ�}| |¡W  5 Q R £ S Q R X d S )Nr
   )ÚtomllibÚrb)Zcompat.py310r   ÚopenÚload)r   r   Úfile© r   ú^/var/www/html/bwave/python/venv/lib/python3.8/site-packages/setuptools/config/pyprojecttoml.pyÚ	load_file#   s    r!   Úbool)Úconfigr   r   c              
   C  s´   ddl m} |j d¡}t|dƒr*| ¡  z| | ¡W S  |jk
r® } zXd|j› �}|j	 
d¡dkr|t |¡ t |j¡ d|j	› d	�}t|› d
|› �ƒd ‚W 5 d }~X Y nX d S )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-   Fr   )Údistr   Úignore_option_errorsr   c                 C  s   t |d|| ƒ}t| ||ƒS )zeApply the configuration from a ``pyproject.toml`` file into an existing
    distribution object.
    T)Úread_configurationÚ_apply)r8   r   r9   r#   r   r   r    Úapply_configuration?   s    r<   TúDistribution | Nonezdict[str, Any])r   r   r9   r8   r   c           
   	   C  s2  t j | ¡} t j | ¡s(td| ›d�ƒ‚t| ƒp2i }| di ¡}| di ¡}| di ¡}|rd|sh|shi S d| di ¡kr€t ¡  d|kr”t	jdd	� |r²|j
d
k	r²| d|j
¡ n| dd¡ ||d< ||d< d|krât	jdd	� t|ƒ� |d|idœ}t|| ƒ W 5 Q R X |�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Ú
setuptoolsZtoolsÚ	distutilsz[tool.distutils])ÚsubjectNzinclude-package-dataTzext-modulesz[tool.setuptools.ext-modules])r'   r>   )ÚosÚpathÚabspathÚisfiler   r!   r+   Ú_ToolsTypoInMetadataÚemitÚ_ExperimentalConfigurationZinclude_package_dataÚ
setdefaultÚ_ignore_errorsr-   ÚdirnameÚexpand_configuration)
r   r   r9   r8   ÚasdictZproject_tableZ
tool_tableZsetuptools_tableZsubsetÚroot_dirr   r   r    r:   K   s6    
r:   úStrPath | None)r#   rN   r9   r8   r   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#   rN   r9   r8   r   r   r    rL   ”   s    rL   c                   @  s  e Zd Zd=dddddœdd	„Zd
dœdd„Zddddœdd„Zd>dd„Zdd„ Zdd„ Zdd„ Z	ddœdd„Z
d
dd œd!d"„Zd
dd#œd$d%„Zddd&œd'd(„Zd
ddd)œd*d+„Zd
dd œd,d-„Zd
d.d/œd0d1„Zd
dd2d3œd4d5„Zd
d6œd7d8„Zd
d6œd9d:„Zd
d6œd;d<„ZdS )?rP   NFr   rO   r"   r=   rQ   c                 C  sp   || _ |pt ¡ | _| di ¡| _| j dg ¡| _| di ¡ di ¡| _| j di ¡| _|| _	|| _
tƒ | _d S )Nr'   Údynamicr>   r?   )r#   rB   ÚgetcwdrN   r+   Úproject_cfgrR   Úsetuptools_cfgÚdynamic_cfgr9   Ú_distÚsetÚ_referenced_files)Úselfr#   rN   r9   r8   r   r   r    Ú__init__¬   s    z_ConfigExpander.__init__r   ©r   c                 C  s0   ddl m} | j| j dd ¡dœ}| jp.||ƒS )Nr   r   r/   )Zsrc_rootr/   )Úsetuptools.distr   rN   rT   r+   rW   )rZ   r   Úattrsr   r   r    Ú_ensure_dist½   s    z_ConfigExpander._ensure_distÚstrr   )Ú	containerÚfieldÚfnc              	   C  s2   ||kr.t | jƒ� ||| ƒ||< W 5 Q R X d S ©N)rJ   r9   )rZ   ra   rb   rc   r   r   r    Ú_process_fieldÃ   s    z_ConfigExpander._process_fieldúpackage-datac                 C  s   | j  |i ¡}t |¡S rd   )rU   r+   Ú_expandZcanonic_package_data)rZ   rb   Úpackage_datar   r   r    Ú_canonic_package_dataÈ   s    z%_ConfigExpander._canonic_package_datac              	   C  sz   |   ¡  |  ¡  |  d¡ |  ¡ }t|| j| jƒ}|�*}|j}|  ¡  |  |¡ |  	||¡ W 5 Q R X |j
 | j
¡ | jS )Nzexclude-package-data)Ú_expand_packagesri   r_   Ú_EnsurePackagesDiscoveredrT   rU   Úpackage_dirÚ_expand_data_filesÚ_expand_cmdclassÚ_expand_all_dynamicrY   Úupdater#   )rZ   r8   ÚctxZensure_discoveredrl   r   r   r    r   Ì   s    

z_ConfigExpander.expandc              	   C  s‚   | j  d¡}|d ks"t|ttfƒr&d S | d¡}t|tƒr~| j|d< | j  di ¡|d< t| j	ƒ� t
jf |Ž| j d< W 5 Q R X d S )NÚpackagesÚfindrN   úpackage-dirZfill_package_dir)rU   r+   Ú
isinstanceÚlistÚtupler   rN   rI   rJ   r9   rg   Zfind_packages)rZ   rr   rs   r   r   r    rj   Ý   s    


z _ConfigExpander._expand_packagesc                 C  s$   t tj| jd�}|  | jd|¡ d S )N)rN   z
data-files)r   rg   Zcanonic_data_filesrN   re   rU   )rZ   Ú
data_filesr   r   r    rm   é   s    z"_ConfigExpander._expand_data_fileszMapping[str, str])rl   c                 C  s*   | j }ttj||d�}|  | jd|¡ d S )N)rl   rN   Úcmdclass)rN   r   rg   ry   re   rU   )rZ   rl   rN   ry   r   r   r    rn   í   s    z _ConfigExpander._expand_cmdclass)r8   rl   c              	     s‚   d‰‡ ‡‡‡fdd„ˆj D ƒ}|jˆ ˆ ˆ¡p0i ˆ ˆ ˆ¡ˆ ˆ ¡ˆ ˆ ¡ˆ ˆ ¡ˆ ˆ ¡d� dd„ | ¡ D ƒ}ˆj	 |¡ d S )N)ÚversionÚreadmeúentry-pointsÚscriptsúgui-scriptsÚclassifiersÚdependenciesúoptional-dependenciesc                   s$   i | ]}|ˆkr|ˆ  ˆ |ˆ¡“qS r   )Ú_obtain©Ú.0rb   ©r8   rl   rZ   Úspecialr   r    Ú
<dictcomp>þ   s   þ z7_ConfigExpander._expand_all_dynamic.<locals>.<dictcomp>)rz   r{   r   r€   Zoptional_dependenciesc                 S  s   i | ]\}}|d k	r||“qS rd   r   )r„   ÚkÚvr   r   r    r‡     s       )
rR   rp   Ú_obtain_entry_pointsÚ_obtain_versionÚ_obtain_readmeÚ_obtain_classifiersÚ_obtain_dependenciesÚ_obtain_optional_dependenciesÚitemsrT   )rZ   r8   rl   Zobtained_dynamicZupdatesr   r…   r    ro   ò   s    þ
ú
z#_ConfigExpander._expand_all_dynamic)r8   rb   c                 C  s2   t | |ƒ}|d kr.| js.d|›d�}t|ƒ‚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   )rZ   r8   rb   ÚpreviousÚmsgr   r   r    Ú_ensure_previously_set  s
    
ÿz&_ConfigExpander._ensure_previously_set)Ú	specifierrl   c              
   C  sž   ddl m} t| jƒ�~ | j}d|krV| j ||d ƒ¡ t |d |¡W  5 Q R £ S d|kr|t 	|d ||¡W  5 Q R £ S t
d|› d|›�ƒ‚W 5 Q R X d S )Nr   )Úalways_iterabler   Úattrz	invalid `z`: )Zmore_itertoolsr•   rJ   r9   rN   rY   rp   rg   Z
read_filesZ	read_attrr4   )rZ   r”   Ú	directiverl   r•   rN   r   r   r    Ú_expand_directive  s    z!_ConfigExpander._expand_directive)r8   rb   rl   c                 C  s4   || j kr$|  d|› �| j | |¡S |  ||¡ d S )Nztool.setuptools.dynamic.)rV   r˜   r“   )rZ   r8   rb   rl   r   r   r    r‚   )  s    
ýz_ConfigExpander._obtainc                 C  s,   d| j kr(d| jkr(t |  |d|¡¡S d S )Nrz   )rR   rV   rg   rz   r‚   )rZ   r8   rl   r   r   r    r‹   3  s
    þz_ConfigExpander._obtain_versionzdict[str, str] | None)r8   r   c                 C  sL   d| j krd S | j}d|kr<|  |di ¡|d  dd¡dœS |  |d¡ d S )Nr{   úcontent-typez
text/x-rst)Útextr™   )rR   rV   r‚   r+   r“   )rZ   r8   rV   r   r   r    rŒ   <  s    
ýz_ConfigExpander._obtain_readmezdict[str, dict] | None)r8   rl   r   c                   sz   d}t ‡fdd„|D ƒƒsd S ˆ |d|¡}|d kr8d S t |¡‰dˆi‰ dddœ‡ ‡‡fdd„}|d	d
ƒ |ddƒ ˆ S )N)r|   r}   r~   c                 3  s   | ]}|ˆ j kV  qd S rd   )rR   rƒ   ©rZ   r   r    Ú	<genexpr>O  s     z7_ConfigExpander._obtain_entry_points.<locals>.<genexpr>r|   r`   )rb   Úgroupc                   s8   |ˆkr4ˆ  |¡}| ˆjkr,tt | |¡ƒ‚|ˆ | < d S rd   )ÚpoprR   r   r   r3   )rb   r�   Úvalue©ÚexpandedÚgroupsrZ   r   r    Ú_set_scriptsY  s
    

z:_ConfigExpander._obtain_entry_points.<locals>._set_scriptsr}   Úconsole_scriptsr~   Úgui_scripts)Úanyr‚   rg   Úentry_points)rZ   r8   rl   Úfieldsrš   r£   r   r    r    rŠ   K  s    


z$_ConfigExpander._obtain_entry_points)r8   c                 C  s(   d| j kr$|  |di ¡}|r$| ¡ S d S )Nr   )rR   r‚   Ú
splitlines©rZ   r8   rŸ   r   r   r    r�   e  s
    
z#_ConfigExpander._obtain_classifiersc                 C  s(   d| j kr$|  |di ¡}|r$t|ƒS d S )Nr€   )rR   r‚   Ú_parse_requirements_listrª   r   r   r    rŽ   l  s
    
z$_ConfigExpander._obtain_dependenciesc                   sV   dˆ j krd S dˆ jkrFˆ jd }t|tƒs0t‚‡ 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‡   y  s   ù ýÿzA_ConfigExpander._obtain_optional_dependencies.<locals>.<dictcomp>)rR   rV   ru   r   ÚAssertionErrorr�   r“   )rZ   r8   Zoptional_dependencies_mapr   r›   r    r�   s  s    



ø
z-_ConfigExpander._obtain_optional_dependencies)NFN)rf   )Ú__name__Ú
__module__Ú__qualname__r[   r_   re   ri   r   rj   rm   rn   ro   r“   r˜   r‚   r‹   rŒ   rŠ   r�   rŽ   r�   r   r   r   r    rP   «   s*      û


	rP   c                 C  s   dd„ |   ¡ D ƒS )Nc                 S  s&   g | ]}|  ¡ r|  ¡  d ¡s|‘qS )ú#)r0   Ú
startswith)r„   Úliner   r   r    Ú
<listcomp>ˆ  s    þz,_parse_requirements_list.<locals>.<listcomp>)r©   )rŸ   r   r   r    r«   ‡  s    þr«   )r9   c              
   c  sZ   | sd V  d S z
d V  W n< t k
rT } zt d|jj› d|› �¡ W 5 d }~X Y nX d S )Nzignored error: z - )Ú	Exceptionr1   r2   Ú	__class__r­   )r9   r6   r   r   r    rJ   �  s    
rJ   c                      sP   e Zd Zddddœ‡ fdd„Zddœ‡ fdd	„Zd
ddddœ‡ fdd„Z‡  ZS )rk   r   r   )ÚdistributionrT   rU   c                   s   t ƒ  |¡ || _|| _d S rd   )Úsuperr[   Ú_project_cfgÚ_setuptools_cfg)rZ   r¶   rT   rU   ©rµ   r   r    r[   œ  s    z"_EnsurePackagesDiscovered.__init__r   r\   c                   sŒ   | j | j }}| di ¡}| |jp&i ¡ ||_|j ¡  |jjdkrV| j	 
d¡|j_|jdkrl| 
d¡|_|jdkr‚| 
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``.
        rt   Nr/   ú
py-modulesrr   )rW   r¹   rI   rp   rl   Úset_defaultsZ_ignore_ext_modulesÚmetadatar/   r¸   r+   Ú
py_modulesrr   r·   Ú	__enter__)rZ   r8   Úcfgrl   rº   r   r    r¿   £  s    


z#_EnsurePackagesDiscovered.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | NoneÚNone)Úexc_typeÚ	exc_valueÚ	tracebackr   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``.
        rr   r»   )r¹   rI   rW   rr   r¾   r·   Ú__exit__)rZ   rÂ   rÃ   rÄ   rº   r   r    rÅ   ¹  s    
z"_EnsurePackagesDiscovered.__exit__)r­   r®   r¯   r[   r¿   rÅ   Ú__classcell__r   r   rº   r    rk   ›  s   rk   c                   @  s   e Zd ZdZdS )rH   z``{subject}` in `pyproject.toml` is still *experimental* and likely to change in future releases.N©r­   r®   r¯   Z_SUMMARYr   r   r   r    rH   È  s   ÿrH   c                   @  s   e Zd ZdZdS )rF   zNIgnoring [tools.setuptools] in pyproject.toml, did you mean [tool.setuptools]?NrÇ   r   r   r   r    rF   Ï  s   ÿrF   )F)TFN)NFN)2Ú__doc__Ú
__future__r   ÚloggingrB   Ú
contextlibr   Ú	functoolsr   Útypesr   Útypingr   r   r   r	   Ú_pathr   Úerrorsr   r   Úwarningsr   r*   r   rg   Z_apply_pyprojecttomlr   r   r   r;   Útyping_extensionsr   r]   r   Ú	getLoggerr­   r1   r!   r-   r<   r:   rL   rP   r«   rJ   ZEnsurePackagesDiscoveredrk   rH   rF   r   r   r   r    Ú<module>   sH   
 ý   üK   ü ]-