pyTooling.Versioning

Implementation of semantic and date versioning version-numbers.

Hint

See high-level help for explanations and usage examples.

Classes

  • Parts: Enumeration of parts in a version number that can be presents.

  • Flags: State enumeration, if a (tagged) version is build from a clean or dirty working directory.

  • Version: Undocumented.

  • SemanticVersion: Representation of a semantic version number like 3.7.12.

  • CalendarVersion: Representation of a calendar version number like 2021.10.


Classes

class pyTooling.Versioning.Parts(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Enumeration of parts in a version number that can be presents.

Inheritance

Inheritance diagram of Parts

Unknown = 0

Undocumented

Major = 1

Major number is present. (e.g. X in vX.0.0).

Minor = 2

Minor number is present. (e.g. Y in v0.Y.0).

Patch = 4

Patch number is present. (e.g. Z in v0.0.Z).

Build = 8

Build number is present. (e.g. bbbb in v0.0.0.bbbb)

Pre = 16

Pre-release number is present.

Post = 32

Post-release number is present.

Prefix = 64

Prefix is present.

Postfix = 128

Postfix is present.

__format__(format_spec, /)

Convert to a string according to format_spec.

__str__()

Return repr(self).

__repr__()

Return repr(self).

__new__(value)
__hash__()

Return hash(self).

__getattribute__(name, /)

Return getattr(self, name).

__lt__(value, /)

Return self<value.

__le__(value, /)

Return self<=value.

__eq__(value, /)

Return self==value.

__ne__(value, /)

Return self!=value.

__gt__(value, /)

Return self>value.

__ge__(value, /)

Return self>=value.

__add__(value, /)

Return self+value.

__radd__(value, /)

Return value+self.

__sub__(value, /)

Return self-value.

__rsub__(value, /)

Return value-self.

__mul__(value, /)

Return self*value.

__rmul__(value, /)

Return value*self.

__mod__(value, /)

Return self%value.

__rmod__(value, /)

Return value%self.

__divmod__(value, /)

Return divmod(self, value).

__rdivmod__(value, /)

Return divmod(value, self).

__pow__(value, mod=None, /)

Return pow(self, value, mod).

__rpow__(value, mod=None, /)

Return pow(value, self, mod).

__neg__()

-self

__pos__()

+self

__abs__()

abs(self)

__bool__()

True if self else False

__invert__()

~self

__lshift__(value, /)

Return self<<value.

__rlshift__(value, /)

Return value<<self.

__rshift__(value, /)

Return self>>value.

__rrshift__(value, /)

Return value>>self.

__and__(value, /)

Return self&value.

__rand__(value, /)

Return value&self.

__xor__(value, /)

Return self^value.

__rxor__(value, /)

Return value^self.

__or__(value, /)

Return self|value.

__ror__(value, /)

Return value|self.

__int__()

int(self)

__float__()

float(self)

__floordiv__(value, /)

Return self//value.

__rfloordiv__(value, /)

Return value//self.

__truediv__(value, /)

Return self/value.

__rtruediv__(value, /)

Return value/self.

__index__()

Return self converted to an integer, if self is suitable for use as an index into a list.

conjugate()

Returns self, the complex conjugate of any int.

bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
to_bytes(length=1, byteorder='big', *, signed=False)

Return an array of bytes representing an integer.

length

Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

from_bytes(byteorder='big', *, signed=False)

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

as_integer_ratio()

Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
__trunc__()

Truncating an Integral returns itself.

__floor__()

Flooring an Integral returns itself.

__ceil__()

Ceiling of an Integral returns itself.

__round__()

Rounding an Integral returns itself.

Rounding with an ndigits argument also returns an integer.

__sizeof__()

Returns size in memory, in bytes.

is_integer()

Returns True. Exists for duck type compatibility with float.is_integer.

real

the real part of a complex number

imag

the imaginary part of a complex number

numerator

the numerator of a rational number in lowest terms

denominator

the denominator of a rational number in lowest terms

__dir__()

Returns public methods and other interesting attributes.

__init__(*args, **kwds)
__reduce_ex__(proto)

Helper for pickle.

class pyTooling.Versioning.Flags(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

State enumeration, if a (tagged) version is build from a clean or dirty working directory.

Inheritance

Inheritance diagram of Flags

Clean = 1

A versioned build was created from a clean working directory.

Dirty = 2

A versioned build was created from a dirty working directory.

__format__(format_spec, /)

Convert to a string according to format_spec.

__str__()

Return repr(self).

__repr__()

Return repr(self).

__new__(value)
__hash__()

Return hash(self).

__getattribute__(name, /)

Return getattr(self, name).

__lt__(value, /)

Return self<value.

__le__(value, /)

Return self<=value.

__eq__(value, /)

Return self==value.

__ne__(value, /)

Return self!=value.

__gt__(value, /)

Return self>value.

__ge__(value, /)

Return self>=value.

__add__(value, /)

Return self+value.

__radd__(value, /)

Return value+self.

__sub__(value, /)

Return self-value.

__rsub__(value, /)

Return value-self.

__mul__(value, /)

Return self*value.

__rmul__(value, /)

Return value*self.

__mod__(value, /)

Return self%value.

__rmod__(value, /)

Return value%self.

__divmod__(value, /)

Return divmod(self, value).

__rdivmod__(value, /)

Return divmod(value, self).

__pow__(value, mod=None, /)

Return pow(self, value, mod).

__rpow__(value, mod=None, /)

Return pow(value, self, mod).

__neg__()

-self

__pos__()

+self

__abs__()

abs(self)

__bool__()

True if self else False

__invert__()

~self

__lshift__(value, /)

Return self<<value.

__rlshift__(value, /)

Return value<<self.

__rshift__(value, /)

Return self>>value.

__rrshift__(value, /)

Return value>>self.

__and__(value, /)

Return self&value.

__rand__(value, /)

Return value&self.

__xor__(value, /)

Return self^value.

__rxor__(value, /)

Return value^self.

__or__(value, /)

Return self|value.

__ror__(value, /)

Return value|self.

__int__()

int(self)

__float__()

float(self)

__floordiv__(value, /)

Return self//value.

__rfloordiv__(value, /)

Return value//self.

__truediv__(value, /)

Return self/value.

__rtruediv__(value, /)

Return value/self.

__index__()

Return self converted to an integer, if self is suitable for use as an index into a list.

conjugate()

Returns self, the complex conjugate of any int.

bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
to_bytes(length=1, byteorder='big', *, signed=False)

Return an array of bytes representing an integer.

length

Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

from_bytes(byteorder='big', *, signed=False)

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

as_integer_ratio()

Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
__trunc__()

Truncating an Integral returns itself.

__floor__()

Flooring an Integral returns itself.

__ceil__()

Ceiling of an Integral returns itself.

__round__()

Rounding an Integral returns itself.

Rounding with an ndigits argument also returns an integer.

__sizeof__()

Returns size in memory, in bytes.

is_integer()

Returns True. Exists for duck type compatibility with float.is_integer.

real

the real part of a complex number

imag

the imaginary part of a complex number

numerator

the numerator of a rational number in lowest terms

denominator

the denominator of a rational number in lowest terms

__dir__()

Returns public methods and other interesting attributes.

__init__(*args, **kwds)
__reduce_ex__(proto)

Helper for pickle.

class pyTooling.Versioning.Version[source]

Inheritance

Inheritance diagram of Version

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

class pyTooling.Versioning.SemanticVersion(major, minor, patch=0, build=0, flags=Flags.Clean)[source]

Representation of a semantic version number like 3.7.12.

Inheritance

Inheritance diagram of SemanticVersion

Parameters:
_pre: int

Pre-release version number part.

_post: int

Post-release version number part.

_prefix: str

Prefix string

_postfix: str

Postfix string

__init__(major, minor, patch=0, build=0, flags=Flags.Clean)[source]
Parameters:
Return type:

None

_major: int

Major number part of the version number.

_minor: int

Minor number part of the version number.

_patch: int

Patch number part of the version number.

_build: int

Build number part of the version number.

_parts: Parts

Integer flag enumeration of present parts in a version number.

_flags: int

State if the version in a working directory is clean or dirty compared to a tagged version.

__eq__(other)[source]

Compare two Version instances (version numbers) for equality.

Parameters:

other (Any) – Parameter to compare against.

Return type:

bool

Returns:

True, if both version numbers are equal.

Raises:

TypeError – If parameter other is not of type SemanticVersion.

__ne__(other)[source]

Compare two Version instances (version numbers) for inequality.

Parameters:

other (Any) – Parameter to compare against.

Return type:

bool

Returns:

True, if both version numbers are not equal.

Raises:

TypeError – If parameter other is not of type SemanticVersion.

__compare(left, right)

Private helper method to compute the comparison of two SemanticVersion instances.

Parameters:
Return type:

Optional[bool]

Returns:

True, if left is smaller than right.
False if left is greater than right.
Otherwise it’s None (both parameters are equal).

__lt__(other)[source]

Compare two Version instances (version numbers) if the version is less than the second operand.

Parameters:

other (Any) – Parameter to compare against.

Return type:

bool

Returns:

True, if version is less than the second operand.

Raises:

TypeError – If parameter other is not of type SemanticVersion.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

__hash__ = None
__le__(other)[source]

Compare two Version instances (version numbers) if the version is less than or equal to the second operand.

Parameters:

other (Any) – Parameter to compare against.

Return type:

bool

Returns:

True, if version is less than or equal to the second operand.

Raises:

TypeError – If parameter other is not of type SemanticVersion.

__gt__(other)[source]

Compare two Version instances (version numbers) if the version is greater than the second operand.

Parameters:

other (Any) – Parameter to compare against.

Return type:

bool

Returns:

True, if version is greater than the second operand.

Raises:

TypeError – If parameter other is not of type SemanticVersion.

__ge__(other)[source]

Compare two Version instances (version numbers) if the version is greater than or equal to the second operand.

Parameters:

other (Any) – Parameter to compare against.

Return type:

bool

Returns:

True, if version is greater than or equal to the second operand.

Raises:

TypeError – If parameter other is not of type SemanticVersion.

__repr__()[source]

Return a string representation of this version number without prefix v.

Return type:

str

Returns:

Raw version number representation without a prefix.

__str__()[source]

Return a string representation of this version number with prefix v.

Return type:

str

Returns:

Version number representation including a prefix.

class pyTooling.Versioning.CalendarVersion[source]

Representation of a calendar version number like 2021.10.

Inheritance

Inheritance diagram of CalendarVersion

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.