| Crates.io | pep440_rs |
| lib.rs | pep440_rs |
| version | 0.7.3 |
| created_at | 2023-03-29 08:45:48.910332+00 |
| updated_at | 2024-12-04 15:32:24.059096+00 |
| description | A library for python version numbers and specifiers, implementing PEP 440 |
| homepage | |
| repository | https://github.com/konstin/pep440-rs |
| max_upload_size | |
| id | 823871 |
| size | 210,900 |
A library for python version numbers and specifiers, implementing PEP 440. See Reimplementing PEP 440 for some background.
Higher level bindings to the requirements syntax are available in pep508_rs.
use std::str::FromStr;
use pep440_rs::{parse_version_specifiers, Version, VersionSpecifier};
let version = Version::from_str("1.19").unwrap();
let version_specifier = VersionSpecifier::from_str("==1.*").unwrap();
assert!(version_specifier.contains(&version));
let version_specifiers = parse_version_specifiers(">=1.16, <2.0").unwrap();
assert!(version_specifiers.contains(&version));
In python (pip install pep440_rs):
from pep440_rs import Version, VersionSpecifier
assert Version("1.1a1").any_prerelease()
assert Version("1.1.dev2").any_prerelease()
assert not Version("1.1").any_prerelease()
assert VersionSpecifier(">=1.0").contains(Version("1.1a1"))
assert not VersionSpecifier(">=1.1").contains(Version("1.1a1"))
# Note that python comparisons are the version ordering, not the version specifiers operators
assert Version("1.1") >= Version("1.1a1")
assert Version("2.0") in VersionSpecifier("==2")
PEP 440 has a lot of unintuitive features, including:
1!1.2.3. Lower epoch always means lower version (1.0 <=2!0.1)^), but a pseudo-semver tilde (~=)1.0+local > 1.0 when sorting, but ==1.0 matches 1.0+local. While the
ordering of versions itself is a total order the version matching needs to catch all sorts of special cases