Skip to main content

Version identifier management

Project description

The verschemes package provides easy and customizable version identifier management in Python. It supports defining custom version schemes in a subclass of the Version class. Instances of Version and its subclasses are concrete versions guaranteed to follow the rules of the class from which they were instantiated.

The source, documentation, and issues are hosted on GitHub.

This is an open-source project by and for the community. Contributions, suggestions, and questions are welcome (Twitter: @bravegnuworld).

Build Status Coverage Status

NOTE

Version 1.1 introduces a backwards-incompatible change: Version instances are now immutable. See the Release Notes for details.

Overview

Concept

Most versioned components have their own method of identifying their versions. This method is often termed “versioning” or called a “version scheme”. The method is simply a set of rules that dictate what is a valid version identifier and is usually separated (often by delimiters, such as a dot) in a number of segments to signify hierarchy among the versions. The hierarchy determines ordering along with the values of the segments within the hierarchy.

Implementation

In the verschemes library, a version scheme is a set of rules pertaining to the identification of versions for a given scope or purpose. Each version contains a number of segments often separated by delimiters. Each segment is allowed to have multiple fields to identify portions of the segment, though many segments have just one field.

Many version schemes are just integers separated by dots. The base Version class works fine for generic version numbers that fit this scheme, but the real power of this library is in defining version schemes (Version subclasses) with segments that specifically describe the scheme and automatically implement validation and normalized rendering of a version identifier or a sequence of version segment values. The SEGMENT_DEFINITIONS attribute of a Version subclass can be used to define the specific parameters of the version scheme that is represented by that class.

The library also contains some implementations of specific version schemes including Python, PEP 440, PostgreSQL, and X.org versioning. More are sure to be added, and submissions of version shemes for popular, public projects/systems are welcome. These implementations also serve as examples for those wishing to subclass Version for their own (or another’s) version scheme.

Examples

Importing

>>> from verschemes import Version
>>> from verschemes.python import PythonVersion, PythonMinorVersion
>>> from verschemes.pep440 import Pep440Version

Instantiation from a string

>>> Version("3.1.4")
verschemes.Version(3, 1, 4)
>>> Pep440Version("3.1.4")
verschemes.pep440.Pep440Version(None, 3, 1, 4, None, None, None, None, None, None)

Instantiation from segment values

>>> Version(3, 1, 4)
verschemes.Version(3, 1, 4)
>>> PythonVersion(3, 1, 4, ["b", 5])
verschemes.python.PythonVersion(3, 1, 4, Segment(releaselevel='b', serial=5))
>>> Pep440Version(None, 3, 1, 4)
verschemes.pep440.Pep440Version(None, 3, 1, 4, None, None, None, None, None, None)

Instantiation from named segment values

>>> PythonVersion(major=3, minor=1, micro=4)
verschemes.python.PythonVersion(3, 1, 4, None)
>>> Pep440Version(release1=3, release2=1, release3=4)
verschemes.pep440.Pep440Version(None, 3, 1, 4, None, None, None, None, None, None)
>>> Pep440Version(epoch=2, release1=3, release2=1, release3=4, post_release=7)
verschemes.pep440.Pep440Version(2, 3, 1, 4, None, None, None, None, 7, None)

Rendering

>>> version = Version(3, 1, 4)
>>> str(version)
'3.1.4'
>>> version.render()
'3.1.4'
>>> version = Pep440Version("3.1.4b5", epoch=2)
>>> str(version)
'2!3.1.4b5'
>>> version.render(min_release_segments=4)
'2!3.1.4.0b5'

Comparison

>>> Version("3.1.4") == Version(3, 1, 4)
True
>>> Version("3.1.10") > Version("3.1.4")
True
>>> PythonVersion(3, 1, 4, ["b", 5]).minor_version == PythonMinorVersion(3, 1)
True

Normalization

>>> str(Version("3.01.0004"))
'3.1.4'
>>> str(Pep440Version("3.1.4-dev5"))
'3.1.4.dev5'
>>> str(Pep440Version("3.1.4post6"))
'3.1.4.post6'
>>> str(Pep440Version("3.1.4.RC7"))
'3.1.4c7'

Properties

>>> version = PythonVersion(3, 1, 4, ["b", 5])
>>> version.major
3
>>> version.minor
1
>>> version.micro
4
>>> version.suffix.releaselevel
'b'
>>> version.suffix.serial
5
>>> version.is_release
True
>>> version.is_nondevelopment
False
>>> Pep440Version("3.1.4").is_release
True
>>> Pep440Version("3.1.4a2").is_release
False

Replacement

>>> version = Version(3, 1, 4)
>>> new_version = version.replace(_0=2)
>>> str(new_version)
'2.1.4'
>>> version = PythonVersion(3, 1, 4)
>>> new_version = version.replace(major=2)
>>> str(new_version)
'2.1.4'

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

verschemes-1.2.1.tar.gz (18.8 kB view details)

Uploaded Source

File details

Details for the file verschemes-1.2.1.tar.gz.

File metadata

  • Download URL: verschemes-1.2.1.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for verschemes-1.2.1.tar.gz
Algorithm Hash digest
SHA256 fdcb7897055af0fc809834afedc1f0705f98b6e2e0ec16e39f0929199d78252e
MD5 91e818809732e35d18ed30a2b48221ed
BLAKE2b-256 43c0e50c4c51a971eb550ab01a5a5cacf6c1c83eef12a7d85b595d6da80bf8d8

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