Skip to main content

Library for parsing system package strings and comparing package versions

Project description

Introduction

version_utils is under active development. It is designed to provide a pure Python convenience library capable of parsing and comparing package and version strings for a variety of packaging standards. Whenever possible, the exact logic of existing package management comparison standards will be implemented so that users can trust that the results are equivalent to what they would get on the command-line.

Using version_utils ensures that packages can be compared even on systems without access to the command line or distro-provided tools on various Linux systems, allowing for easier and more consistent unit testing, safer deployment to multiple distributions, and easier and quicker development due to a well-documented API and standardized function calls.

Current Status and Roadmap

Currently, only RPM/Yum style packages are supported, but we have plans to add dpkg/Debian in the near future. Development will probably slow from there, although Pacman/Arch and various other distributions are on the radar.

Installation

This package has no dependencies, so a simple:

pip install version_utils

should suffice. Feel free to build from source as well, if you prefer.

Basic Use

Check the API documentation to ensure the module you are seeking to use is present. The example below uses the rpm module. From your application:

from subprocess import PIPE, Popen
from version_utils import rpm

pkg_req = 1.07

# Get a package string for an installed package
out, err = Popen(['rpm', '-q', 'foo'], stdout=PIPE, stderr=PIPE).communicate()
sys_pkg_str = out

# Get package information
sys_package = rpm.package(sys_package)
sys_pkg_name = sys_package.name
sys_pkg_version = sys_package.version

# Compare versions
result = rpm.compare_versions(pkg_req, sys_pkg_version)

if result < 0:  # sys_pkg was newer
    print('System package {0} does not satisfy
          requirement!'.format(sys_pkg_name))

In addition to indirectly comparing versions, a compare_packages function is provided to directly compare package strings, using the same logic as the package manager:

from version_utils import rpm

sys_pkg = 'perl-Compress-Raw-Zlib-2.021-136.el6_6.1.x86_64'
repo_pkg = 'perl-Compress-Raw-Zlib-2.021-138.el6_6.1.x86_64'

result = rpm.compare_packages(repo_pkg, sys_pkg)

if result > 0:  # repo_pkg is newer
    print('Repo package is newer')

The Package class can be used to succinctly transmit package information:

from version_utils import rpm

pkg_str = 'pkgconfig-0.23-9.1.el6.x86_64'
pkg = rpm.package(pkg_str)

# Get package name, epoch, version, release, and architecture as a tuple
print(pkg.info)

# Access the package string that was parsed to make the Package object
print(pkg.package)

# Access the epoch, version, and release information as a tuple
print(pkg.evr)

# Access name, epoch, version, release, and architecture independently
print('Name: {0}, Epoch: {1}, Version: {2}, Release: {3}, Arch:
      {4}'.format(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch))

Changes

  • 0.1.0 - Initial release

  • 0.1.1 - Added VersionUtilsError and RpmError classes. RpmError is thrown if a package string cannot be parsed. All errors inherit from VersionUtilsError

  • 0.2.0 - Added common.Package class and rpm.package method to return a Package object when parsing package strings. Deprecated public access to the rpm.parse_package method, although the function remains unchanged for backwards compatibility.

  • 0.2.1 - Fixed sdist to actually contain the package! Sorry about that. find_packages was not working as expected.

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

version_utils-0.2.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

version_utils-0.2.1-py2.py3-none-any.whl (8.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file version_utils-0.2.1.tar.gz.

File metadata

File hashes

Hashes for version_utils-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ff2514dbdd1bc988751a40f4b283cfe382fb8287c2518351bf2cf68fbd178ed5
MD5 bd0ec58f2a4b22be5392ff42de6cd8b6
BLAKE2b-256 f8b2f9b07276499b748cb1426ba3089328f077eafc1178b62596a395dbb7f11e

See more details on using hashes here.

File details

Details for the file version_utils-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for version_utils-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d3bde4cca1cd74e820d58b1d7c291f7a2603e995ea124ed0655baa26940ba122
MD5 548d829bf11afe136479b6c5297ac782
BLAKE2b-256 db0cb418d5b28ff7bd62e7c373f6f93560b619ce59ae4a1323c4f9fac4a0ee5f

See more details on using hashes here.

Supported by

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