summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-09-04 08:57:36 +0200
committerGeorg Brandl <georg@python.org>2014-09-04 08:57:36 +0200
commit3be62bc412f4270022582aaaee0b6823652fe4b8 (patch)
tree53ae8916a8e05bbae573bfa4d747663355b0824f
parent5009f760b8da40156439c873f68170f71abe39a6 (diff)
downloadsphinx-3be62bc412f4270022582aaaee0b6823652fe4b8.tar.gz
Add extension version check ability with new config value "needs_extensions".
-rw-r--r--CHANGES5
-rw-r--r--doc/config.rst13
-rw-r--r--sphinx/application.py15
-rw-r--r--sphinx/config.py1
4 files changed, 32 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index a56c147f..54f329d9 100644
--- a/CHANGES
+++ b/CHANGES
@@ -27,8 +27,9 @@ Features added
* Added ``sphinx.ext.napoleon`` extension for NumPy and Google style docstring
support.
* Added support for extension versions (a string returned by ``setup()``, these
- can be shown in the traceback log files). In the future this might also be
- used for version checking.
+ can be shown in the traceback log files). Version requirements for extensions
+ can be specified in projects using the new :confval:`needs_extensions` config
+ value.
* PR#214: Added stemming support for 14 languages, so that the built-in document
search can now handle these. Thanks to Shibukawa Yoshiki.
* PR#202: Allow "." and "~" prefixed references in ``:param:`` doc fields
diff --git a/doc/config.rst b/doc/config.rst
index 1e66d090..cc35a757 100644
--- a/doc/config.rst
+++ b/doc/config.rst
@@ -201,6 +201,19 @@ General configuration
.. versionadded:: 1.0
+.. confval:: needs_extensions
+
+ This value can be a dictionary specifying version requirements for extensions
+ in :confval:`extensions`, e.g. ``needs_extensions =
+ {'sphinxcontrib.something': '1.5'}``. The version strings should be in the
+ form ``major.minor``. Requirements do not have to be specified for all
+ extensions, only for those you want to check.
+
+ This requires that the extension specifies its version to Sphinx (see
+ :ref:`dev-extensions` for how to do that).
+
+ .. versionadded:: 1.3
+
.. confval:: nitpicky
If true, Sphinx will warn about *all* references where the target cannot be
diff --git a/sphinx/application.py b/sphinx/application.py
index b36e34db..21e60f43 100644
--- a/sphinx/application.py
+++ b/sphinx/application.py
@@ -144,6 +144,21 @@ class Sphinx(object):
'This project needs at least Sphinx v%s and therefore cannot '
'be built with this version.' % self.config.needs_sphinx)
+ # check extension versions if requested
+ if self.config.needs_extensions:
+ for extname, needs_ver in self.config.needs_extensions.items():
+ if extname not in self._extensions:
+ self.warn('needs_extensions config value specifies a '
+ 'version requirement for extension %s, but it is '
+ 'not loaded' % extname)
+ continue
+ has_ver = self._extension_versions[extname]
+ if has_ver == 'unknown version' or needs_ver > has_ver:
+ raise VersionRequirementError(
+ 'This project needs the extension %s at least in '
+ 'version %s and therefore cannot be built with the '
+ 'loaded version (%s).' % (extname, needs_ver, has_ver))
+
# set up translation infrastructure
self._init_i18n()
# set up the build environment
diff --git a/sphinx/config.py b/sphinx/config.py
index 7ab34eb3..9e5705ea 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -68,6 +68,7 @@ class Config(object):
trim_doctest_flags = (True, 'env'),
primary_domain = ('py', 'env'),
needs_sphinx = (None, None),
+ needs_extensions = ({}, None),
nitpicky = (False, 'env'),
nitpick_ignore = ([], 'html'),