Skip to main content

A library for dealing with RPM versions (NEVRA, EVR) correctly. Python bindings for the Rust crate rpm-version

Project description

Description

A library for dealing with RPM versions (NEVRA, EVR) correctly. Sort algorithm is identical to RPM.

Usage

from rpm_version import Evr, Nevra, evr_compare, evr_sort, nevra_sort

# Compare EVR strings directly
assert evr_compare("1.2.3-4", "1.2.3-5") == -1
assert evr_compare("2:1.0-1", "1:9.9-1") == 1

# Or use the Evr object for structured comparisons
v1 = Evr.parse("1:2.3.4-5")
v2 = Evr.parse("1:2.3.4-6")
assert v1 < v2

# Full NEVRA (Name-Epoch-Version-Release-Architecture) parsing
nevra = Nevra.parse("foo-1:2.3.4-5.x86_64")
print(f"{nevra.name} {nevra.version} {nevra.arch}")  # foo 2.3.4 x86_64

# Tilde (~) denotes a pre-release: sorts before the version without it
assert Evr.parse("1.0~rc1-1") < Evr.parse("1.0-1")
# Caret (^) denotes a post-release snapshot: sorts after the base version
assert Evr.parse("1.0-1") < Evr.parse("1.0^git1-1")
assert Evr.parse("1.0^git1-1") < Evr.parse("1.1-1")

# Bulk sorting entirely in Rust (avoids per-comparison FFI overhead)
sorted_versions = evr_sort(["2.0-1", "1.0-1", "1:0.5-1", "3.0-1"])
assert sorted_versions == ["1.0-1", "2.0-1", "3.0-1", "1:0.5-1"]

sorted_packages = nevra_sort(["foo-2.0-1.x86_64", "bar-1.0-1.x86_64", "foo-1.0-1.x86_64"])
assert sorted_packages == ["bar-1.0-1.x86_64", "foo-1.0-1.x86_64", "foo-2.0-1.x86_64"]

# Evr and Nevra are hashable
seen = {nevra}

# Version requirement matching
from rpm_version import Requirement, ReqOperator
req = Requirement("foo", ReqOperator.GE, Evr.parse("2.0-1"))
assert req.satisfies("foo", Evr.parse("2.0-1"))
assert req.satisfies("foo", Evr.parse("3.0-1"))
assert not req.satisfies("foo", Evr.parse("1.0-1"))

# String operators also work
req = Requirement("foo", ">=", Evr.parse("2.0-1"))

# Sort keys: encode RPM version ordering into raw bytes.
# Useful in databases (in-database RPM version ordering)
from rpm_version import EvrSortKey
key_a = EvrSortKey.from_values("1", "2.0", "3.fc40")
key_b = EvrSortKey.parse("1:3.0-1.fc40")
assert key_a < key_b
# Evr.sortkey() returns the same thing
assert Evr.parse("1:2.0-3.fc40").sortkey() == key_a
# Use as a sort key for sorted()
sorted(["2.0-1", "1:0.1-1", "1.0-1"], key=EvrSortKey.parse)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rpm_version-0.5.0.tar.gz (29.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rpm_version-0.5.0-cp310-abi3-win_amd64.whl (170.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

rpm_version-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl (319.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

rpm_version-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl (315.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

rpm_version-0.5.0-cp310-abi3-macosx_11_0_arm64.whl (282.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file rpm_version-0.5.0.tar.gz.

File metadata

  • Download URL: rpm_version-0.5.0.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rpm_version-0.5.0.tar.gz
Algorithm Hash digest
SHA256 47efce55bf50eab7de1e000f1938ea03c6d032892c31b079bc7235a30ccee485
MD5 5a252cca387dcaf7e867343cb079e76f
BLAKE2b-256 05573b03e61235325ddec40db9b8060a0e237876225ed0d961a3509abfb376d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpm_version-0.5.0.tar.gz:

Publisher: release.yml on rpm-rs/rpm-version

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rpm_version-0.5.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: rpm_version-0.5.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 170.2 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rpm_version-0.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 33ffa0af26a7076690e5c2a80a59957cae7722c0adc27f93728e2f5f0b74660c
MD5 8bacc9b182fb7f0224d9b3fcaf3e457a
BLAKE2b-256 a9f517637570689fe40a822baeb853a47672f07ef781777dbaea2ab26279ff9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpm_version-0.5.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on rpm-rs/rpm-version

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rpm_version-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rpm_version-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2ab412a9a06e50cb930dd7b34c736ff4c958c2096d3d94288e9dd2a4d81f11c5
MD5 46850b43c6d33b17afe62d1532298f31
BLAKE2b-256 be09d702d839192a0b958c190046620cf0fa116f45c491ffee79ee6dc766a10e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpm_version-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on rpm-rs/rpm-version

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rpm_version-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for rpm_version-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e9dbbc0a405e1e71e9327ff14502402f949cf55548508afe0bbf2ef6d52b359d
MD5 455d68fc6f2fac6e42ba4396b4678a7c
BLAKE2b-256 2b3395fcc898bbdcd752a286b82d1b430abc6344e3e12c77b5fd1a44f6e46861

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpm_version-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on rpm-rs/rpm-version

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rpm_version-0.5.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rpm_version-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c21601ff0c96f26c18ee0e4cfdde9a83d9cd9b4e626dd7df56aed3a9dd0b942c
MD5 af564e048e8e2a0430ea6686aabad465
BLAKE2b-256 1e4770446f8802639e5c014ad6965e3a60880c0b0eca3425875b17f053cb22c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpm_version-0.5.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on rpm-rs/rpm-version

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page