Skip to content

Commit 6f95ca7

Browse files
author
Ben Finney
committed
Add a function to parse a version string to a version info tuple.
1 parent 94b478b commit 6f95ca7

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ This module provides just couple of functions, main of which are:
4848
... 'major': 3, 'minor': 4, 'patch': 5,
4949
... 'prerelease': 'pre.2', 'build': 'build.4'}
5050
True
51+
>>> version_info = semver.parse_version_info("3.4.5-pre.2+build.4")
52+
>>> version_info
53+
VersionInfo(major=3, minor=4, patch=5, prerelease='pre.2', build='build.4')
54+
>>> version_info.major
55+
3
56+
>>> version_info > (1, 0)
57+
True
58+
>>> version_info < (3, 5)
59+
True
5160
>>> semver.bump_major("3.4.5")
5261
'4.0.0'
5362
>>> semver.bump_minor("3.4.5")

semver.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""
22
Python helper for Semantic Versioning (http://semver.org/)
33
"""
4+
5+
import collections
46
import re
57

8+
69
__version__ = '2.6.0'
710
__author__ = 'Konstantine Rybnikov'
811
__author_email__ = 'k-bx@k-bx.com'
@@ -37,6 +40,21 @@ def parse(version):
3740
return version_parts
3841

3942

43+
VersionInfo = collections.namedtuple(
44+
'VersionInfo', 'major minor patch prerelease build')
45+
46+
def parse_version_info(version):
47+
"""
48+
Parse version string to a VersionInfo instance.
49+
"""
50+
parts = parse(version)
51+
version_info = VersionInfo(
52+
parts['major'], parts['minor'], parts['patch'],
53+
parts['prerelease'], parts['build'])
54+
55+
return version_info
56+
57+
4058
def compare(ver1, ver2):
4159
def nat_cmp(a, b):
4260
def convert(text):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy