o
    @=`&                     @   s   d Z ddlmZmZ ddlZddlZejdk rdZndZzeZ	W n e
y-   dd Z	Y nw d	d
 ZeG dd deZe ZG dd deZeG dd deZdd Zdd ZddlmZ g dZdS )z0
Versions for Python packages.

See L{Version}.
    )divisionabsolute_importN)   r   FTc                 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   6/usr/lib/python3/dist-packages/incremental/__init__.py_cmp   s
   r   c                 C   s`   t s| S dd }dd }dd }dd }d	d
 }dd }|| _|| _|| _|| _|| _|| _| S )z
    Class decorator that ensures support for the special C{__cmp__} method.

    On Python 2 this does nothing.

    On Python 3, C{__eq__}, C{__lt__}, etc. methods are added to the class,
    relying on C{__cmp__} to implement their comparisons.
    c                 S   s   |  |}|tu r|S |dkS Nr   __cmp__NotImplementedselfothercr   r   r
   __eq__8      
z_comparable.<locals>.__eq__c                 S   s   |  |}|tu r|S |dkS r   r   r   r   r   r
   __ne__>   r   z_comparable.<locals>.__ne__c                 S   s   |  |}|tu r|S |dk S r   r   r   r   r   r
   __lt__D   r   z_comparable.<locals>.__lt__c                 S   s   |  |}|tu r|S |dkS r   r   r   r   r   r
   __le__J   r   z_comparable.<locals>.__le__c                 S   s   |  |}|tu r|S |dkS r   r   r   r   r   r
   __gt__P   r   z_comparable.<locals>.__gt__c                 S   s   |  |}|tu r|S |dkS r   r   r   r   r   r
   __ge__V   r   z_comparable.<locals>.__ge__)_PY3r   r   r   r   r   r   )klassr   r   r   r   r   r   r   r   r
   _comparable+   s   
r   c                   @   s   e Zd Z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   )r   )r   r   r   r   r
   r   p   s   z_inf.__cmp__N)__name__
__module____qualname____doc__r   r   r   r   r
   r   j   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    r#   c                   @   sZ   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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   r-   r.   r/   r0   r1   
prereleaser2   r3   r   r   r
   __init__   s*   

zVersion.__init__c                 C   s   t jdtddf | jS )NzuAccessing incremental.Version.prerelease was deprecated in Incremental 16.9.0. Use Version.release_candidate instead.r%   r&   )r*   r+   r,   r1   r   r   r   r
   r4      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)r.   r1   r2   r3   r/   r0   )r   rcr2   r3   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 )Nr7   z, release_candidate=%rz	, post=%rz, dev=%rz%s(%r, %r, %d, %d%s%s%s))	r1   r2   r3   	__class__r   r-   r.   r/   r0   )r   r1   r2   r3   r   r   r
   __repr__   s&   


zVersion.__repr__c                 C   s   d| j |  f S )Nz[%s, version %s]r-   shortr6   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:   r   r-   lowerr#   r.   r   r1   r2   r3   r   r/   r0   )r   r   r.   r1   r2   r3   
othermajorotherrc	otherpostotherdevxr   r   r
   r     sB   







zVersion.__cmp__)NNNN)r   r    r!   r"   r5   propertyr4   r9   baser=   localr;   r>   r   r   r   r   r
   r$      s     
9
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
   getVersionStringc  s   rK   c              	   C   s   |sdS ddl m} || }|  | D ]2}|d dkrIi }t|d }t| | W d   n1 s9w   Y  |d  | j_	 dS qt
d)	zF
    Get the version from the package listed in the Distribution.
    Nr   )build_pyr   _versionr%   __version__zNo _version.py found.)distutils.commandrL   finalize_optionsfind_all_modulesopenexecreadr9   metadatarI   	Exception)distkeywordvaluerL   
sp_commanditemversion_filefr   r   r
   _get_versionn  s   
	r^   r   )rN   )rN   r$   rK   )r"   
__future__r   r   sysr*   version_infor   cmpr   	NameErrorr   objectr   	TypeErrorr#   r$   rK   r^   rM   rN   __all__r   r   r   r
   <module>   s0   
? ]