[Python-checkins] r56645 - in doctools/trunk: TODO converter/newfiles/conf.py converter/newfiles/doc_sphinx.rst sphinx/builder.py sphinx/patchlevel.py sphinx/templates/sidebar.html
georg.brandl
python-checkins at python.org
Wed Aug 1 18:06:46 CEST 2007
Author: georg.brandl
Date: Wed Aug 1 18:06:45 2007
New Revision: 56645
Added:
doctools/trunk/sphinx/patchlevel.py
Modified:
doctools/trunk/TODO
doctools/trunk/converter/newfiles/conf.py
doctools/trunk/converter/newfiles/doc_sphinx.rst
doctools/trunk/sphinx/builder.py
doctools/trunk/sphinx/templates/sidebar.html
Log:
Automatically get version info from the patchlevel.h file.
Modified: doctools/trunk/TODO
==============================================================================
--- doctools/trunk/TODO (original)
+++ doctools/trunk/TODO Wed Aug 1 18:06:45 2007
@@ -3,7 +3,7 @@
- "often used" combo box in sidebar
- discuss and debug comments system
-- write new Makefile, handle automatic version info and checkout
+- write new Makefile, handle automatic checkout
- write a "printable" builder (export to latex, most probably)
- discuss lib -> ref section move
- prepare for databases other than sqlite for comments
Modified: doctools/trunk/converter/newfiles/conf.py
==============================================================================
--- doctools/trunk/converter/newfiles/conf.py (original)
+++ doctools/trunk/converter/newfiles/conf.py Wed Aug 1 18:06:45 2007
@@ -6,11 +6,17 @@
# that aren't pickleable (module imports are okay, they're removed automatically).
#
-# The default replacements for |version| and |release|:
+# The default replacements for |version| and |release|.
+# If 'auto', Sphinx looks for the Include/patchlevel.h file in the current Python
+# source tree and replaces the values accordingly.
+#
# The short X.Y version.
-version = '2.6'
+# version = '2.6'
+version = 'auto'
# The full version, including alpha/beta/rc tags.
-release = '2.6a0'
+# release = '2.6a0'
+release = 'auto'
+
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
today = ''
Modified: doctools/trunk/converter/newfiles/doc_sphinx.rst
==============================================================================
--- doctools/trunk/converter/newfiles/doc_sphinx.rst (original)
+++ doctools/trunk/converter/newfiles/doc_sphinx.rst Wed Aug 1 18:06:45 2007
@@ -17,17 +17,22 @@
These variables are:
-release : string
- A string that is used as a replacement for the ``|release|`` reST
- substitution. It should be the full version string including
- alpha/beta/release candidate tags, e.g. ``2.5.2b3``.
-
version : string
A string that is used as a replacement for the ``|version|`` reST
substitution. It should be the Python version the documentation refers to.
This consists only of the major and minor version parts, e.g. ``2.5``, even
for version 2.5.1.
+release : string
+ A string that is used as a replacement for the ``|release|`` reST
+ substitution. It should be the full version string including
+ alpha/beta/release candidate tags, e.g. ``2.5.2b3``.
+
+Both ``release`` and ``version`` can be ``'auto'``, which means that they are
+determined at runtime from the ``Include/patchlevel.h`` file, if a complete
+Python source distribution can be found, or else from the interpreter running
+Sphinx.
+
today_fmt : string
A ``strftime`` format that is used to format a replacement for the
``|today|`` reST substitution.
@@ -37,7 +42,7 @@
output literally. If this is nonzero, it is used instead of
``strftime(today_fmt)``.
-unused_file : list of strings
+unused_files : list of strings
A list of reST filenames that are to be disregarded during building. This
could be docs for temporarily disabled modules or documentation that's not
yet ready for public consumption.
Modified: doctools/trunk/sphinx/builder.py
==============================================================================
--- doctools/trunk/sphinx/builder.py (original)
+++ doctools/trunk/sphinx/builder.py Wed Aug 1 18:06:45 2007
@@ -31,6 +31,7 @@
from .writer import HTMLWriter
from .util.console import bold, purple, green
from .htmlhelp import build_hhx
+from .patchlevel import get_version_info, get_sys_version_info
from .environment import BuildEnvironment
from .highlighting import pygments, get_stylesheet
@@ -96,6 +97,18 @@
for key, val in self.config.items():
if isinstance(val, types.ModuleType):
del self.config[key]
+ # replace version info if 'auto'
+ if self.config['version'] == 'auto' or self.config['revision'] == 'auto':
+ try:
+ version, release = get_version_info(srcdirname)
+ except (IOError, OSError):
+ print >>warning_stream, 'WARNING: Can\'t get version info from ' \
+ 'Include/patchlevel.h, using version of this interpreter.'
+ version, release = get_sys_version_info()
+ if self.config['version'] == 'auto':
+ self.config['version'] = version
+ if self.config['release'] == 'auto':
+ self.config['release'] = release
if confoverrides:
self.config.update(confoverrides)
Added: doctools/trunk/sphinx/patchlevel.py
==============================================================================
--- (empty file)
+++ doctools/trunk/sphinx/patchlevel.py Wed Aug 1 18:06:45 2007
@@ -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
Modified: doctools/trunk/sphinx/templates/sidebar.html
==============================================================================
--- doctools/trunk/sphinx/templates/sidebar.html (original)
+++ doctools/trunk/sphinx/templates/sidebar.html Wed Aug 1 18:06:45 2007
@@ -23,7 +23,7 @@
{% elif builder == 'html' %}
<li><a href="{{ pathto(sourcename, true)|e }}">Show Source</a></li>
{% endif %}
- <li><a href="http://bugs.python.org/XXX?page={{ sourcename|e }}">Report Bug</a></li>
+ {# <li><a href="http://bugs.python.org/XXX?page={{ sourcename|e }}">Report Bug</a></li> #}
</ul>
{% endif %}
{% if current_page_name == "index" %}
More information about the Python-checkins
mailing list