annotate Doc/tools/sphinxext/patchlevel.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 26f8ae6f037d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44858
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
2 """
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
3 patchlevel.py
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
4 ~~~~~~~~~~~~~
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
5
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
6 Extract version info from Include/patchlevel.h.
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
7 Adapted from Doc/tools/getversioninfo.
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
8
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
9 :copyright: 2007-2008 by Georg Brandl.
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
10 :license: Python license.
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
11 """
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
12
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
13 import os
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
14 import re
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
15 import sys
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
16
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
17 def get_header_version_info(srcdir):
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
18 patchlevel_h = os.path.join(srcdir, '..', 'Include', 'patchlevel.h')
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
19
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
20 # This won't pick out all #defines, but it will pick up the ones we
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
21 # care about.
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
22 rx = re.compile(r'\s*#define\s+([a-zA-Z][a-zA-Z_0-9]*)\s+([a-zA-Z_0-9]+)')
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
23
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
24 d = {}
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
25 f = open(patchlevel_h)
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
26 try:
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
27 for line in f:
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
28 m = rx.match(line)
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
29 if m is not None:
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
30 name, value = m.group(1, 2)
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
31 d[name] = value
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
32 finally:
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
33 f.close()
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
34
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
35 release = version = '%s.%s' % (d['PY_MAJOR_VERSION'], d['PY_MINOR_VERSION'])
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
36 micro = int(d['PY_MICRO_VERSION'])
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
37 if micro != 0:
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
38 release += '.' + str(micro)
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
39
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
40 level = d['PY_RELEASE_LEVEL']
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
41 suffixes = {
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
42 'PY_RELEASE_LEVEL_ALPHA': 'a',
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
43 'PY_RELEASE_LEVEL_BETA': 'b',
54737
26f8ae6f037d use 'rc' for release candidates for consistency
Benjamin Peterson <benjamin@python.org>
parents: 45602
diff changeset
44 'PY_RELEASE_LEVEL_GAMMA': 'rc',
44858
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
45 }
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
46 if level != 'PY_RELEASE_LEVEL_FINAL':
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
47 release += suffixes[level] + str(int(d['PY_RELEASE_SERIAL']))
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
48 return version, release
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
49
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
50
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
51 def get_sys_version_info():
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
52 major, minor, micro, level, serial = sys.version_info
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
53 release = version = '%s.%s' % (major, minor)
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
54 if micro:
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
55 release += '.%s' % micro
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
56 if level != 'final':
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
57 release += '%s%s' % (level[0], serial)
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
58 return version, release
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
59
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
60
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
61 def get_version_info():
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
62 try:
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
63 return get_header_version_info('.')
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
64 except (IOError, OSError):
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
65 version, release = get_sys_version_info()
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
66 print >>sys.stderr, 'Can\'t get version info from Include/patchlevel.h, ' \
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
67 'using version of this interpreter (%s).' % release
b76c78cda3ab Adapt to latest doctools refactoring.
Georg Brandl <georg@python.org>
parents:
diff changeset
68 return version, release
45602
5b7078eccee8 Make patchlevel print out the release if called as a script.
Georg Brandl <georg@python.org>
parents: 44858
diff changeset
69
5b7078eccee8 Make patchlevel print out the release if called as a script.
Georg Brandl <georg@python.org>
parents: 44858
diff changeset
70 if __name__ == '__main__':
5b7078eccee8 Make patchlevel print out the release if called as a script.
Georg Brandl <georg@python.org>
parents: 44858
diff changeset
71 print get_header_version_info('.')[1]