Add a function to parse a version string to a version info tuple.
This commit is contained in:
parent
94b478badf
commit
6f95ca74d5
@ -48,6 +48,15 @@ This module provides just couple of functions, main of which are:
|
||||
... 'major': 3, 'minor': 4, 'patch': 5,
|
||||
... 'prerelease': 'pre.2', 'build': 'build.4'}
|
||||
True
|
||||
>>> version_info = semver.parse_version_info("3.4.5-pre.2+build.4")
|
||||
>>> version_info
|
||||
VersionInfo(major=3, minor=4, patch=5, prerelease='pre.2', build='build.4')
|
||||
>>> version_info.major
|
||||
3
|
||||
>>> version_info > (1, 0)
|
||||
True
|
||||
>>> version_info < (3, 5)
|
||||
True
|
||||
>>> semver.bump_major("3.4.5")
|
||||
'4.0.0'
|
||||
>>> semver.bump_minor("3.4.5")
|
||||
|
18
semver.py
18
semver.py
@ -1,8 +1,11 @@
|
||||
"""
|
||||
Python helper for Semantic Versioning (http://semver.org/)
|
||||
"""
|
||||
|
||||
import collections
|
||||
import re
|
||||
|
||||
|
||||
__version__ = '2.6.0'
|
||||
__author__ = 'Konstantine Rybnikov'
|
||||
__author_email__ = 'k-bx@k-bx.com'
|
||||
@ -37,6 +40,21 @@ def parse(version):
|
||||
return version_parts
|
||||
|
||||
|
||||
VersionInfo = collections.namedtuple(
|
||||
'VersionInfo', 'major minor patch prerelease build')
|
||||
|
||||
def parse_version_info(version):
|
||||
"""
|
||||
Parse version string to a VersionInfo instance.
|
||||
"""
|
||||
parts = parse(version)
|
||||
version_info = VersionInfo(
|
||||
parts['major'], parts['minor'], parts['patch'],
|
||||
parts['prerelease'], parts['build'])
|
||||
|
||||
return version_info
|
||||
|
||||
|
||||
def compare(ver1, ver2):
|
||||
def nat_cmp(a, b):
|
||||
def convert(text):
|
||||
|
Loading…
Reference in New Issue
Block a user