U
     T‚gy?  ã                   @   s8  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)d(ddg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 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   é   N© )ÚaÚbr   r   ú8/tmp/pip-unpacked-wheel-qa1ew7ja/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 k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   s    z_Inf.__lt__c                 C   s   |   |¡dkS r   r   r   r   r   r   Ú__le__F   s    z_Inf.__le__c                 C   s   |   |¡dkS r   r   r   r   r   r   Ú__gt__I   s    z_Inf.__gt__c                 C   s   |   |¡dkS r   r   r   r   r   r   Ú__ge__L   s    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ƒ‚n|r.|s.|}tjdtdd� |dkrR|sJ|sJ|sJ|sJ|rRt 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   r/   r0   r1   r2   r3   Ú
prereleaser4   r5   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.   r3   ©r   r   r   r   r6   ™   s    ûzVersion.prereleasec                 C   s~   | j dkr| j S | jdkr d}nd| jf }| jdkr<d}nd| jf }| jdkrXd}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)r0   r3   r4   r5   r1   r2   )r   Úrcr4   r5   r   r   r   Úpublic¤   s    



zVersion.publicc              	   C   sx   | j d krd}nd| j f }| jd kr,d}nd| jf }| jd krHd}nd| jf }d| jj| j| j| j| j|||f S )Nr9   z, release_candidate=%rz	, post=%rz, dev=%rz%s(%r, %r, %d, %d%s%s%s))	r3   r4   r5   Ú	__class__r!   r/   r0   r1   r2   )r   r3   r4   r5   r   r   r   Ú__repr__Ç   s&    


øzVersion.__repr__c                 C   s   d| j |  ¡ f S )Nz[%s, version %s]©r/   Úshortr8   r   r   r   Ú__str__â   s    zVersion.__str__c                 C   s  t || jƒstS | j ¡ |j ¡ kr8td| j|jf ƒ‚| jdkrHt}n| j}| jdkr^t}n| j}| j	dkrtd}n| j	}| j
dkrŠt}n| j
}|jdkr t}n|j}|jdkr¶t}n|j}|j	dkrÌd}n|j	}|j
dkrât}	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<   ÚNotImplementedr/   Úlowerr%   r0   r   r3   r4   r5   r   r1   r2   )r   r   r0   r3   r4   r5   Z
othermajorZotherrcZ	otherpostZotherdevÚxr   r   r   r   å   sB    







þzVersion.__cmp__c                 C   s   |   |¡}|tkr|S |dkS r   ©r   rB   ©r   r   Úcr   r   r   Ú__eq__/  s    
zVersion.__eq__c                 C   s   |   |¡}|tkr|S |dkS r   rE   rF   r   r   r   Ú__ne__5  s    
zVersion.__ne__c                 C   s   |   |¡}|tkr|S |dk S r   rE   rF   r   r   r   r   ;  s    
zVersion.__lt__c                 C   s   |   |¡}|tkr|S |dkS r   rE   rF   r   r   r   r   A  s    
zVersion.__le__c                 C   s   |   |¡}|tkr|S |dkS r   rE   rF   r   r   r   r   G  s    
zVersion.__gt__c                 C   s   |   |¡}|tkr|S |dkS r   rE   rF   r   r   r   r    M  s    
zVersion.__ge__)NNNN)r!   r"   r#   r$   r7   Úpropertyr6   r;   Úbaser?   Úlocalr=   r@   r   rH   rI   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    rO   c                 C   s\   t j | d| ¡ ¡}t j | | ¡ ¡}t j |¡r6|S t j |¡rF|S td |||¡ƒ‚dS )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 {}N)ÚosÚpathÚjoinrC   Úisdirr+   Úformat)rR   r/   Úsrc_dirZcurrent_dirr   r   r   Ú	_findPath_  s      ÿÿrW   c              	   C   s0   i }t | dƒ�}t| ¡ |ƒ W 5 Q R X |d S )z?
    Load the current version from a ``_version.py`` file.
    ÚrÚ__version__)ÚopenÚexecÚread)Úversion_pathÚversion_infoÚfr   r   r   Ú_existing_versiony  s    r`   c                 C   sd   zt dƒ}W n tk
r"   Y dS X |js.dS zt|jƒ}W n tk
rR   Y dS X | ¡ | 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_inr`   r]   ÚFileNotFoundErrorr;   ÚmetadatarM   )ÚdistÚconfigrM   r   r   r   Ú_get_setuptools_version…  s    rh   c                 C   s|   |sdS ddl m} | | ¡}| ¡  | ¡ D ]@}|d dkr.tj tj |d ¡d¡}t|ƒ 	¡ | j
_ dS q.tdƒ‚dS )	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.)Zsetuptools.commandri   Úfinalize_optionsZfind_all_modulesrQ   rR   rS   Údirnamer`   r;   re   rM   rb   )rf   ÚkeywordÚvalueri   Z
sp_commandÚitemr]   r   r   r   Ú_get_distutils_version¨  s    
rq   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)Úsysr^   ÚtomllibZtomliÚload)r_   ru   r   r   r   Ú
_load_tomlÁ  s    

rw   T)Úfrozenc                   @   s6   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.
    rc   r/   rR   c                 C   s   t j | jd¡S )z0Path of the ``_version.py`` file. May not exist.rk   )rQ   rR   rS   r8   r   r   r   r]   â  s    z_IncrementalConfig.version_pathN)	r!   r"   r#   r$   ÚboolÚ__annotations__ÚstrrJ   r]   r   r   r   r   ry   Ï  s   
ry   c              	   C   s¼   t | dƒ�}t|ƒ}W 5 Q R X t|ƒ}d}|dk	rBd|krB|d }|dkrpz|d d }W n tk
rn   Y nX |dkr€tdƒ‚t|tƒsœtd t	|ƒ¡ƒ‚t
|dk	|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Úprojectz¤Incremental 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 {})rc   r/   rR   )rZ   rw   Ú_extract_tool_incrementalÚKeyErrorr+   rA   r|   Ú	TypeErrorrU   Útypery   rW   rQ   rR   rm   )Z	toml_pathr_   ÚdataÚtool_incrementalr/   r   r   r   ra   è  s,    
ÿýra   c                 C   sl   d| krd S t | d tƒs"tdƒ‚d| d kr2d S | d d }t |tƒsPtdƒ‚dh | ¡ ¡shtdƒ‚|S )NZtoolz[tool] must be a tableÚincrementalz"[tool.incremental] must be a tabler~   z'Unexpected key(s) in [tool.incremental])rA   Údictr+   Ú
issupersetÚkeys)r„   r…   r   r   r   r€     s    
r€   r   )rY   c                   C   s   t  ¡ S )N)rY   r;   r   r   r   r   Ú_setuptools_version1  s    rŠ   rY   )+r$   Ú
__future__r   r   rQ   rt   r,   Útypingr   r   r   r   r   r	   r
   Zdataclassesr   ÚioZtyping_extensionsr   Údistutils.distr   Z_Distributionr   Úobjectr   r   r‚   r%   r&   rO   rW   r`   rh   rq   rw   ry   ra   r€   rj   rY   rŠ   Ú__all__r   r   r   r   Ú<module>   s:   $ |#5