o
    >hy?                     @   s6  d Z ddlmZmZ ddlZddlZddlZddlmZm	Z	m
Z
mZmZmZmZ ddlmZ er@ddlZddlmZ ddlmZ dd	 ZG d
d deZe ZG dd deZG dd deZdd Zdd Zdd Z dd Z!dd Z"dd Z#eddG dd dZ$d d! Z%d"d# Z&d$d%l'm(Z( d&d' Z)g d(Z*dS ))z0
Versions for Python packages.

See L{Version}.
    )divisionabsolute_importN)TYPE_CHECKINGAnyTypeVarUnionOptionalDictBinaryIO)	dataclass)Literal)Distributionc                 C   s   | |k rdS | |krdS dS )z
    Compare two objects.

    Returns a negative number if C{a < b}, zero if they are equal, and a
    positive number if C{a > b}.
    r       )abr   r   t/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/incremental/__init__.py_cmp   s
   r   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )_Infz:
    An object that is bigger than all other objects.
    c                 C   s   |t u rdS dS )z
        @param other: Another object.
        @type other: any

        @return: 0 if other is inf, 1 otherwise.
        @rtype: C{int}
        r   r   )_infselfotherr   r   r   __cmp__7   s   z_Inf.__cmp__c                 C   s   |  |dk S Nr   r   r   r   r   r   __lt__C      z_Inf.__lt__c                 C   s   |  |dkS r   r   r   r   r   r   __le__F   r   z_Inf.__le__c                 C   s   |  |dkS r   r   r   r   r   r   __gt__I   r   z_Inf.__gt__c                 C   s   |  |dkS r   r   r   r   r   r   __ge__L   r   z_Inf.__ge__N)	__name__
__module____qualname____doc__r   r   r   r    r!   r   r   r   r   r   2   s    r   c                   @   s   e Zd ZdZdS )IncomparableVersionsz-
    Two versions could not be compared.
    N)r"   r#   r$   r%   r   r   r   r   r&   S   s    r&   c                   @   s   e Zd ZdZ				dddZedd Zdd ZeZeZ	eZ
d	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )Versionz
    An encapsulation of a version for a project, with support for outputting
    PEP-440 compatible version strings.

    This class supports the standard major.minor.micro[rcN] scheme of
    versioning.
    Nc	           	      C   s~   |r|rt d|r|s|}tjdtdd |dkr(|s$|s$|s$|s$|r(t d|| _|| _|| _|| _|| _|| _	|| _
dS )a  
        @param package: Name of the package that this is a version of.
        @type package: C{str}
        @param major: The major version number.
        @type major: C{int} or C{str} (for the "NEXT" symbol)
        @param minor: The minor version number.
        @type minor: C{int}
        @param micro: The micro version number.
        @type micro: C{int}
        @param release_candidate: The release candidate number.
        @type release_candidate: C{int}
        @param prerelease: The prerelease number. (Deprecated)
        @type prerelease: C{int}
        @param post: The postrelease number.
        @type post: C{int}
        @param dev: The development release number.
        @type dev: C{int}
        z Please only return one of these.zvPassing prerelease to incremental.Version was deprecated in Incremental 16.9.0. Please pass release_candidate instead.   
stacklevelNEXTz;When using NEXT, all other values except Package must be 0.N)
ValueErrorwarningswarnDeprecationWarningpackagemajorminormicrorelease_candidatepostdev)	r   r0   r1   r2   r3   r4   
prereleaser5   r6   r   r   r   __init__b   s*   
zVersion.__init__c                 C   s   t jdtdd | jS )NzuAccessing incremental.Version.prerelease was deprecated in Incremental 16.9.0. Use Version.release_candidate instead.r(   r)   )r-   r.   r/   r4   r   r   r   r   r7      s   zVersion.prereleasec                 C   s~   | j dkr| j S | jdu rd}nd| jf }| jdu rd}nd| jf }| jdu r,d}nd| jf }d| j | j| j|||f S )z
        Return a PEP440-compatible "public" representation of this L{Version}.

        Examples:

          - 14.4.0
          - 1.2.3rc1
          - 14.2.1rc1dev9
          - 16.04.0dev0
        r+   N zrc%sz.post%sz.dev%sz%r.%d.%d%s%s%s)r1   r4   r5   r6   r2   r3   )r   rcr5   r6   r   r   r   public   s   



zVersion.publicc              	   C   sx   | j d u rd}nd| j f }| jd u rd}nd| jf }| jd u r$d}nd| jf }d| jj| j| j| j| j|||f S )Nr:   z, release_candidate=%rz	, post=%rz, dev=%rz%s(%r, %r, %d, %d%s%s%s))	r4   r5   r6   	__class__r"   r0   r1   r2   r3   )r   r4   r5   r6   r   r   r   __repr__   s&   


zVersion.__repr__c                 C   s   d| j |  f S )Nz[%s, version %s]r0   shortr9   r   r   r   __str__   s   zVersion.__str__c                 C   s  t || jstS | j |j krtd| j|jf | jdkr$t}n| j}| jdu r/t}n| j}| j	du r:d}n| j	}| j
du rEt}n| j
}|jdkrPt}n|j}|jdu r[t}n|j}|j	du rfd}n|j	}|j
du rqt}	n|j
}	t|| j| j|||f||j|j|||	f}
|
S )aw  
        Compare two versions, considering major versions, minor versions, micro
        versions, then release candidates, then postreleases, then dev
        releases. Package names are case insensitive.

        A version with a release candidate is always less than a version
        without a release candidate. If both versions have release candidates,
        they will be included in the comparison.

        Likewise, a version with a dev release is always less than a version
        without a dev release. If both versions have dev releases, they will
        be included in the comparison.

        @param other: Another version.
        @type other: L{Version}

        @return: NotImplemented when the other object is not a Version, or one
            of -1, 0, or 1.

        @raise IncomparableVersions: when the package names of the versions
            differ.
        z%r != %rr+   Nr   )
isinstancer=   NotImplementedr0   lowerr&   r1   r   r4   r5   r6   r   r2   r3   )r   r   r1   r4   r5   r6   
othermajorotherrc	otherpostotherdevxr   r   r   r      sB   







zVersion.__cmp__c                 C   s   |  |}|tu r|S |dkS r   r   rC   r   r   cr   r   r   __eq__/     
zVersion.__eq__c                 C   s   |  |}|tu r|S |dkS r   rJ   rK   r   r   r   __ne__5  rN   zVersion.__ne__c                 C   s   |  |}|tu r|S |dk S r   rJ   rK   r   r   r   r   ;  rN   zVersion.__lt__c                 C   s   |  |}|tu r|S |dkS r   rJ   rK   r   r   r   r   A  rN   zVersion.__le__c                 C   s   |  |}|tu r|S |dkS r   rJ   rK   r   r   r   r    G  rN   zVersion.__gt__c                 C   s   |  |}|tu r|S |dkS r   rJ   rK   r   r   r   r!   M  rN   zVersion.__ge__)NNNN)r"   r#   r$   r%   r8   propertyr7   r<   baser@   localr>   rA   r   rM   rO   r   r   r    r!   r   r   r   r   r'   Y   s,    
7

Jr'   c                 C   s   d| j |  f }|S )z
    Get a friendly string for the given version object.

    @param version: A L{Version} object.
    @return: A string containing the package and short version number.
    z%s %sr?   )versionresultr   r   r   getVersionStringT  s   rU   c                 C   sX   t j| d| }t j| | }t j|r|S t j|r#|S td|||)z
    Determine the package root directory.

    The result is one of:

        - src/{package}
        - {package}

    Where {package} is downcased.
    srcz=Can't find the directory of project {}: I looked in {} and {})ospathjoinrD   isdirr,   format)rX   r0   src_dircurrent_dirr   r   r   	_findPath_  s   r^   c                 C   sJ   i }t | d}t| | W d   |d S 1 sw   Y  |d S )z?
    Load the current version from a ``_version.py`` file.
    rN__version__)openexecread)version_pathversion_infofr   r   r   _existing_versiony  s   
rg   c                 C   s`   zt d}W n
 ty   Y dS w |jsdS zt|j}W n
 ty'   Y dS w | | j_dS )a  
    Setuptools integration: load the version from the working directory

    This function is registered as a setuptools.finalize_distribution_options
    entry point [1]. Consequently, it is called in all sorts of weird
    contexts. In setuptools, silent failure is the law.

    [1]: https://setuptools.pypa.io/en/latest/userguide/extension.html#customizing-distribution-options

    @param dist:
        A (possibly) empty C{setuptools.Distribution} instance to mutate.
        There may be some metadata here if a `setup.py` called `setup()`,
        but this hook is always called before setuptools loads anything
        from ``pyproject.toml``.
    z./pyproject.tomlN)	_load_pyproject_toml	Exceptionopt_inrg   rd   FileNotFoundErrorr<   metadatarS   )distconfigrS   r   r   r   _get_setuptools_version  s   ro   c                 C   sx   |sdS ddl m} || }|  | D ] }|d dkr7tjtj|d d}t|	 | j
_ dS qtd)	a  
    Distutils integration: get the version from the package listed in the Distribution.

    This function is invoked when a C{setup.py} calls C{setup(use_incremental=True)}.

    @see: https://setuptools.pypa.io/en/latest/userguide/extension.html#adding-arguments
    Nr   )build_pyr   _versionr(   _version.pyzNo _version.py found.)setuptools.commandrp   finalize_optionsfind_all_modulesrW   rX   rY   dirnamerg   r<   rl   rS   ri   )rm   keywordvaluerp   
sp_commanditemrd   r   r   r   _get_distutils_version  s   
r{   c                 C   s&   t jdkr
ddl}nddl}|| S )z*
    Read the content of a TOML file.
    )      r   N)sysre   tomllibtomliload)rf   r   r   r   r   
_load_toml  s   


r   T)frozenc                   @   s<   e Zd ZU dZeed< 	 eed< 	 eed< 	 edd ZdS )_IncrementalConfigz>
    Configuration loaded from a ``pyproject.toml`` file.
    rj   r0   rX   c                 C   s   t j| jdS )z0Path of the ``_version.py`` file. May not exist.rr   )rW   rX   rY   r9   r   r   r   rd     s   z_IncrementalConfig.version_pathN)	r"   r#   r$   r%   bool__annotations__strrP   rd   r   r   r   r   r     s   
 r   c                 C   s   t | d}t|}W d   n1 sw   Y  t|}d}|dur+d|v r+|d }|du rAz|d d }W n	 ty@   Y nw |du rItdt|tsWtdt	|t
|du|ttj| |dS )a  
    Load Incremental configuration from a ``pyproject.toml``

    If the [tool.incremental] section is empty we take the project name
    from the [project] section. Otherwise we require only a C{name} key
    specifying the project name. Other keys are forbidden to allow future
    extension and catch typos.

    @param toml_path:
        Path to the ``pyproject.toml`` to load.
    rbNnameprojectzIncremental failed to extract the project name from pyproject.toml. Specify it like:

    [project]
    name = "Foo"

Or:

    [tool.incremental]
    name = "Foo"

z/The project name must be a string, but found {})rj   r0   rX   )ra   r   _extract_tool_incrementalKeyErrorr,   rB   r   	TypeErrorr[   typer   r^   rW   rX   rv   )	toml_pathrf   datatool_incrementalr0   r   r   r   rh     s0   

rh   c                 C   sl   d| vrd S t | d tstdd| d vrd S | d d }t |ts(tddh| s4td|S )Ntoolz[tool] must be a tableincrementalz"[tool.incremental] must be a tabler   z'Unexpected key(s) in [tool.incremental])rB   dictr,   
issupersetkeys)r   r   r   r   r   r     s   
r   r   )r`   c                   C   s   t  S )N)r`   r<   r   r   r   r   _setuptools_version1  s   r   )r`   r'   rU   )+r%   
__future__r   r   rW   r~   r-   typingr   r   r   r   r   r	   r
   dataclassesr   iotyping_extensionsr   distutils.distr   _Distributionr   objectr   r   r   r&   r'   rU   r^   rg   ro   r{   r   r   rh   r   rq   r`   r   __all__r   r   r   r   <module>   s<   $ |#5