
    Vhy?                     P   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 Z G d	 d
e      Z e       Z G d de      Z G d de      Zd Zd Zd Z d Z!d Z"d Z# ed       G d d             Z$d Z%d Z&ddl'm(Z( d Z)g dZ*y)z0
Versions for Python packages.

See L{Version}.
    )divisionabsolute_importN)TYPE_CHECKINGAnyTypeVarUnionOptionalDictBinaryIO)	dataclass)Literal)Distributionc                     | |k  ry| |k(  ryy)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bs     D/home/dcms/DCMS/lib/python3.12/site-packages/incremental/__init__.py_cmpr      s     	1u	
a    c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)_Infz:
    An object that is bigger than all other objects.
    c                     |t         u ryy)z
        @param other: Another object.
        @type other: any

        @return: 0 if other is inf, 1 otherwise.
        @rtype: C{int}
        r   r   )_infselfothers     r   __cmp__z_Inf.__cmp__7   s     D=r   c                 *    | j                  |      dk  S Nr   r   r   s     r   __lt__z_Inf.__lt__C       ||E"Q&&r   c                 *    | j                  |      dk  S r!   r"   r   s     r   __le__z_Inf.__le__F       ||E"a''r   c                 *    | j                  |      dkD  S r!   r"   r   s     r   __gt__z_Inf.__gt__I   r$   r   c                 *    | j                  |      dk\  S r!   r"   r   s     r   __ge__z_Inf.__ge__L   r'   r   N)	__name__
__module____qualname____doc__r   r#   r&   r)   r+   r   r   r   r   r   2   s     
'('(r   r   c                       e Zd ZdZy)IncomparableVersionsz-
    Two versions could not be compared.
    N)r,   r-   r.   r/   r   r   r   r1   r1   S   s    r   r1   c                   x    e Zd ZdZ	 	 	 	 ddZed        Zd ZeZeZ	eZ
d Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zy)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	                     |r|rt        d      |r |s|}t        j                  dt        d       |dk(  r|s|s|s|s|rt        d      || _        || _        || _        || _        || _        || _	        || _
        y)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?   r@   rA   
prereleaserB   rC   s	            r   __init__zVersion.__init__b   s    : ?@@ 1 *MM- # F?!2dc Q  


!2	r   c                 R    t        j                  dt        d       | j                  S )NzuAccessing incremental.Version.prerelease was deprecated in Incremental 16.9.0. Use Version.release_candidate instead.r5   r6   )r:   r;   r<   rA   r   s    r   rD   zVersion.prerelease   s)    1 	
 %%%r   c                 >   | j                   dk(  r| j                   S | j                  d}nd| j                  }| j                  d}nd| j                  }| j                  d}nd| j                  }d| j                   | j                  | j
                  |||fz  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
        r8    rcz.postz.devz%r.%d.%d%s%s%s)r>   rA   rB   rC   r?   r@   )r   rJ   rB   rC   s       r   publiczVersion.public   s     ::::!!)B *  113B99D  !%		+D88C  #hh(C4::tzz4::r4QT"UUUr   c           	      H   | j                   d}nd| j                   }| j                  d}nd| j                  }| j                  d}nd| j                  }d| j                  j                  | j
                  | j                  | j                  | j                  |||fz  S )NrI   z, release_candidate=z, post=z, dev=z%s(%r, %r, %d, %d%s%s%s))	rA   rB   rC   	__class__r,   r=   r>   r?   r@   )r   rA   rB   rC   s       r   __repr__zVersion.__repr__   s    !!) " * =A<R<R T99D  #'))-D88C  !%*C)NN##LLJJJJJJ	-
 	
 		
r   c                 D    d| j                   d| j                         dS )N[z
, version ]r=   shortrG   s    r   __str__zVersion.__str__   s    %)\\4::<@@r   c           	      \   t        || j                        st        S | j                  j	                         |j                  j	                         k7  r$t        | j                  d|j                        | j                  dk(  rt        }n| j                  }| j                  t        }n| j                  }| j                  d}n| j                  }| j                  t        }n| j                  }|j                  dk(  rt        }n|j                  }|j                  t        }n|j                  }|j                  d}n|j                  }|j                  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 != r8   r   )
isinstancerM   NotImplementedr=   lowerr1   r>   r   rA   rB   rC   r   r?   r@   )r   r   r>   rA   rB   rC   
othermajorotherrc	otherpostotherdevxs              r   r   zVersion.__cmp__   sb   . %0!!<<5==#6#6#88&T\\5=='QRR::EJJE!!) $ $ 6 699D99D88C((C;;& JJ""*G--G::I

I99HyyHDJJ

,=tSIekk7IxP
 r   c                 B    | j                  |      }|t        u r|S |dk(  S r!   r   rW   r   r   cs      r   __eq__zVersion.__eq__/  &    LLHAvr   c                 B    | j                  |      }|t        u r|S |dk7  S r!   r_   r`   s      r   __ne__zVersion.__ne__5  rc   r   c                 B    | j                  |      }|t        u r|S |dk  S r!   r_   r`   s      r   r#   zVersion.__lt__;  &    LLH1ur   c                 B    | j                  |      }|t        u r|S |dk  S r!   r_   r`   s      r   r&   zVersion.__le__A  rc   r   c                 B    | j                  |      }|t        u r|S |dkD  S r!   r_   r`   s      r   r)   zVersion.__gt__G  rg   r   c                 B    | j                  |      }|t        u r|S |dk\  S r!   r_   r`   s      r   r+   zVersion.__ge__M  rc   r   )NNNN)r,   r-   r.   r/   rE   propertyrD   rK   baserS   localrN   rT   r   rb   re   r#   r&   r)   r+   r   r   r   r3   r3   Y   sv     5n & &V> DEE
6AHTr   r3   c                 D    | j                   d| j                         }|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.
     rR   )versionresults     r   getVersionStringrr   T  s      9FMr   c                 x   t         j                  j                  | d|j                               }t         j                  j                  | |j                               }t         j                  j	                  |      r|S t         j                  j	                  |      r|S t        dj                  |||            )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joinrX   isdirr9   format)rv   r=   src_dircurrent_dirs       r   	_findPathr|   _  s     ggll48G'',,tW]]_5K	ww}}W	{	#KRR+
 	
r   c                     i }t        | d      5 }t        |j                         |       ddd       |d   S # 1 sw Y   |d   S xY w)z?
    Load the current version from a ``_version.py`` file.
    rN__version__)openexecread)version_pathversion_infofs      r   _existing_versionr   y  sO     L	lC	  %AQVVX|$% &&% &&s	   7Ac                     	 t        d      }|j                  sy	 t        |j                        }|j                         | j                  _        y# t        $ r Y yw xY w# t
        $ r Y yw xY w)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   FileNotFoundErrorrK   metadatarp   )distconfigrp   s      r   _get_setuptools_versionr     sq      &&89 ==#F$7$78 $NN,DMM    s"   A A 	AA	A+*A+c                 z   |syddl m} |j                  |       }|j                          |j                         D ]t  }|d   dk(  st        j
                  j                  t        j
                  j                  |d         d      }t        |      j                         | j                  _         y 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   _versionr5   _version.pyzNo _version.py found.)setuptools.commandr   finalize_optionsfind_all_modulesru   rv   rw   dirnamer   rK   r   rp   r   )r   keywordvaluer   
sp_commanditemr   s          r   _get_distutils_versionr     s     +""4(J!++- 7j 77<<Q(@-PL$5l$C$J$J$LDMM!	 +
,,r   c                 \    t         j                  dkD  rddl}nddl}|j	                  |       S )z*
    Read the content of a TOML file.
    )      r   N)sysr   tomllibtomliload)r   r   s     r   
_load_tomlr     s&     '!<<?r   T)frozenc                   F    e Zd ZU dZeed<   	 eed<   	 eed<   	 ed        Zy)_IncrementalConfigz>
    Configuration loaded from a ``pyproject.toml`` file.
    r   r=   rv   c                 V    t         j                  j                  | j                  d      S )z0Path of the ``_version.py`` file. May not exist.r   )ru   rv   rw   rG   s    r   r   z_IncrementalConfig.version_path  s     ww||DII}55r   N)	r,   r-   r.   r/   bool__annotations__strrk   r   r   r   r   r   r     s7     L LC
I"6 6r   r   c           	         t        | d      5 }t        |      }ddd       t              }d}|	d|v r|d   }|		 |d   d   }|t	        d      t        |t              s#t        dj                  t        |                  t        |du|t        t        j                  j                  |       |            S # 1 sw Y   xY w# t        $ r Y w xY w)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 {})r   r=   rv   )r   r   _extract_tool_incrementalKeyErrorr9   rV   r   	TypeErrorry   typer   r|   ru   rv   r   )	toml_pathr   datatool_incrementalr=   s        r   r   r     s     
i	 !!} 16 G#2B(B"6*	9of-G    	 gs#=DDT']S
 	
 t+rwwy17; E   		s   B;C ;C	CCc                     d| vry t        | d   t              st        d      d| d   vry | d   d   }t        |t              st        d      dhj                  |j	                               st        d      |S )Ntoolz[tool] must be a tableincrementalz"[tool.incremental] must be a tabler   z'Unexpected key(s) in [tool.incremental])rV   dictr9   
issupersetkeys)r   r   s     r   r   r     s    Td6lD)122DL(F|M2&-=>>8/4467BCCr   r   )r   c                  *    t        j                         S )N)r   rK   r   r   r   _setuptools_versionr   1  s    r   )r   r3   rr   )+r/   
__future__r   r   ru   r   r:   typingr   r   r   r   r	   r
   r   dataclassesr   iotyping_extensionsr   distutils.distr   _Distributionr   objectr   r   r   r1   r3   rr   r|   r   r   r   r   r   r   r   r   r   r   __all__r   r   r   <module>r      s    1 	 
  O O O ! )<((6 (< v9 xf xv
4	' -F-2 $6 6 602j" "  9r   