diff options
author | Georg Brandl <georg@python.org> | 2014-09-30 20:56:38 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-09-30 20:56:38 (GMT) |
commit | 61bd1dcf9bde6e64408392765d649c057a8fc81b (patch) | |
tree | 5947147361e896938f105eaebe90e0300ebb8345 /Doc/tools/patchlevel.py | |
parent | c8da4287a774fe8f26d6c47c501cf17a365ab922 (diff) | |
download | cpython-61bd1dcf9bde6e64408392765d649c057a8fc81b.zip cpython-61bd1dcf9bde6e64408392765d649c057a8fc81b.tar.gz cpython-61bd1dcf9bde6e64408392765d649c057a8fc81b.tar.bz2 |
Move Doc/tools/sphinxext content to Doc/tools, there is no need for the nested subdirectory anymore.
Diffstat (limited to 'Doc/tools/patchlevel.py')
-rw-r--r-- | Doc/tools/patchlevel.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Doc/tools/patchlevel.py b/Doc/tools/patchlevel.py new file mode 100644 index 0000000..bca2eb8 --- /dev/null +++ b/Doc/tools/patchlevel.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +""" + patchlevel.py + ~~~~~~~~~~~~~ + + Extract version info from Include/patchlevel.h. + Adapted from Doc/tools/getversioninfo. + + :copyright: 2007-2008 by Georg Brandl. + :license: Python license. +""" + +import os +import re +import sys + +def get_header_version_info(srcdir): + patchlevel_h = os.path.join(srcdir, '..', 'Include', 'patchlevel.h') + + # This won't pick out all #defines, but it will pick up the ones we + # care about. + rx = re.compile(r'\s*#define\s+([a-zA-Z][a-zA-Z_0-9]*)\s+([a-zA-Z_0-9]+)') + + d = {} + f = open(patchlevel_h) + try: + for line in f: + m = rx.match(line) + if m is not None: + name, value = m.group(1, 2) + d[name] = value + finally: + f.close() + + release = version = '%s.%s' % (d['PY_MAJOR_VERSION'], d['PY_MINOR_VERSION']) + micro = int(d['PY_MICRO_VERSION']) + release += '.' + str(micro) + + level = d['PY_RELEASE_LEVEL'] + suffixes = { + 'PY_RELEASE_LEVEL_ALPHA': 'a', + 'PY_RELEASE_LEVEL_BETA': 'b', + 'PY_RELEASE_LEVEL_GAMMA': 'rc', + } + if level != 'PY_RELEASE_LEVEL_FINAL': + release += suffixes[level] + str(int(d['PY_RELEASE_SERIAL'])) + return version, release + + +def get_sys_version_info(): + major, minor, micro, level, serial = sys.version_info + release = version = '%s.%s' % (major, minor) + release += '.%s' % micro + if level != 'final': + release += '%s%s' % (level[0], serial) + return version, release + + +def get_version_info(): + try: + return get_header_version_info('.') + except (IOError, OSError): + version, release = get_sys_version_info() + print >>sys.stderr, 'Can\'t get version info from Include/patchlevel.h, ' \ + 'using version of this interpreter (%s).' % release + return version, release + +if __name__ == '__main__': + print(get_header_version_info('.')[1]) |