This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

A script and python module to compare version numbers. Use this to compare the version strings of packages, modules, really anything.

Commandline Tool

You can use the provided cmp-version tool to compare two version strings.

It will print to stdout “-1” if version1 is less/older than version2, “0” if they are equal, and “1” if version1 is greater/newer than version2.

Examples:

$ ./cmp-version 1.0.1b 1.0.1a

1

$ ./cmp-version 1.0.1b 1.0.2

-1

$ ./cmp-version 1.0 1.0.0

0

Comparing Filenames

Without actually scanning the contents of a package, you can from a script compare the versions based on the filenames.

Example:

$ cmp-version glibc-6.2.1-3.x86_64.rpm glibc-6.2.3-1.x86_64.rpm

-1

Method Signature

The cmp_version module provides a single method, cmp_version which compares two versions “cmp” style (think strcmp or the “cmp” operator in python<3).

def cmp_version(version1, version2):

”’

cmp_version - Compare two version strings, checking which one represents a “newer” (greater) release.

Note that even if two version strings are not equal string-wise, they may still be equal version-wise (e.x. 1.0.0 is the same version as 1.0)

@param version1 <str> - A version string

@param version2 <str> - A version string

@return <int>

-1 if version1 is older/less than version2

0 if version1 is equal to version2

1 if version1 is newer/greater than version2

So for example,

cmp_version(‘1.0.5b’, ‘1.0.5a’) would return 1 because 1.0.5b comes after 1.0.5a

Special Type

cmp_version provides a special type, “VersionString”, which inherits string. All the comparison magic functions are implemented, such that you can directly compare VersionString objects.

Example:

>>> x = VersionString('0.1b2')
>>> y = VersionString('.2b2')
>>>
>>> '0.1b2' < '.2b2' # Show that as strings this version compare gives wrong answer

False

>>> x < y # Show that using VersionString objects, the comparison does work

True

Sorting Lists

You can sort a list of versions, or filenames containing versions etc like this:

>>> from cmp_version import cmp_version, VersionString
>>>
>>> x = ['.9a', '0.9', '0.9.0', '1.2c', '1.1b', '1.b4.0']
>>> sorted(x, key=VersionString)

[‘0.9’, ‘0.9.0’, ‘.9a’, ‘1.1b’, ‘1.2c’, ‘1.b4.0’]

Return value

  • 0 is returned when the two versions are equal, even if the strings are not equal (for example “1.0” is the same version as “1.0.0”)
  • -1 is returned when version1 is older/less than version2
  • 1 is returned when version1 is newer/greater than version2.

License

This module is released under Public Domain.

Release History

Release History

2.0.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cmp_version-2.0.0.tar.gz (4.5 kB) Copy SHA256 Checksum SHA256 Source Mar 23, 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