Skip to main content

Convert between semver range and maven version range

Project description

unified-range

The library converts input semver ranges to a uniform model, and the other way around, providing objects that are easier to use programmatically.

Examples of supported ranges

  1. npm style semver - <1.2.3 >=2.0.0
  2. ruby style semver - <1.2.3, >=2.0.0
  3. maven style version ranges - [1.2.3,2.1.1), [3.0.0,4.1.1)

Additionally, use this library to run algorithms on any input version ranges and calculate whether a specific version is included in this range.

Prerequisites

  1. Ensure you have installed either pip or pipenv

  2. Install: pipenv install unified-range or pip install unified-range

  3. Import the api module: from unified_range import api

How to use

Following are the different functions you can perform with this library.

To convert a range to the uniform string range, from the semver format:

ver_rng = api.from_semver(semver_str)

Results: uniform range structure

Convert from the uniform range structure to a semver string (return str):

semver = api.to_semver(unified_spec_str)

To convert the versionrange object to a string:

version_range_str = str(ver_rng)

Convert from the uniform string to the uniform model object (VersionRange objects):

ver_rng = api.unified_range(unified_spec_str)

>>> api.unified_range('[1.2.3,4.5.6)')
<unified_range.models.UnifiedVersionRange at 0x7f7e4dc17320>

Within a list of ranges, retrieve versions not included:

filtered_lst = api.filter_versions(ascending_version_list, ranges)

>>> api.filter_versions(['0.1', '0.2', '1.0', '1.1', '2.0'], ['[,0.2]', '[1.1]'])
['1.0', '2.0']

The versions in ascending_version_list should be sorted in ascending order, from oldest to newest, and contain all the versions for the package.

From a list of version ranges, retrieve the closest version in the list to the current version (next):

Filter next version and maximum version from list of version and ranges:

next_version = api.next_filtered_version(current_version, ascending_version_list, ranges) current_version must be included in the ascending_version_list.

>>> api.next_filtered_version(current_version='0.2', ascending_version_list=['0.1', '0.2', '1.0', '1.1', '2.0'], ranges=['[,0.2]', '[1.1]'])
'1.0'

>>> api.next_filtered_version(current_version='1.1', ascending_version_list=['0.1', '0.2', '1.0', '1.1', '2.0'], ranges=['[,0.2]', '[1.1]'])
'2.0'

Retreive the latest version that is not included:

max_version = api.maximum_filtered_version(ascending_version_list, ranges)

>>> api.maximum_filtered_version(ascending_version_list=['0.1', '0.2', '1.0', '1.1', '2.0'], ranges=['[,0.2]', '[1.1]'])
'2.0'

Uniform structure examples

Following are the uniform structures used in this library:

Uniform string structure example: (,1.2.3)

Uniform model examples:

UnifiedVersionRange.constraints -> List[Restrictions]

Restriction.bounds -> Tuple[Bound, Bound]

Bound.version -> str

Bound.inclusive -> boolean

References and prior works

This library was built with the following:

  1. Maven’s VersionRange: model and spec of maven.
  2. https://semver.org/
  3. npm’s semver library

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

unified-range-0.1.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

unified_range-0.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file unified-range-0.1.1.tar.gz.

File metadata

  • Download URL: unified-range-0.1.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.9 Linux/4.15.0-1115-aws

File hashes

Hashes for unified-range-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5a1bbe0cb5c1a9a4d90d6ea35a55b594b7f6d6c669c79fd31d34570c5670a6d9
MD5 374a668187db421b7b38fa44e9366c22
BLAKE2b-256 1e383341a020274a63e9094f5e389f010e28a5576deef9dffd4bb861c6a1c363

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unified_range-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.9 Linux/4.15.0-1115-aws

File hashes

Hashes for unified_range-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34fa642ad9da081367958d3fb8a5f3794c72d76132e4d7f880f4be3e643a38dc
MD5 a2e9e3aef54cdc996f2cd1dd7873c789
BLAKE2b-256 148aaaea1d2d4f5c1a2c3f03563f17cbfc3648a54c2193c02d2fee24170400d8

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