ยปCore Development>Code coverage>Doc/tools/extensions/patchlevel.py

# Python code coverage for Doc/tools/extensions/patchlevel.py

#countcontent
1n/a# -*- coding: utf-8 -*-
2n/a"""
3n/a patchlevel.py
4n/a ~~~~~~~~~~~~~
5n/a
6n/a Extract version info from Include/patchlevel.h.
8n/a
9n/a :copyright: 2007-2008 by Georg Brandl.
11n/a"""
12n/a
13n/afrom __future__ import print_function
14n/a
15n/aimport os
16n/aimport re
17n/aimport sys
18n/a
20n/a patchlevel_h = os.path.join(srcdir, '..', 'Include', 'patchlevel.h')
21n/a
22n/a # This won't pick out all #defines, but it will pick up the ones we
24n/a rx = re.compile(r'\s*#define\s+([a-zA-Z][a-zA-Z_0-9]*)\s+([a-zA-Z_0-9]+)')
25n/a
26n/a d = {}
27n/a with open(patchlevel_h) as f:
28n/a for line in f:
29n/a m = rx.match(line)
30n/a if m is not None:
31n/a name, value = m.group(1, 2)
32n/a d[name] = value
33n/a
34n/a release = version = '%s.%s' % (d['PY_MAJOR_VERSION'], d['PY_MINOR_VERSION'])
35n/a micro = int(d['PY_MICRO_VERSION'])
36n/a release += '.' + str(micro)
37n/a
38n/a level = d['PY_RELEASE_LEVEL']
39n/a suffixes = {
40n/a 'PY_RELEASE_LEVEL_ALPHA': 'a',
41n/a 'PY_RELEASE_LEVEL_BETA': 'b',
42n/a 'PY_RELEASE_LEVEL_GAMMA': 'rc',
43n/a }
44n/a if level != 'PY_RELEASE_LEVEL_FINAL':
45n/a release += suffixes[level] + str(int(d['PY_RELEASE_SERIAL']))
46n/a return version, release
47n/a
48n/a
50n/a major, minor, micro, level, serial = sys.version_info
51n/a release = version = '%s.%s' % (major, minor)
52n/a release += '.%s' % micro
53n/a if level != 'final':
54n/a release += '%s%s' % (level[0], serial)
55n/a return version, release
56n/a
57n/a