mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Automatically get version info from the patchlevel.h file.
This commit is contained in:
parent
0bccf4d944
commit
ca78ec11e9
2
TODO
2
TODO
@ -3,7 +3,7 @@ Global TODO
|
||||
|
||||
- "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
|
||||
|
@ -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 = ''
|
||||
|
@ -17,17 +17,22 @@ during a build run.
|
||||
|
||||
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 @@ today : string
|
||||
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.
|
||||
|
@ -31,6 +31,7 @@ from .util import (get_matching_files, attrdict, status_iterator,
|
||||
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 @@ class Builder(object):
|
||||
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)
|
||||
|
||||
|
56
sphinx/patchlevel.py
Normal file
56
sphinx/patchlevel.py
Normal file
@ -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
|
@ -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" %}
|
||||
|
Loading…
Reference in New Issue
Block a user