B
    ‹dËL  ã               @   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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 eeejf Z e !e"¡Z#e e$dœdd„Z%e$e e&dœdd„Z'd0de ddœdd„Z(d1e ed dœdd„Z)e$e$ed e&dœdd„Z*d2e$ee  e&ed e$d œd!d"„Z+G d#d$„ d$ƒZ,d%d&„ Z-ee&d'œd(d)„ƒZ.G d*d+„ d+ej/ƒZ0G d,d-„ d-eƒZ1G d.d/„ d/eƒZ2dS )3ac  
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ÚUnioné   )Ú	FileErrorÚOptionError)ÚSetuptoolsWarningé   )Úexpand)Ú_PREVIOUSLY_DEFINEDÚ_WouldIgnoreField)Úapply)ÚDistribution)ÚfilepathÚreturnc          	   C   s,   ddl m} t| dƒ}| |¡S Q R X d S )Nr   )ÚtomliÚrb)Zsetuptools.externr   ÚopenÚload)r   r   Úfile© r   úl/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/setuptools/config/pyprojecttoml.pyÚ	load_file   s    r   )Úconfigr   r   c          
   C   s²   ddl m} |j d¡}t|dƒr*| ¡  y
| | ¡S  |jk
r¬ } zXd|j› }|j	 
d¡dkrzt |¡ t |j¡ d|j	› d	}t|› d
|› ƒd ‚W d 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   r   c             C   s   t |d|| ƒ}t| ||ƒS )zeApply the configuration from a ``pyproject.toml`` file into an existing
    distribution object.
    T)Úread_configurationÚ_apply)r4   r   Úignore_option_errorsr   r   r   r   Úapply_configuration:   s    r8   T)r   r4   c          
   C   sV  t j | ¡} t j | ¡s(td| ›dƒ‚t| ƒp2i }| di ¡}| di ¡}| di ¡}|rd|sh|shi S |rtt ¡  | 	¡ }|r t
|ddƒdk	r | d|j¡ n| dd	¡ ||d< ||d< y|d|id
œ}	t|	| ƒ W nX tk
r0 }
 z8t|||ƒrüi S |rt d|
jj› d|
› ¡ n‚ W dd}
~
X Y nX |rRt 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Úinclude_package_dataNzinclude-package-dataT)r#   r9   zignored error: z - )ÚosÚpathÚabspathÚisfiler   r   r'   Ú_BetaConfigurationÚemitÚcopyÚgetattrÚ
setdefaultr;   r)   Ú	ExceptionÚ_skip_bad_configr-   r.   Ú	__class__Ú__name__ÚdirnameÚexpand_configuration)r   r   r7   r4   ÚasdictZproject_tableZ
tool_tableZsetuptools_tableZorig_setuptools_tableZsubsetr2   Úroot_dirr   r   r   r5   F   s<    r5   )Úproject_cfgÚsetuptools_cfgr4   r   c             C   sf   |dks*|j jdkr.|j jdkr.|jdkr.dS |r6dS t|  ¡ ƒ}ddddh}||krbt ¡  dS dS )z8Be temporarily forgiving with invalid ``pyproject.toml``NFr+   ÚversionZpython_requireszrequires-pythonT)Úmetadatar+   rO   Zinstall_requiresÚsetÚkeysÚ_InvalidFilerA   )rM   rN   r4   Zgiven_configZpopular_subsetr   r   r   rF   ”   s    
rF   )r   rL   r7   r4   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   rL   r7   r4   r   r   r   rJ   ²   s    rJ   c               @   s`  e Zd Zd4eee eed dœdd„Zddœdd	„Zee	e
d
œdd„Zd5dd„Zdd„ Zdd„ Zdd„ Zee	e	f dœdd„Zdee	e	f dœdd„Zde	dœdd„Ze	ee	e	f dœd d!„Zde	ee	e	f d"œd#d$„Zdee	e	f dœd%d&„Zdeee	e	f  d'œd(d)„Zdee	e	f eee	ef  d*œd+d,„Zdd-œd.d/„Zdd-œd0d1„Zdd-œd2d3„ZdS )6rT   NFr   )r   rL   r7   r4   c             C   sp   || _ |pt ¡ | _| di ¡| _| j dg ¡| _| di ¡ di ¡| _| j di ¡| _|| _	|| _
tƒ | _d S )Nr#   Údynamicr9   r:   )r   r<   ÚgetcwdrL   r'   rM   rU   rN   Údynamic_cfgr7   Ú_distrQ   Ú_referenced_files)Úselfr   rL   r7   r4   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+   )Zsrc_rootr+   )Úsetuptools.distr   rL   rM   r'   rX   )rZ   r   Úattrsr   r   r   Ú_ensure_distÛ   s    z_ConfigExpander._ensure_dist)Ú	containerÚfieldÚfnc          	   C   s2   ||kr.t | jƒ ||| ƒ||< W d Q R X d S )N)Ú_ignore_errorsr7   )rZ   r_   r`   ra   r   r   r   Ú_process_fieldá   s    z_ConfigExpander._process_fieldúpackage-datac             C   s   | j  |i ¡}t |¡S )N)rN   r'   Ú_expandZcanonic_package_data)rZ   r`   Úpackage_datar   r   r   Ú_canonic_package_dataæ   s    z%_ConfigExpander._canonic_package_datac          	   C   sz   |   ¡  |  ¡  |  d¡ |  ¡ }t|| j| jƒ}|*}|j}|  ¡  |  |¡ |  	||¡ W d Q R X |j
 | j
¡ | jS )Nzexclude-package-data)Ú_expand_packagesrg   r^   Ú_EnsurePackagesDiscoveredrM   rN   Úpackage_dirÚ_expand_data_filesÚ_expand_cmdclassÚ_expand_all_dynamicrY   Úupdater   )rZ   r4   ÚctxZensure_discoveredrj   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 d Q R X d S )NÚpackagesÚfindrL   zpackage-dirZfill_package_dir)rN   r'   Ú
isinstanceÚlistÚtupleÚdictrL   rD   rb   r7   re   Zfind_packages)rZ   rp   rq   r   r   r   rh   û   s    


z _ConfigExpander._expand_packagesc             C   s$   t tj| jd}|  | jd|¡ d S )N)rL   z
data-files)r   re   Zcanonic_data_filesrL   rc   rN   )rZ   Ú
data_filesr   r   r   rk     s    z"_ConfigExpander._expand_data_files)rj   c             C   s*   | j }ttj||d}|  | jd|¡ d S )N)rj   rL   Úcmdclass)rL   r   re   rw   rc   rN   )rZ   rj   rL   rw   r   r   r   rl     s    z _ConfigExpander._expand_cmdclass)r4   rj   c          	      s‚   d‰‡ ‡‡‡fdd„ˆj D ƒ}|jˆ ˆ ˆ¡p0i ˆ ˆ ˆ¡ˆ ˆ ¡ˆ ˆ ¡ˆ ˆ ¡ˆ ˆ ¡d dd„ | ¡ D ƒ}ˆj	 |¡ d S )N)rO   Úreadmezentry-pointsÚscriptszgui-scriptsÚclassifiersÚdependencieszoptional-dependenciesc                s$   i | ]}|ˆkrˆ  ˆ |ˆ¡|“qS r   )Ú_obtain)Ú.0r`   )r4   rj   rZ   Úspecialr   r   ú
<dictcomp>  s   z7_ConfigExpander._expand_all_dynamic.<locals>.<dictcomp>)rO   rx   rz   r{   Zoptional_dependenciesc             S   s   i | ]\}}|d k	r||“qS )Nr   )r}   ÚkÚvr   r   r   r   +  s    )
rU   rn   Ú_obtain_entry_pointsÚ_obtain_versionÚ_obtain_readmeÚ_obtain_classifiersÚ_obtain_dependenciesÚ_obtain_optional_dependenciesÚitemsrM   )rZ   r4   rj   Zobtained_dynamicZupdatesr   )r4   rj   rZ   r~   r   rm     s    


z#_ConfigExpander._expand_all_dynamic)r4   r`   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   r7   r   )rZ   r4   r`   ÚpreviousÚmsgr   r   r   Ú_ensure_previously_set.  s    z&_ConfigExpander._ensure_previously_set)Ú	specifierrj   c          	   C   s†   ddl m} t| jƒf | j}d|krJ| j ||d ƒ¡ t |d |¡S d|krdt 	|d ||¡S t
d|› d|›ƒ‚W d Q R X d S )Nr   )Úalways_iterabler   Úattrz	invalid `z`: )Z setuptools.extern.more_itertoolsr   rb   r7   rL   rY   rn   re   Z
read_filesZ	read_attrr0   )rZ   rŒ   Ú	directiverj   r   rL   r   r   r   Ú_expand_directive8  s    z!_ConfigExpander._expand_directive)r4   r`   rj   c             C   s4   || j kr$|  d|› | j | |¡S |  ||¡ d S )Nztool.setuptools.dynamic.)rW   r   r‹   )rZ   r4   r`   rj   r   r   r   r|   G  s    
z_ConfigExpander._obtainc             C   s,   d| j kr(d| jkr(t |  |d|¡¡S d S )NrO   )rU   rW   re   rO   r|   )rZ   r4   rj   r   r   r   rƒ   Q  s    z_ConfigExpander._obtain_version)r4   r   c             C   sL   d| j krd S | j}d|kr<|  |di ¡|d  dd¡dœS |  |d¡ d S )Nrx   zcontent-typez
text/x-rst)Útextzcontent-type)rU   rW   r|   r'   r‹   )rZ   r4   rW   r   r   r   r„   W  s    
z_ConfigExpander._obtain_readme)r4   rj   r   c                sz   d}t ‡fdd„|D ƒƒsd S ˆ |d|¡}|d kr8d S t |¡‰dˆi‰ ttdœ‡ ‡‡fdd„}|dd	ƒ |d
dƒ ˆ S )N)zentry-pointsry   zgui-scriptsc             3   s   | ]}|ˆ j kV  qd S )N)rU   )r}   r`   )rZ   r   r   ú	<genexpr>i  s    z7_ConfigExpander._obtain_entry_points.<locals>.<genexpr>zentry-points)r`   Úgroupc                s6   |ˆkr2ˆ  |¡}| ˆjkr*tj| |d |ˆ | < d S )N)r`   Úvalue)ÚpoprU   r   rA   )r`   r“   r”   )ÚexpandedÚgroupsrZ   r   r   Ú_set_scriptss  s
    

z:_ConfigExpander._obtain_entry_points.<locals>._set_scriptsry   Úconsole_scriptszgui-scriptsÚgui_scripts)Úanyr|   re   Úentry_pointsÚstr)rZ   r4   rj   Úfieldsr‘   r˜   r   )r–   r—   rZ   r   r‚   e  s    
	

z$_ConfigExpander._obtain_entry_points)r4   c             C   s(   d| j kr$|  |di ¡}|r$| ¡ S d S )Nrz   )rU   r|   Ú
splitlines)rZ   r4   r”   r   r   r   r…     s
    
z#_ConfigExpander._obtain_classifiersc             C   s(   d| j kr$|  |di ¡}|r$t|ƒS d S )Nr{   )rU   r|   Ú_parse_requirements_list)rZ   r4   r”   r   r   r   r†   ˆ  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 )Nzoptional-dependenciesc                s*   i | ]"\}}t ˆ  d |› |i ¡ƒ|“qS )z.tool.setuptools.dynamic.optional-dependencies.)r    r   )r}   r“   r   )rZ   r   r   r   •  s   zA_ConfigExpander._obtain_optional_dependencies.<locals>.<dictcomp>)rU   rW   rr   ru   ÚAssertionErrorrˆ   r‹   )rZ   r4   Zoptional_dependencies_mapr   )rZ   r   r‡     s    



z-_ConfigExpander._obtain_optional_dependencies)NFN)rd   )rH   Ú
__module__Ú__qualname__ru   r   Ú_PathÚboolr[   r^   r   r   rc   rg   r   rh   rk   r   rl   rm   r‹   r   r|   rƒ   r   r„   r‚   r…   r†   r‡   r   r   r   r   rT   É   s*     

rT   c             C   s   dd„ |   ¡ D ƒS )Nc             S   s&   g | ]}|  ¡ r|  ¡  d ¡s|‘qS )ú#)r,   Ú
startswith)r}   Úliner   r   r   ú
<listcomp>£  s   z,_parse_requirements_list.<locals>.<listcomp>)rŸ   )r”   r   r   r   r    ¡  s    r    )r7   c          
   c   sZ   | sd V  d S y
d V  W n< t k
rT } zt d|jj› d|› ¡ W d d }~X Y nX d S )Nzignored error: z - )rE   r-   r.   rG   rH   )r7   r2   r   r   r   rb   ©  s    
rb   c                   s>   e Zd Zdeedœ‡ fdd„Z‡ fdd„Z‡ fdd„Z‡  ZS )	ri   r   )ÚdistributionrM   rN   c                s   t ƒ  |¡ || _|| _d S )N)Úsuperr[   Ú_project_cfgÚ_setuptools_cfg)rZ   rª   rM   rN   )rG   r   r   r[   ¶  s    z"_EnsurePackagesDiscovered.__init__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``.
        zpackage-dirNr+   z
py-modulesrp   )rX   r­   rD   rn   rj   Úset_defaultsZ_ignore_ext_modulesrP   r+   r¬   r'   Ú
py_modulesrp   r«   Ú	__enter__)rZ   r4   Úcfgrj   )rG   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``.
        rp   z
py-modules)r­   rD   rX   rp   r¯   r«   Ú__exit__)rZ   Úexc_typeÚ	exc_valueÚ	traceback)rG   r   r   r²   Ó  s    z"_EnsurePackagesDiscovered.__exit__)rH   r¢   r£   ru   r[   r°   r²   Ú__classcell__r   r   )rG   r   ri   µ  s   ri   c               @   s   e Zd ZdZdS )r@   zDSupport for `[tool.setuptools]` in `pyproject.toml` is still *beta*.N)rH   r¢   r£   Ú_SUMMARYr   r   r   r   r@   Ý  s   r@   c               @   s   e Zd ZdZdZdZdZdS )rS   z@The given `pyproject.toml` file is invalid and would be ignored.a©  
    ############################
    # Invalid `pyproject.toml` #
    ############################

    Any configurations in `pyproject.toml` will be ignored.
    Please note that future releases of setuptools will halt the build process
    if an invalid file is given.

    To prevent setuptools from considering `pyproject.toml` please
    DO NOT include both `[project]` or `[tool.setuptools]` tables in your file.
    )iç  é   r   zuserguide/pyproject_config.htmlN)rH   r¢   r£   r·   Z_DETAILSZ	_DUE_DATEZ	_SEE_DOCSr   r   r   r   rS   á  s   rS   )F)TFN)NFN)3Ú__doc__Úloggingr<   Ú
contextlibr   Ú	functoolsr   Útypingr   r   r   r   r   r	   r
   Úerrorsr   r   Úwarningsr   r&   r   re   Z_apply_pyprojecttomlr   r   r   r6   r\   r   r   ÚPathLiker¤   Ú	getLoggerrH   r-   ru   r   r¥   r)   r8   r5   rF   rJ   rT   r    rb   ZEnsurePackagesDiscoveredri   r@   rS   r   r   r   r   Ú<module>
   sF   $

  K
   Y(