MCPcopy Create free account
hub / github.com/numpy/numpy / NumpyVersion

Class NumpyVersion

numpy/lib/_version.py:14–155  ·  view source on GitHub ↗

Parse and compare numpy version strings. NumPy has the following versioning scheme (numbers given are examples; they can be > 9 in principle): - Released version: '1.8.0', '1.8.1', etc. - Alpha: '1.8.0a1', '1.8.0a2', etc. - Beta: '1.8.0b1', '1.8.0b2', etc. - Release candida

Source from the content-addressed store, hash-verified

12
13
14class NumpyVersion():
15 """Parse and compare numpy version strings.
16
17 NumPy has the following versioning scheme (numbers given are examples; they
18 can be > 9 in principle):
19
20 - Released version: '1.8.0', '1.8.1', etc.
21 - Alpha: '1.8.0a1', '1.8.0a2', etc.
22 - Beta: '1.8.0b1', '1.8.0b2', etc.
23 - Release candidates: '1.8.0rc1', '1.8.0rc2', etc.
24 - Development versions: '1.8.0.dev-f1234afa' (git commit hash appended)
25 - Development versions after a1: '1.8.0a1.dev-f1234afa',
26 '1.8.0b2.dev-f1234afa',
27 '1.8.1rc1.dev-f1234afa', etc.
28 - Development versions (no git hash available): '1.8.0.dev-Unknown'
29
30 Comparing needs to be done against a valid version string or other
31 `NumpyVersion` instance. Note that all development versions of the same
32 (pre-)release compare equal.
33
34 .. versionadded:: 1.9.0
35
36 Parameters
37 ----------
38 vstring : str
39 NumPy version string (``np.__version__``).
40
41 Examples
42 --------
43 >>> from numpy.lib import NumpyVersion
44 >>> if NumpyVersion(np.__version__) < '1.7.0':
45 ... print('skip')
46 >>> # skip
47
48 >>> NumpyVersion('1.7') # raises ValueError, add ".0"
49 Traceback (most recent call last):
50 ...
51 ValueError: Not a valid numpy version string
52
53 """
54
55 def __init__(self, vstring):
56 self.vstring = vstring
57 ver_main = re.match(r'\d+\.\d+\.\d+', vstring)
58 if not ver_main:
59 raise ValueError("Not a valid numpy version string")
60
61 self.version = ver_main.group()
62 self.major, self.minor, self.bugfix = [int(x) for x in
63 self.version.split('.')]
64 if len(vstring) == ver_main.end():
65 self.pre_release = 'final'
66 else:
67 alpha = re.match(r'a\d', vstring[ver_main.end():])
68 beta = re.match(r'b\d', vstring[ver_main.end():])
69 rc = re.match(r'rc\d', vstring[ver_main.end():])
70 pre_rel = [m for m in [alpha, beta, rc] if m is not None]
71 if pre_rel:

Callers 10

test_main_versionsFunction · 0.90
test_version_1_point_10Function · 0.90
test_alpha_beta_rcFunction · 0.90
test_dev_versionFunction · 0.90
test_dev_a_b_rc_mixedFunction · 0.90
test_dev0_versionFunction · 0.90
test_dev0_a_b_rc_mixedFunction · 0.90
lib_version.pyFile · 0.90
setupMethod · 0.90
_compareMethod · 0.85

Calls

no outgoing calls

Tested by 7

test_main_versionsFunction · 0.72
test_version_1_point_10Function · 0.72
test_alpha_beta_rcFunction · 0.72
test_dev_versionFunction · 0.72
test_dev_a_b_rc_mixedFunction · 0.72
test_dev0_versionFunction · 0.72
test_dev0_a_b_rc_mixedFunction · 0.72