o
    8)i*                     @  s  d Z ddlmZ ddl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 e
r>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j !dZ d5ddZ"G dd dZ#e$dZ%	 dZ&dZ'd6d!d"Z(d7d$d%Z)G d&d' d'eZ*d8d-d.Z+ej,G d/d0 d0Z-ej,G d1d2 d2Z.ej,G d3d4 d4Z/dS )9configuration    )annotationsN)Path)TYPE_CHECKING)Any)Pattern)Protocol   git)_log)_types)PyProjectData)get_args_for_pyproject)read_pyproject)read_toml_overrides)Version)_validate_version_cls)	_VersionTconfigreturnboolc                  C  sj   ddl } |  }z*|}|dusJ tdD ]}|j}|du r# W ~dS d|jjv r. W ~dS qW ~dS ~w )z9Check if the current call is from the dataclasses module.r   N   zdataclasses.pyTF)inspectcurrentframerangef_backf_codeco_filename)r   framecurrent_frame_ r"   Q/home/app/PyTorch/.pytorch/lib/python3.10/site-packages/setuptools_scm/_config.py_is_called_from_dataclasses"   s"   
r$   c                   @  s(   e Zd ZdZ	ddd	d
ZdddZdS )_GitDescribeCommandDescriptorz:Data descriptor for deprecated git_describe_command field.NobjConfiguration | Noneobjtypetype[Configuration] | Noner   _t.CMD_TYPE | Nonec                 C  s0   |d u r| S t  }|stjdtdd |jjjS NaConfiguration field 'git_describe_command' is deprecated. Use 'scm.git.describe_command' instead.   
stacklevel)r$   warningswarnDeprecationWarningscmr   describe_command)selfr&   r(   is_from_dataclassesr"   r"   r#   __get__9   s   
z%_GitDescribeCommandDescriptor.__get__ConfigurationvalueNonec                 C  s   t jdtdd ||jj_d S r+   )r0   r1   r2   r3   r   r4   )r5   r&   r9   r"   r"   r#   __set__J   s   z%_GitDescribeCommandDescriptor.__set__N)r&   r'   r(   r)   r   r*   )r&   r8   r9   r*   r   r:   )__name__
__module____qualname____doc__r7   r;   r"   r"   r"   r#   r%   6   s
    r%   z@^(?:[\w-]+-)?(?P<version>[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$zguess-next-devznode-and-dater9   str | Pattern[str] | NonePattern[str]c                 C  sP   | st }nt| }|j }|jdks|jdkr&d|vr&td|j d|S )Nr   r	   versionzExpected tag_regex 'ze' 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
ValueErrorpattern)r9   regexZgroup_namesr"   r"   r#   _check_tag_regex^   s   

rM   git.GitPreParsec                  C  s   ddl m}  | jjS )z(Get the default git pre_parse enum valuer	   r
   ) r   GitPreParseZWARN_ON_SHALLOWr
   r"   r"   r#   _get_default_git_pre_parsen   s   rQ   c                   @  s   e Zd Zd
ddZd	S )ParseFunctionroot_t.PathTr   r8   r   _t.SCMVERSION | Nonec                C  s   d S r<   r"   )r5   rS   r   r"   r"   r#   __call__v   s   zParseFunction.__call__N)rS   rT   r   r8   r   rU   )r=   r>   r?   rV   r"   r"   r"   r#   rR   u   s    rR   rS   rT   relative_to_t.PathT | Nonestrc                 C  s   t d| | |rYtj| r+tj|r+tj| |g| ks+td|  d| d tj|rHtd| d t d| tj	|| } nt d| tj	tj
|| } tj| S )	Nz%check absolute root=%s relative_to=%szabsolute root path 'z' overrides relative_to ''z8relative_to is expected to be a file, its the directory z)
assuming the parent directory was passedzdir %szfile %s)logdebugospathisabs
commonpathr0   r1   isdirjoindirnameabspath)rS   rW   r"   r"   r#   _check_absolute_root{   s*   

re   c                   @  sD   e Zd ZU dZejdd dZded< dZded	< e	dddZ
dS )GitConfigurationz"Git-specific configuration optionsc                   C     t  S r<   )rQ   r"   r"   r"   r#   <lambda>       zGitConfiguration.<lambda>default_factoryrN   	pre_parseNr*   r4   datadict[str, Any]r   c              
   C  s   |  }d|v rEt|d trEddlm} z||d |d< W n$ tyD } zdd |jD }td|d  dd| |d	}~ww | d
i |S )zLCreate GitConfiguration from configuration data, converting strings to enumsrl   r	   r
   c                 S  s   g | ]}|j qS r"   )r9   ).0optionr"   r"   r#   
<listcomp>   s    z.GitConfiguration.from_data.<locals>.<listcomp>z Invalid git pre_parse function 'z'. Valid options are: z, Nr"   )copy
isinstancerY   rO   r   rP   rJ   rb   )clsrm   git_datar   eZvalid_optionsr"   r"   r#   	from_data   s"   zGitConfiguration.from_data)rm   rn   r   rf   )r=   r>   r?   r@   dataclassesfieldrl   __annotations__r4   classmethodrw   r"   r"   r"   r#   rf      s   
 rf   c                   @  s4   e Zd ZU dZejedZded< e	ddd	Z
d
S )ScmConfigurationz"SCM-specific configuration optionsrj   rf   r   rm   rn   r   c                 C  s0   |  }|di }t|}| dd|i|S )z/Create ScmConfiguration from configuration datar   Nr"   )rr   poprf   rw   )rt   rm   scm_dataru   Z
git_configr"   r"   r#   rw      s   
zScmConfiguration.from_dataN)rm   rn   r   r|   )r=   r>   r?   r@   rx   ry   rf   r   rz   r{   rw   r"   r"   r"   r#   r|      s
   
 r|   c                   @  s@  e Zd ZU dZdZded< dZded< eZded	< e	Z
ded
< eZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< e Zded< dZded< eZded< dZded< dZded< ejd d! d"Zd#ed$< d:d(d)Ze d;d+d,Z!e"	-		d<d=d4d5Z#e"d>d8d9Z$dS )?r8   zGlobal configuration modelNrX   rW   .rT   rS   z_t.VERSION_SCHEMEversion_schemelocal_schemerB   	tag_regex
str | Noneparentdir_prefix_versionfallback_versionfallback_rootwrite_towrite_to_templateversion_fileversion_file_templatezParseFunction | Noneparsez'dataclasses.InitVar[_t.CMD_TYPE | None]git_describe_command	dist_nameztype[_VersionT]version_clsFr   search_parent_directoriesparentc                   C  rg   r<   )r|   r"   r"   r"   r#   rh      ri   zConfiguration.<lambda>rj   r|   r3   r*   r   r:   c                 C  s   t | j| _|d ur@t|tsBt }| jjjd uo| jjj|k}|r&|r&d S tj	dt
dd | jjjd ur9td|| jj_d S d S d S )Nr,   r-   r.   zCannot specify both 'git_describe_command' (deprecated) and 'scm.git.describe_command'. Please use only 'scm.git.describe_command'.)rM   r   rs   r%   r$   r3   r   r4   r0   r1   r2   rJ   )r5   r   r6   Z
same_valuer"   r"   r#   __post_init__   s*   
zConfiguration.__post_init__rY   c                 C  s   t | j| jS r<   )re   rS   rW   )r5   r"   r"   r#   absolute_root  s   zConfiguration.absolute_rootpyproject.tomlnamestr | os.PathLike[str]pyproject_dataPyProjectData | Nonekwargsr   c                 K  sL   |du r
t t|}t|||}|t|d  |d|}| j||dS )a  
                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.

        Parameters:
        - name: path to pyproject.toml
        - dist_name: name of the distribution
        - **kwargs: additional keyword arguments to pass to the Configuration constructor
        Nr   rW   )rW   rm   )_read_pyprojectr   _get_args_for_pyprojectupdater   r}   rw   )rt   r   r   r   r   argsrW   r"   r"   r#   	from_file  s   zConfiguration.from_filerm   rn   c                 C  sF   t |dd|dd}|di }t|}| d|||d|S )zt
        given configuration data
        create a config instance after validating tag regex/version class
        r   N	normalizeTr3   )rW   r   r3   r"   )r   r}   r|   rw   )rt   rW   rm   r   r~   Z
scm_configr"   r"   r#   rw   '  s   
zConfiguration.from_data)r   r*   r   r:   )r   rY   )r   NN)
r   r   r   r   r   r   r   r   r   r8   )rW   r   rm   rn   r   r8   )%r=   r>   r?   r@   rW   rz   rS   DEFAULT_VERSION_SCHEMEr   DEFAULT_LOCAL_SCHEMEr   rD   r   r   r   r   r   r   r   r   r   r%   r   r   _Versionr   r   r   rx   ry   r3   r   propertyr   r{   r   rw   r"   r"   r"   r#   r8      sD   
 

"r8   )r   r   )r9   rA   r   rB   )r   rN   )rS   rT   rW   rX   r   rY   )0r@   
__future__r   rx   r]   rE   r0   pathlibr   typingr   r   r   r   rO   r   r   r   Z_tZ_integration.pyproject_readingr   r   r   r   r   Z
_overridesr   Z_version_clsr   r   r   r   r[   getChildr$   r%   rF   rD   r   r   rM   rQ   rR   re   	dataclassrf   r|   r8   r"   r"   r"   r#   <module>   sR    



