Refactor needs_sphinx

This commit is contained in:
Takeshi KOMIYA
2016-04-17 12:40:09 +09:00
parent 64f1b3f5b1
commit ed52e00f34
2 changed files with 10 additions and 6 deletions

View File

@@ -133,12 +133,14 @@ class Sphinx(object):
self.config.check_unicode(self.warn)
# defer checking types until i18n has been initialized
# initialize some limited config variables before loading extensions
self.config.pre_init_values(self.warn)
# check the Sphinx version if requested
needs_sphinx = self.config.get_needs_sphinx()
if needs_sphinx and needs_sphinx > sphinx.__display_version__:
if self.config.needs_sphinx and self.config.needs_sphinx > sphinx.__display_version__:
raise VersionRequirementError(
'This project needs at least Sphinx v%s and therefore cannot '
'be built with this version.' % needs_sphinx)
'be built with this version.' % self.config.needs_sphinx)
# set confdir to srcdir if -C given (!= no confdir); a few pieces
# of code expect a confdir to be set

View File

@@ -338,9 +338,11 @@ class Config(object):
'characters; this can lead to Unicode errors occurring. '
'Please use Unicode strings, e.g. %r.' % (name, u'Content'))
def get_needs_sphinx(self):
"""Obtain the value of ``needs_sphinx``"""
return self.overrides.get('needs_sphinx') or self._raw_config.get('needs_sphinx')
def pre_init_values(self, warn):
"""Initialize some limited config variables before loading extensions"""
variables = ['needs_sphinx']
for name in variables:
self.__dict__[name] = self.overrides.get(name) or self._raw_config.get(name)
def init_values(self, warn):
config = self._raw_config