U
    ©€lj¾=  ã                   @   sl  d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	m
Z
mZmZmZ er\ddlmZ eeedœdd„ZG d	d
„ d
ƒZeƒ ZG dd„ deƒZG dd„ dƒZeedœdd„Zeeedœdd„Zeedœdd„Zdddœdd„Zdeeddœdd„Ze	edœd d!„Zed"d#�G d$d%„ d%ƒƒZ ee d&œd'd(„Z!e
eef ee
eef  d)œd*d+„Z"d,d-l#m$Z$ dd.dgZ%dS )/z0
Versions for Python packages.

See L{Version}.
é    N)Ú	dataclass)ÚTYPE_CHECKINGÚAnyÚBinaryIOÚDictÚLiteralÚOptionalÚUnion)ÚDistribution)ÚaÚbÚreturnc                 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© )r   r   r   r   ú8/tmp/pip-unpacked-wheel-1x2dpkdc/incremental/__init__.pyÚ_cmp   s
    r   c                   @   s`   e Zd ZdZeedœdd„Zeedœdd„Zeedœdd„Z	eedœd	d
„Z
eedœdd„ZdS )Ú_Infz:
    An object that is bigger than all other objects.
    ©Úotherr   c                 C   s   |t krdS dS )zz
        @param other: Another object.
        @type other: any

        @return: 0 if other is inf, 1 otherwise.
        r   r   )Ú_inf©Úselfr   r   r   r   Ú__cmp__2   s    z_Inf.__cmp__c                 C   s   |   |¡dk S ©Nr   ©r   r   r   r   r   Ú__lt__=   s    z_Inf.__lt__c                 C   s   |   |¡dkS r   r   r   r   r   r   Ú__le__@   s    z_Inf.__le__c                 C   s   |   |¡dkS r   r   r   r   r   r   Ú__gt__C   s    z_Inf.__gt__c                 C   s   |   |¡dkS r   r   r   r   r   r   Ú__ge__F   s    z_Inf.__ge__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚobjectÚintr   Úboolr   r   r   r   r   r   r   r   r   -   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'   M   s   r'   c                
   @   s  e Zd ZdZdeeed ef eeee ee ee ee dœdd„Z	e
ee dœdd	„ƒZedœd
d„ZeZeZeZedœdd„Zedœdd„Zeedœdd„Zeedœdd„Zeedœdd„Zeedœdd„Zeedœdd„Zeedœdd„Zeedœ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.
    NÚNEXT)ÚpackageÚmajorÚminorÚmicroÚrelease_candidateÚ
prereleaseÚpostÚdevc	           	      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.é   ©Ú
stacklevelr)   z;When using NEXT, all other values except Package must be 0.N)Ú
ValueErrorÚwarningsÚwarnÚDeprecationWarningr*   r+   r,   r-   r.   r0   r1   )	r   r*   r+   r,   r-   r.   r/   r0   r1   r   r   r   Ú__init__\   s*    
ûÿzVersion.__init__©r   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.r2   r3   )r6   r7   r8   r.   ©r   r   r   r   r/   “   s    ûzVersion.prereleasec                 C   sŽ   | j dkr| j S | jdkr d}nd| j› �}| jdkr<d}nd| j› �}| jdkrXd}nd| j› �}| j ›d| jd›d| jd›|› |› |› �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Ú Úrcz.postz.devÚ.Úd)r+   r.   r0   r1   r,   r-   )r   r=   r0   r1   r   r   r   Úpublicž   s    



zVersion.publicc                 C   s’   | j d krd}nd| j ›�}| jd kr,d}nd| j›�}| jd krHd}nd| j›�}| jj› d| j›d| j›d| jd›d| jd›|› |› |› d�S )	Nr<   z, release_candidate=z, post=z, dev=ú(z, r?   ú))	r.   r0   r1   Ú	__class__r    r*   r+   r,   r-   )r   r.   r0   r1   r   r   r   Ú__repr__Á   s    


<ÿzVersion.__repr__c                 C   s   d| j › d|  ¡ › d�S )Nú[z
, version ú]©r*   Úshortr;   r   r   r   Ú__str__×   s    zVersion.__str__r   c                 C   s  t || jƒstS | j ¡ |j ¡ kr:t| j›d|j›�ƒ‚| jdkrJt}n| j}| jdkr`t}n| j}| j	dkrvd}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)   Nr   )Ú
isinstancerC   ÚNotImplementedr*   Úlowerr'   r+   r   r.   r0   r1   r   r,   r-   )r   r   r+   r.   r0   r1   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   rK   ©r   r   Úcr   r   r   Ú__eq__(  s    
zVersion.__eq__c                 C   s   |   |¡}|tkr|S |dkS r   rN   rO   r   r   r   Ú__ne__.  s    
zVersion.__ne__c                 C   s   |   |¡}|tkr|S |dk S r   rN   rO   r   r   r   r   4  s    
zVersion.__lt__c                 C   s   |   |¡}|tkr|S |dkS r   rN   rO   r   r   r   r   :  s    
zVersion.__le__c                 C   s   |   |¡}|tkr|S |dkS r   rN   rO   r   r   r   r   @  s    
zVersion.__gt__c                 C   s   |   |¡}|tkr|S |dkS r   rN   rO   r   r   r   r   F  s    
zVersion.__ge__)NNNN)r    r!   r"   r#   Ústrr	   r   r%   r   r9   Úpropertyr/   r@   ÚbaserH   ÚlocalrD   rI   r$   r   r&   rQ   rR   r   r   r   r   r   r   r   r   r(   S   s<       ÷÷7
Nr(   )Úversionr   c                 C   s   | j › d|  ¡ › �}|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.
    ú rG   )rW   Úresultr   r   r   ÚgetVersionStringM  s    rZ   )Úpathr*   r   c                 C   sd   t j | d| ¡ ¡}t j | | ¡ ¡}t j |¡r6|S t j |¡rF|S td|› d|› 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 z: I looked in z and N)Úosr[   ÚjoinrL   Úisdirr5   )r[   r*   Úsrc_dirZcurrent_dirr   r   r   Ú	_findPathX  s    ÿra   )Úversion_pathr   c              	   C   s.   i }t | ƒ�}t| ¡ |ƒ W 5 Q R X |d S )z?
    Load the current version from a ``_version.py`` file.
    Ú__version__)ÚopenÚexecÚread)rb   Úversion_infoÚfr   r   r   Ú_existing_versionp  s    
ri   Ú_Distribution)Údistr   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_inri   rb   ÚFileNotFoundErrorr@   ÚmetadatarW   )rk   ÚconfigrW   r   r   r   Ú_get_setuptools_version|  s    rr   )rk   ÚkeywordÚvaluer   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   Ú_versionr2   ú_version.pyzNo _version.py found.)Zsetuptools.commandru   Úfinalize_optionsZfind_all_modulesr]   r[   r^   Údirnameri   r@   rp   rW   rm   )rk   rs   rt   ru   Z
sp_commandÚitemrb   r   r   r   Ú_get_distutils_versionŸ  s    

r{   )rh   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)Úsysrg   ÚtomllibZtomliÚload)rh   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edœdd„ƒZdS )	Ú_IncrementalConfigz>
    Configuration loaded from a ``pyproject.toml`` file.
    rn   r*   r[   r:   c                 C   s   t j | jd¡S )z0Path of the ``_version.py`` file. May not exist.rw   )r]   r[   r^   r;   r   r   r   rb   Û  s    z_IncrementalConfig.version_pathN)	r    r!   r"   r#   r&   Ú__annotations__rS   rT   rb   r   r   r   r   rƒ   È  s   
rƒ   )Ú	toml_pathr   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 )rn   r*   r[   )rd   r�   Ú_extract_tool_incrementalÚKeyErrorr5   rJ   rS   Ú	TypeErrorÚtyperƒ   ra   r]   r[   ry   )r…   rh   ÚdataÚtool_incrementalr*   r   r   r   rl   á  s(    
ýrl   )r�   r   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])rJ   Údictr5   Ú
issupersetÚkeys)r�   rŽ   r   r   r   r‰     s    
r‰   r   )rc   rc   )&r#   r]   r~   r6   Zdataclassesr   Útypingr   r   r   r   r   r   r	   Údistutils.distr
   rj   r%   r   r   r   r‹   r'   r(   rS   rZ   ra   ri   rr   r$   r{   r�   rƒ   rl   r‰   rv   rc   Ú__all__r   r   r   r   Ú<module>   s:   $ {$  þ3$