Version Handling¶
A core requirement of dealing with packages is the ability to work with versions. PEP 440 defines the standard version scheme for Python packages which has been implemented by this module.
Usage¶
>>> from inversion.python import PythonVersion
>>> v1 = PythonVersion("1.0a5")
>>> v2 = PythonVersion("1.0")
>>> v1
<PythonVersion('1.0a5')>
>>> v2
<PythonVersion('1.0')>
>>> v1 < v2
True
>>> v1.epoch
0
>>> v1.release
(1, 0)
>>> v1.pre
('a', 5)
>>> v1.is_prerelease
True
>>> v2.is_prerelease
False
>>> PythonVersion("french toast")
Traceback (most recent call last):
...
InvalidVersion: Invalid version: 'french toast'
>>> PythonVersion("1.0").post
>>> PythonVersion("1.0").is_postrelease
False
>>> PythonVersion("1.0.post0").post
0
>>> PythonVersion("1.0.post0").is_postrelease
True
Reference¶
Python Versions¶
- class inversion.python.PythonVersion(version)¶
This class abstracts handling of a project’s versions. It implements the scheme defined in PEP 440. A
PythonVersioninstance is comparison aware and can be compared and sorted using the standard Python interfaces.- Parameters:
version (str) – The string representation of a version which will be parsed and normalized before use.
- Raises:
InvalidVersion – If the
versiondoes not conform to PEP 440 in any way then this exception will be raised.
- public¶
A string representing the public version portion of this
PythonVersion.
- base_version¶
A string representing the base version of this
PythonVersioninstance. The base version is the public version of the project without any pre or post release markers.
- epoch¶
An integer giving the version epoch of this
PythonVersioninstance
- release¶
A tuple of integers giving the components of the release segment of this
PythonVersioninstance; that is, the1.2.3part of the version number, including trailing zeroes but not including the epoch or any prerelease/development/postrelease suffixes
- local¶
A string representing the local version portion of this
PythonVersionif it has one, orNoneotherwise.
- pre¶
If this
PythonVersioninstance represents a prerelease, this attribute will be a pair of the prerelease phase (the string"a","b", or"rc") and the prerelease number (an integer). If this instance is not a prerelease, the attribute will be None.
- is_prerelease¶
A boolean value indicating whether this
PythonVersioninstance represents a prerelease and/or development release.
- dev¶
If this
PythonVersioninstance represents a development release, this attribute will be the development release number (an integer); otherwise, it will be None.
- is_devrelease¶
A boolean value indicating whether this
PythonVersioninstance represents a development release.
- post¶
If this
PythonVersioninstance represents a postrelease, this attribute will be the postrelease number (an integer); otherwise, it will be None.
- is_postrelease¶
A boolean value indicating whether this
PythonVersioninstance represents a post-release.
- class inversion.python.Version(version)¶
An alias for
PythonVersion.
- exception inversion.python.InvalidVersion¶
Raised when attempting to create a
PythonVersionwith a version string that does not conform to PEP 440.
- inversion.python.VERSION_PATTERN¶
A string containing the regular expression used to match a valid version. The pattern is not anchored at either end, and is intended for embedding in larger expressions (for example, matching a version number as part of a file name). The regular expression should be compiled with the
re.VERBOSEandre.IGNORECASEflags set.
Loose Versions¶
- class inversion.loose.LooseVersion(version)¶
This class abstracts handling of a version if it is not compatible with the scheme defined in PEP 440. It implements a similar interface to that of
PythonVersion. In addition to supporting pre-PEP 440 versions, this class is useful for handling versions for non-Python projects.- Parameters:
version (str) – The string representation of a version which will be used as is.
Note
LooseVersioninstances can’t be compared withPythonVersioninstances:>>> from inversion.python import PythonVersion >>> from inversion.loose import LooseVersion >>> v1 = PythonVersion("1.0") >>> v2 = LooseVersion("1.0") >>> v1 == v2 False >>> v1 >= v2 Traceback (most recent call last): ... TypeError: '>' not supported between instances of 'PythonVersion' and 'LooseVersion'
- public¶
A string representing the public version portion of this
LooseVersion. This will always be the entire version string.
- base_version¶
A string representing the base version portion of this
LooseVersioninstance. This will always be the entire version string.
- release¶
This will always be
Nonesince without PEP 440 we do not have the concept of a release segment or its components. It exists primarily for compatibility withPythonVersion’s interface.
- local¶
This will always be
Nonesince without PEP 440 we do not have the concept of a local version. It exists primarily for compatibility withPythonVersion’s interface.
- pre¶
This will always be
Nonesince without PEP 440 we do not have the concept of a prerelease. It exists primarily for compatibility withPythonVersion’s interface.
- is_prerelease¶
This will always be
Falsesince without PEP 440 we do not have the concept of a prerelease. It exists primarily for compatibility withPythonVersion’s interface.
- dev¶
This will always be
Nonesince without PEP 440 we do not have the concept of a development release. It exists primarily for compatibility withPythonVersion’s interface.
- is_devrelease¶
This will always be
Falsesince without PEP 440 we do not have the concept of a development release. It exists primarily for compatibility withPythonVersion’s interface.
- post¶
This will always be
Nonesince without PEP 440 we do not have the concept of a postrelease. It exists primarily for compatibility withPythonVersion’s interface.
- is_postrelease¶
This will always be
Falsesince without PEP 440 we do not have the concept of a postrelease. It exists primarily for compatibility withPythonVersion’s interface.
- class inversion.loose.Version(version)¶
An alias for
LooseVersion.