Parsing, inspecting and specifying versions.
Project description
versions
Parsing, inspecting and specifying versions.
Installing
Python 3.7 or above is required.
pip
Installing the library with pip
is quite simple:
$ pip install versions
Alternatively, the library can be installed from source:
$ git clone https://github.com/nekitdev/versions.git
$ cd versions
$ python -m pip install .
poetry
You can add versions
as a dependency with the following command:
$ poetry add versions
Or by directly specifying it in the configuration like so:
[tool.poetry.dependencies]
versions = "^1.5.0"
Alternatively, you can add it directly from the source:
[tool.poetry.dependencies.versions]
git = "https://github.com/nekitdev/versions.git"
Examples
Versions
parse_version
is used to parse versions:
from versions import parse_version
version = parse_version("1.0.0-dev.1+build.1")
print(version) # 1.0.0-dev.1+build.1
Segments
All version segments can be fetched with their respective names:
>>> print(version.release)
1.0.0
>>> version.release.parts
(1, 0, 0)
>>> print(version.dev)
dev.1
>>> (version.dev.phase, version.dev.value)
("dev", 1)
>>> print(version.local)
build.1
>>> version.local.parts
("build", 1)
Comparison
Versions support total ordering:
>>> v1 = parse_version("1.0.0")
>>> v2 = parse_version("2.0.0")
>>> v1 == v2
False
>>> v1 != v2
True
>>> v1 >= v2
False
>>> v1 <= v2
True
>>> v1 > v2
False
>>> v1 < v2
True
Specification
versions
also supports specifying version requirements and matching version against them.
Since versions support total ordering, they can be checked using version sets
(via parse_version_set
):
>>> from versions import parse_version, parse_version_set
>>> version_set = parse_version_set("^1.0.0")
>>> version_set
<VersionRange (>= 1.0.0, < 2.0.0)>
>>> version = parse_version("1.3.0")
>>> version.matches(version_set)
True
>>> another = parse_version("2.2.0")
>>> another.matches(version_set)
False
Alternatively, one can use specifiers, which are similar to version sets, except they retain
the structure of specifications given (via parse_specifier
):
>>> from versions import parse_specifier, parse_version
>>> specifier = parse_specifier("^1.0.0")
>>> specifier
<SpecifierOne (^1.0.0)>
>>> version = parse_version("1.3.0")
>>> version.matches(specifier)
True
>>> another = parse_version("2.2.0")
>>> another.matches(specifier)
False
Versioned
versions
allows users to access versions of items that have the __version__
attribute:
>>> from versions import get_version
>>> import versions
>>> get_version(versions)
<Version (1.5.0)>
Documentation
You can find the documentation here.
Support
If you need support with the library, you can send an email or refer to the official Discord server.
Changelog
You can find the changelog here.
Security Policy
You can find the Security Policy of versions
here.
Contributing
If you are interested in contributing to versions
, make sure to take a look at the
Contributing Guide, as well as the Code of Conduct.
License
versions
is licensed under the MIT License terms. See License for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file versions-1.5.0.tar.gz
.
File metadata
- Download URL: versions-1.5.0.tar.gz
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.11.3 Linux/5.15.0-1037-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2220fb26733d3ea5d071006f77a31ea37020797d1cba24fab9c355e1ae71f8c7 |
|
MD5 | 51dc9139a269a73e5c8a55a84a03daeb |
|
BLAKE2b-256 | 20fda3c6be1ed3d648b1f9d65b2a8d026bfc13eeb1abc11725e71b4c6f0951c3 |
File details
Details for the file versions-1.5.0-py3-none-any.whl
.
File metadata
- Download URL: versions-1.5.0-py3-none-any.whl
- Upload date:
- Size: 41.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.0 CPython/3.11.3 Linux/5.15.0-1037-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33f378fb8046b4303b62da8657b9bc8ab83f8dab46a7c26a07e66c6da6665811 |
|
MD5 | 77b500b8decfa4ae06f145a4b4aa6d6c |
|
BLAKE2b-256 | 200c02586eeeb7f8a630365b065fcb560586da96c3c444db67ea5cb577cfdcc2 |