summaryrefslogtreecommitdiff
path: root/sphinx/patchlevel.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-08-01 16:06:45 +0000
committerGeorg Brandl <georg@python.org>2007-08-01 16:06:45 +0000
commitca78ec11e985570b0c4ab6ebe244555a5ef3c729 (patch)
tree9f1f3d6c706b750be96a2dd37a81df4c1cfbc5e1 /sphinx/patchlevel.py
parent0bccf4d9446af555f537cc5bdf0a1d9e62bc33fd (diff)
downloadsphinx-git-ca78ec11e985570b0c4ab6ebe244555a5ef3c729.tar.gz
Automatically get version info from the patchlevel.h file.
Diffstat (limited to 'sphinx/patchlevel.py')
-rw-r--r--sphinx/patchlevel.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/sphinx/patchlevel.py b/sphinx/patchlevel.py
new file mode 100644
index 000000000..85615a58e
--- /dev/null
+++ b/sphinx/patchlevel.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+"""
+ sphinx.patchlevel
+ ~~~~~~~~~~~~~~~~~
+
+ Extract version info from Include/patchlevel.h.
+ Adapted from Doc/tools/getversioninfo.
+
+ :copyright: 2007 by Georg Brandl.
+ :license: Python license.
+"""
+from __future__ import with_statement
+
+import os
+import re
+import sys
+
+def get_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 = {}
+ with open(patchlevel_h) as f:
+ for line in f:
+ m = rx.match(line)
+ if m is not None:
+ name, value = m.group(1, 2)
+ d[name] = value
+
+ release = version = "%s.%s" % (d["PY_MAJOR_VERSION"], d["PY_MINOR_VERSION"])
+ micro = int(d["PY_MICRO_VERSION"])
+ if micro != 0:
+ release += "." + str(micro)
+
+ level = d["PY_RELEASE_LEVEL"]
+ suffixes = {
+ "PY_RELEASE_LEVEL_ALPHA": "a",
+ "PY_RELEASE_LEVEL_BETA": "b",
+ "PY_RELEASE_LEVEL_GAMMA": "c",
+ }
+ 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)
+ if micro:
+ release += '.%s' % micro
+ if level != 'final':
+ release += '%s%s' % (level[0], serial)
+ return version, release