MCPcopy
hub / github.com/borgbackup/borg / parse_version

Function parse_version

src/borg/version.py:4–33  ·  view source on GitHub ↗

Simplistic parser for setuptools_scm versions. Supports final versions and alpha ('a'), beta ('b') and release candidate ('rc') versions. It does not try to parse anything else than that, even if there is more in the version string. Output is a version tuple containing integers. I

(version)

Source from the content-addressed store, hash-verified

2
3
4def parse_version(version):
5 """
6 Simplistic parser for setuptools_scm versions.
7
8 Supports final versions and alpha ('a'), beta ('b') and release candidate ('rc') versions.
9 It does not try to parse anything else than that, even if there is more in the version string.
10
11 Output is a version tuple containing integers. It ends with one or two elements that ensure that relational
12 operators yield correct relations for alpha, beta and rc versions, too.
13 For final versions the last element is a -1.
14 For prerelease versions the last two elements are a smaller negative number and the number of e.g. the beta.
15
16 This version format is part of the remote protocol; don't change it in breaking ways.
17 """
18 version_re = r"""
19 (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+) # version, e.g. 1.2.33
20 (?P<prerelease>(?P<ptype>a|b|rc)(?P<pnum>\d+))? # optional prerelease, e.g. a1 or b2 or rc33
21 """
22 m = re.match(version_re, version, re.VERBOSE)
23 if m is None:
24 raise ValueError("Invalid version string %s" % version)
25 gd = m.groupdict()
26 version = [int(gd["major"]), int(gd["minor"]), int(gd["patch"])]
27 if m.lastgroup == "prerelease":
28 p_type = {"a": -4, "b": -3, "rc": -2}[gd["ptype"]]
29 p_num = int(gd["pnum"])
30 version += [p_type, p_num]
31 else:
32 version += [-1]
33 return tuple(version)
34
35
36def format_version(version):

Callers 7

xattr.pyFile · 0.90
__init__.pyFile · 0.90
do_versionMethod · 0.90
remote.pyFile · 0.70
legacyremote.pyFile · 0.70
test_parse_versionFunction · 0.50

Calls 1

matchMethod · 0.45

Tested by 2

test_parse_versionFunction · 0.40