Skip to main content

Semantic Version Comparison for Python

Project description

semvercomp

🐍 Semantic Version Comparison for Python

Implementation of a Version object with comparison capabilities and tag validation following semver conventions.

Installation

pip install semvercomp

Usage

Classes

Version(major=0 : int, minor=0 : int, patch=0 : int, pre_release="" : str, patch="" : str, has_v=False : str)

Class Version represents a version tag following semver conventions. A version tag is structured the following way:

X.Y.Z-pre+build
Value Name Description
X Major Version when you make incompatible API changes
Y Minor Version when you add functionality in a backwards-compatible manner
Z Patch Version when you make backwards-compatible bug fixes
pre Pre Release Version pre-release tag
build Build Version build tag

Source: Semantic Versioning 2.0.0

  • Public Properties
Key Value Type
has_v bool Flag for preceding v or V in version tag
major int Major member
minor int Minor member
patch int Patch member
pre_release str Pre Release member
build str Build member
  • Instance of Version
from semvercomp.Version import Version

ver = Version(1, 0, 0, 'beta', '20191224')
print(str(ver))
# 1.0.0-beta+20191224
  • Creating a Version object from a version string:
from semvercomp.Version import Version

str_v = Version()
str_v.parse_version_number('v1.0.0-beta')
# str_v.major == 1
# str_v.minor == 0
# str_v.patch == 0
# str_v.has_v == True
# str_v.pre_release == 'beta'

Comparison of Version Objects

Version class implements __gt__, __lt__ and __eq__ built-in methods to implement comparison.

Equal

from semvercomp.Version import Version

a = Version(1, 0, 0)
b = Version(1, 0, 0)
print(a == b) # True

Greater

from semvercomp.Version import Version

a = Version(1, 1, 0)
b = Version(1, 0, 0)
print(a > b) # True

Lower

from semvercomp.Version import Version

a = Version(0, 1, 0)
b = Version(1, 0, 0)
print(a < b) # True

Validation

It is possible to validate and gather the different members of a version tag using validate version from semvercomp.validators.

validate_version(version: str): (parts: dict(), is_ok: bool)

Will return a tuple where, the first element is a dictionary with the properties of the given version tag destructured.

The second element in the tuple is a boolean flag that stands as the validation result.

from semvercomp.validators import validate_version

ver_str = 'v1.0.22'
(parts, is_ok) = validate_version(ver_str)
print(parts) # {'has_v': True, 'major': 1, 'minor': 0, 'patch': 22, 'pre_release': None, 'build': None}
print(is_ok) # True

Utils

to_version_list(coll: iterable): Version[]

Create an array of Version objects from an iterable of version tags as strings.

from semvercomp.utils import to_version_list

all = [
	'1.0.0-beta',
	'0.1.0+1234',
	'33.22.3'
]

versions = to_version_list(all)

Development

Requirements

Debugging

  • Debugging tests Tests for this package are written with pytest. The following json, is an example of the .vscode/settings.json:
{
	"python.pythonPath": /* Your Python Binary Address*/,
	"python.testing.pytestArgs": [
		"tests"
	],
	"python.testing.unittestEnabled": false,
	"python.testing.nosetestsEnabled": false,
	"python.testing.pytestEnabled": true
}

Testing

  • Running unit tests
# from repository root directory
pytest
  • Running test coverage
# from repository root directory
pytest --cov=semvercomp tests/

# or with html report
pytest --cov-report html --cov=semvercomp tests/

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

semvercomp-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semvercomp-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file semvercomp-0.1.1.tar.gz.

File metadata

  • Download URL: semvercomp-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for semvercomp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ac3f42aa15d9b5e598d9d405f48e0f59169d1370ffed1c860f8f746f4b8a96b4
MD5 2d7240998dc514736078a9f284025dc5
BLAKE2b-256 9858807f0e08d17db529c15d8aba06dc25bb1ca4dd709e77ccd2a7013689173a

See more details on using hashes here.

File details

Details for the file semvercomp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: semvercomp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for semvercomp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da647a950274e35689403ca41224f39e2dd81034913c170044e6f84ed0726e40
MD5 809f315a60db3d088314f9932a1cd12b
BLAKE2b-256 9696ec8b994e25baf057c18dd2e6f408b8016158f5ed19728508d79af3fdc2b9

See more details on using hashes here.

Supported by

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