Commits

Anonymous committed 9e7b542

Automatically get version info from the patchlevel.h file.

Comments (0)

Files changed (6)

 
 - "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

converter/newfiles/conf.py

 # 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 = ''

converter/newfiles/doc_sphinx.rst

 
 These variables are:
 
+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``.
 
-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.
+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
    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.

sphinx/builder.py

 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
 
         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)
 

sphinx/patchlevel.py

+# -*- 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

sphinx/templates/sidebar.html

               {% 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" %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.