Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Version numbers for your package system: parsing of requirements, comparison of version ranges, etc.

Project Description

Package versions

Implements version numbers, e.g. for use in your custom package/module/extension/addon system.

Version ranges are stored as VersionRange and can be created using syntax similar to pip:

VersionRange('==3')
# >=3.0,<4.0
VersionRange('<=2.5,>1')
# >=2.0,<=2.5
VersionRange('==2.*')
# >=2.0,<3.0

The main functionality is the combination of version ranges as best as possible, which is needed in case two packages rely on the same third package, but with different version limitations:

VersionRange('<=2.5,>1') & VersionRange('==2.*')
#>=2.0,<=2.5
VersionRange('<4.4') & VersionRange('>0,<=7')
#>=1.0,<4.4
VersionRange('<4.4') & VersionRange('>5.3')
#==5.3 and an optional warning or error (due to the mismatch in range)

It can also choose the most appropriate version among a list of options:

options = ['0.0.0', '2.8.', '2.1.unordered', '1.0.dev1', '2.2.words', '2.9.9', '999.999.0']
VersionRange('>=2.2,<2.9').choose(options)
# 2.8
VersionRange('>2.2,<2.8').choose(options)
# 2.8. and an optional warning or error (due to no match in range)
VersionRange('>2.2').choose(options)
# 999.999.0

And parse package dependencies:

parse_dependency('package>=3')
# ('package', VersionRange(>=3.0))
parse_dependency('specialname123>2.0,<3')
# ('specialname123', VersionRange(>=2.1,<3.0))
parse_dependencies('packA>1.3,<6\n#packskip==*\n\npackB<3.4#,>1.2')
# OrderedDict([('packa', VersionRange(>=1.4,<6.0)), ('packb', VersionRange(<=3.3))])

For a lot more examples, see the unit tests.

Installation

Install using:

pip install package-versions

Import using:

from package_versions import VersionRange, parse_dependencies

You’re ready to go!

Restrictions

A restriction this package imposes is that it assumed that feature versions are pairs of at most two integers, like 11.7 but not 11.7.3 or 1.7dev.

Version 11.7.3 is assumed to contain only bug-fixes compared to 11.7, and as such will always be preferred. Personally I like this unambiguous interpretation, but it’s up to you if you accept it.

Due to internal representation, there is a maximum for major and minor versions of 46340.

Package names roughly follow Python module naming guide (start with a letter, lowercase, not too long). Note that some systems treat upper and lower case as the same, so it’s probably wise to keep this restriction.

Tests

There are a lot of py.test unit tests that you can run using:

python3 -m pytest

License

BSD 3-clause “Revised” License. Keep the license file and understand that I’m not to be held liable, and then you’re free to do pretty much whatever.

Release History

Release History

This version
History Node

1.1

History Node

1.0

History Node

0.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
package-versions-1.1.tar.gz (10.6 kB) Copy SHA256 Checksum SHA256 Source Feb 16, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting