The library converts input semver ranges to a uniform model, and the other way around, providing objects that are easier to use programmatically.
- npm style semver -
<1.2.3 >=2.0.0
- ruby style semver -
<1.2.3, >=2.0.0
- 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.
-
Ensure you have installed either pip or pipenv
-
Install:
pipenv install unified-range
orpip install unified-range
-
Import the
api
module:from unified_range import api
Following are the different functions you can perform with this library.
ver_rng = api.from_semver(semver_str)
Results: uniform range structure
semver = api.to_semver(unified_spec_str)
version_range_str = str(ver_rng)
ver_rng = api.unified_range(unified_spec_str)
>>> api.unified_range('[1.2.3,4.5.6)')
<unified_range.models.UnifiedVersionRange at 0x7f7e4dc17320>
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'
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'
Following are the uniform structures used in this library:
Uniform string structure example: (,1.2.3)
UnifiedVersionRange.constraints -> List[Restrictions]
Restriction.bounds -> Tuple[Bound, Bound]
Bound.version -> str
Bound.inclusive -> boolean
This library was built with the following:
- Maven’s VersionRange: model and spec of maven.
- https://semver.org/
- npm’s semver library