o
    bE                     @  s  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 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 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 erjddlmZ ddlmZ dZdZdZd,ddZ d-d!d"Z!eeef Z"d.d(d)Z#G d*d+ d+Z$dS )/z configuration     )annotationsN)Any)Callable)cast)Pattern)Type)TYPE_CHECKING)Union   )get_args_for_pyproject)read_pyproject)NonNormalizedVersion)Version)trace)_types)
ScmVersionz@^(?:[\w-]+-)?(?P<version>[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$zguess-next-devznode-and-datevaluestr | Pattern[str] | NonereturnPattern[str]c                 C  sF   | st } t| }|j }|jdks|jdkr!d|vr!td |S )Nr   r
   versionzvExpected tag_regex to contain a single match group or a group named 'version' to identify the version part of any tag.)DEFAULT_TAG_REGEXrecompile
groupindexkeysgroupswarningswarn)r   regexgroup_names r!   9usr/lib/python3.10/site-packages/setuptools_scm/config.py_check_tag_regex!   s   

r#   root_t.PathTrelative_to_t.PathT | Nonestrc                 C  s   t dtt  |rTtj| r)tj|r)tj| |g| ks)td| |f  tj	|rDtd|f  t d| tj
|| } nt d| tj
tj|| } tj| S )Nzabs rootz2absolute root path '%s' overrides relative_to '%s'zcrelative_to is expected to be a file, its the directory %r
assuming the parent directory was passeddirfile)r   reprlocalsospathisabs
commonpathr   r   isdirjoindirnameabspath)r$   r&   r!   r!   r"   _check_absolute_root0   s.   



r5   version_clstype[_VersionT] | str | None	normalizebooltype[_VersionT]c                 C  s   |s| d ur
t dtS | d u rtS t| tr?zdd l}| dd\}}||}tt	t
 t||W S    t d|  d| S )NzHProviding a custom `version_cls` is not permitted when `normalize=False`r   .r
   zUnable to import version_cls='')
ValueErrorr   r   
isinstancer(   	importlibrsplitimport_moduler   r   	_VersionTgetattr)r6   r8   r?   pkgcls_nameversion_cls_hostr!   r!   r"   _validate_version_clsM   s"   

rG   c                   @  s   e Zd ZU dZded< ded< ded< ded	< d
deed
d
ed
d
dd
d
d
d
ddfd@d$d%Ze	dAd'd(Z
e
jdBd+d(Z
e	dAd,d-Ze	dCd.d/ZejdBd0d/Ze	dAd1d2ZejdBd3d2Ze	dDd5d6ZejdEd7d6Ze	8	
	
dFdGd>d?Zd
S )HConfigurationzGlobal configuration modelr'   parentr(   _root
str | None_relative_tor:   r6   Nr;   TFr&   r$   r%   version_scheme(str | Callable[[ScmVersion], str | None]local_schemewrite_towrite_to_template	tag_regexstr | Pattern[str]parentdir_prefix_versionfallback_versionfallback_rootparse
Any | Nonegit_describe_command_t.CMD_TYPE | None	dist_name#type[_VersionT] | type | str | Noner8   r9   search_parent_directoriesc                 C  s   |d u rd nt || _d| _t || _|| _|| _|| _|| _|| _	|	| _
|
| _|| _|| _|| _|| _|| _d | _t||| _d S )Nr;   )r-   fspathrL   rJ   r$   rM   rO   rP   rQ   rT   rU   rV   rW   rR   rY   r[   r]   rI   rG   r6   )selfr&   r$   rM   rO   rP   rQ   rR   rT   rU   rV   rW   rY   r[   r6   r8   r]   r!   r!   r"   __init__r   s"   zConfiguration.__init__r   c                 C     | j S N)_fallback_rootr_   r!   r!   r"   rV         zConfiguration.fallback_rootr   Nonec                 C  s   t j|| _d S rb   )r-   r.   r4   rc   r_   r   r!   r!   r"   rV      s   c                 C  ra   rb   )_absolute_rootrd   r!   r!   r"   absolute_root   re   zConfiguration.absolute_rootc                 C  ra   rb   )rL   rd   r!   r!   r"   r&      re   zConfiguration.relative_toc                 C  s<   t | j|| _t|| _tdt| j tdt| d S Nr$   r&   )r5   rJ   rh   r-   r^   rL   r   r+   rg   r!   r!   r"   r&      s   c                 C  ra   rb   )rJ   rd   r!   r!   r"   r$      re   zConfiguration.rootc                 C  s>   t || j| _t|| _tdt| j tdt| j d S rj   )r5   rL   rh   r-   r^   rJ   r   r+   rg   r!   r!   r"   r$      s   r   c                 C  ra   rb   )
_tag_regexrd   r!   r!   r"   rR      re   zConfiguration.tag_regexc                 C  s   t || _d S rb   )r#   rk   rg   r!   r!   r"   rR      s   pyproject.tomlname
_load_toml&Callable[[str], dict[str, Any]] | Nonekwargsr   c                 K  s*   t ||d}t|||}| dd|i|S )z
        Read Configuration from pyproject.toml (or similar).
        Raises exceptions when file is not found or toml is
        not installed or the file has invalid format or does
        not contain the [tool.setuptools_scm] section.
        )rn   r&   Nr!   )_read_pyproject_get_args_for_pyproject)clsrm   r[   rn   rp   pyproject_dataargsr!   r!   r"   	from_file   s   zConfiguration.from_file) r&   r'   r$   r%   rM   rN   rO   rN   rP   r'   rQ   rK   rR   rS   rT   rK   rU   rK   rV   r%   rW   rX   rY   rZ   r[   rK   r6   r\   r8   r9   r]   r9   )r   r(   )r   r%   r   rf   )r   rK   )r   r   )r   rS   r   rf   )rl   NN)
rm   r(   r[   rK   rn   ro   rp   r   r   rH   )__name__
__module____qualname____doc____annotations__DEFAULT_VERSION_SCHEMEDEFAULT_LOCAL_SCHEMEr   r`   propertyrV   setterri   r&   r$   rR   classmethodrv   r!   r!   r!   r"   rH   j   s\   
 *rH   )r   r   r   r   )r$   r%   r&   r'   r   r(   )r6   r7   r8   r9   r   r:   )%rz   
__future__r   r-   r   r   typingr   r   r   r   r   r   r	   Z_integration.pyproject_readingr   rr   r   rq   _version_clsr   r   utilsr    r   Z_tsetuptools_scm.versionr   r   r|   r}   r#   r5   rB   rG   rH   r!   r!   r!   r"   <module>   s8    


