rberga06.utils.types.Version#
- class rberga06.utils.types.Version(version: str)#
Bases:
Version
,SupportsPydanticV2
[Version | packaging.version.Version | str
]A
pydantic
v2-compatiblepackaging.version.Version
subclass.- Example:
>>> class Model(pydantic.BaseModel): ... # with packaging.version.Version, this would fail ... v: Version ... >>> Model(v=Version("v1.0.0")) Model(v=<Version('1.0.0')>) >>> Model(v=packaging.version.Version("v1.0.0")) Model(v=<Version('1.0.0')>) >>> Model(v="v1.0.0") Model(v=<Version('1.0.0')>) >>> Model.model_validate(dict(v="v1.0.0")) Model(v=<Version('1.0.0')>) >>> # In addition, Version behaves exactly like packaging.version.Version: >>> Version("1.0.0") > Version("1.0.0.a2") True
See
packaging.version.Version
for more details.- __init__(version: str) None #
Initialize a Version object.
- Parameters:
version – The string representation of a version which will be parsed and normalized before use.
- Raises:
InvalidVersion – If the
version
does not conform to PEP 440 in any way then this exception will be raised.
Methods
Attributes
The "base version" of the version.
The development number of the version.
The epoch of the version.
Whether this version is a development release.
Whether this version is a post-release.
Whether this version is a pre-release.
The local version segment of the version.
The first item of
release
or0
if unavailable.The third item of
release
or0
if unavailable.The second item of
release
or0
if unavailable.The post-release number of the version.
The pre-release segment of the version.
The public portion of the version.
The components of the "release" segment of the version.
- property base_version: str#
The “base version” of the version.
>>> Version("1.2.3").base_version '1.2.3' >>> Version("1.2.3+abc").base_version '1.2.3' >>> Version("1!1.2.3+abc.dev1").base_version '1!1.2.3'
The “base version” is the public version of the project without any pre or post release markers.
- property dev: int | None#
The development number of the version.
>>> print(Version("1.2.3").dev) None >>> Version("1.2.3.dev1").dev 1
- property epoch: int#
The epoch of the version.
>>> Version("2.0.0").epoch 0 >>> Version("1!2.0.0").epoch 1
- property is_devrelease: bool#
Whether this version is a development release.
>>> Version("1.2.3").is_devrelease False >>> Version("1.2.3.dev1").is_devrelease True
- property is_postrelease: bool#
Whether this version is a post-release.
>>> Version("1.2.3").is_postrelease False >>> Version("1.2.3.post1").is_postrelease True
- property is_prerelease: bool#
Whether this version is a pre-release.
>>> Version("1.2.3").is_prerelease False >>> Version("1.2.3a1").is_prerelease True >>> Version("1.2.3b1").is_prerelease True >>> Version("1.2.3rc1").is_prerelease True >>> Version("1.2.3dev1").is_prerelease True
- property local: str | None#
The local version segment of the version.
>>> print(Version("1.2.3").local) None >>> Version("1.2.3+abc").local 'abc'
- property micro: int#
The third item of
release
or0
if unavailable.>>> Version("1.2.3").micro 3 >>> Version("1").micro 0
- property minor: int#
The second item of
release
or0
if unavailable.>>> Version("1.2.3").minor 2 >>> Version("1").minor 0
- property post: int | None#
The post-release number of the version.
>>> print(Version("1.2.3").post) None >>> Version("1.2.3.post1").post 1
- property pre: Tuple[str, int] | None#
The pre-release segment of the version.
>>> print(Version("1.2.3").pre) None >>> Version("1.2.3a1").pre ('a', 1) >>> Version("1.2.3b1").pre ('b', 1) >>> Version("1.2.3rc1").pre ('rc', 1)
- property public: str#
The public portion of the version.
>>> Version("1.2.3").public '1.2.3' >>> Version("1.2.3+abc").public '1.2.3' >>> Version("1.2.3+abc.dev1").public '1.2.3'
- property release: Tuple[int, ...]#
The components of the “release” segment of the version.
>>> Version("1.2.3").release (1, 2, 3) >>> Version("2.0.0").release (2, 0, 0) >>> Version("1!2.0.0.post0").release (2, 0, 0)
Includes trailing zeroes but not the epoch or any pre-release / development / post-release suffixes.