amtSemVer

Simple semantic versioning module


License
Apache-2.0
Install
pip install amtSemVer==1.0.0

Documentation

amtSemVer

Python 3.7+ Latest version released on PyPI Tests coverage Package license


amtSemVer is a Python 3 package that provides a very simplistic support for the Semantic Versioning 2.0.


Basic Usage

Install with pip:

pip install amtsemver

Import the SemanticVersion class in your python code

from amtSemVer import SemanticVersion

You can create a new version from its constituents:

# create a version with all the parameters 1.2.3-alpha+2345
version_a = SemanticVersion(major=1, minor=2, patch=3, pre_release="alpha", build="2345")

# create a simple version 2.0.0
version_b = SemanticVersion(major=2, minor=0, patch=0)

Or by parsing a string:

# create an object from the string
version_a = SemanticVersion.parse("1.2.3-alpha+2345")

# this works too
version_b = SemanticVersion.parse("1.2.3")
# or (1.2.0)
version_c = SemanticVersion.parse("1.2")
# or (1.0.0)
version_d = SemanticVersion.parse("1")
# or even (1.0.0-alpha)
version_e = SemanticVersion.parse("1+alpha")

__str__ representation of an object returns the following format major.minor.patch[-pre_release][+build]

>>> a = SemanticVersion.parse("1.2.3-alpha+2345")
>>> str(a)
'1.2.3-alpha+2345'

__repr__ returns a string that can be evaluated back as an object.

>>> a = SemanticVersion.parse("1.2.3-alpha+2345")
>>> b = repr(a)
>>> b
'SemanticVersion(major=1, minor=2, patch=3, pre_release="alpha", build="2345")'
>>> c = eval(b)
>>> c == a
True

Object supports the rich comparison operators:

  • Equal: a == b
  • Not Equal: a != b
  • Lesser: a < b
  • Lesser or Equal: a <= b
  • Greater: a > b
  • Greater or Equal: a >= b
>>> a = SemanticVersion.parse("1.2.0")
>>> b = SemanticVersion.parse("1.2.0-alpha")
>>> a > b
True
>>> a != b
True
>>> a <= b
False

Tests

Run tests:

$ tox

License

This package is released under the Apache License 2.0. See the bundled LICENSE file for details.