Package version handling library
Project description
versions is a Python library to parse and compare package versions.
Documentation: versions.rtfd.org
Basic usage
Version comparisons example:
>>> from versions import Version >>> v1 = Version.parse('1') >>> v2 = Version.parse('2') >>> v1 == v2 False >>> v1 != v2 True >>> v1 > v2 False >>> v1 < v2 True >>> v1 >= v2 False >>> v1 <= v2 True
Version.parse expects a Semantic Version 2.0 string and returns a corresponding Version object:
>>> from versions import Version >>> v = Version.parse('1.2.0-dev+foo.bar') >>> v.major, v.minor, v.patch, v.prerelease, v.build_metadata (1, 2, 0, 'dev', set(['foo', 'bar']))
If it isn’t a semantic version string, the parser tries to normalize it:
>>> v = Version.parse('1') >>> v.major, v.minor, v.patch, v.prerelease, v.build_metadata (1, 0, 0, None, None)
Version constraint matching
versions also implements version constraint parsing and evaluation:
>>> from versions import Constraint >>> Constraint.parse('>1').match('2') True >>> Constraint.parse('<2').match(Version.parse('1')) True
For conveniance, constraint matching can be tested using the in operator:
>>> '1.5' in Constraint.parse('<2') True >>> Version('2') in Constraint.parse('!=2') False
Constraints can be merged using Constraints:
>>> from versions import Constraints >>> '1.0' in Constraints.parse('>1,<2') False >>> '1.5' in Constraints.parse('>1,<2') True >>> '2.0' in Constraints.parse('>1,<2') False
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
versions-0.3.0.tar.gz
(11.1 kB
view details)
File details
Details for the file versions-0.3.0.tar.gz
.
File metadata
- Download URL: versions-0.3.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78d5e2dc97ac1b1bac1032e5e30242d1fdf78a240a9139afa7aa76db1183d3e4 |
|
MD5 | 6a37e7d08d01a252990461f75be8beb7 |
|
BLAKE2b-256 | 5b7e209b31b1bfda09d78a426379c87b93547213249f089ac266b59622c3baa6 |