diff options
Diffstat (limited to 'sphinx/config.py')
-rw-r--r-- | sphinx/config.py | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/sphinx/config.py b/sphinx/config.py index 69ba7cfe..77d6779d 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -8,21 +8,21 @@ :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import with_statement import re -import sys from os import path +from six import PY3, iteritems, string_types, binary_type, integer_types + from sphinx.errors import ConfigError from sphinx.locale import l_ from sphinx.util.osutil import make_filename, cd -from sphinx.util.pycompat import bytes, b, execfile_ +from sphinx.util.pycompat import execfile_ -nonascii_re = re.compile(b(r'[\x80-\xff]')) +nonascii_re = re.compile(br'[\x80-\xff]') CONFIG_SYNTAX_ERROR = "There is a syntax error in your configuration file: %s" -if sys.version_info >= (3, 0): +if PY3: CONFIG_SYNTAX_ERROR += "\nDid you change the syntax from 2.x to 3.x?" class Config(object): @@ -51,10 +51,6 @@ class Config(object): source_suffix = ('.rst', 'env'), source_encoding = ('utf-8-sig', 'env'), exclude_patterns = ([], 'env'), - # the next three are all deprecated now - unused_docs = ([], 'env'), - exclude_trees = ([], 'env'), - exclude_dirnames = ([], 'env'), default_role = (None, 'env'), add_function_parentheses = (True, 'env'), add_module_names = (True, 'env'), @@ -71,8 +67,15 @@ 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'), + numfig = (False, 'env'), + numfig_secnum_depth = (1, 'env'), + numfig_prefix = ({'figure': l_('Fig. %s'), + 'table': l_('Table %s'), + 'code-block': l_('Listing %s')}, + 'env'), # HTML options html_theme = ('default', 'html'), @@ -205,6 +208,10 @@ class Config(object): # gettext options gettext_compact = (True, 'gettext'), + gettext_location = (True, 'gettext'), + gettext_uuid = (False, 'gettext'), + gettext_auto_build = (True, 'env'), + gettext_enables = ([], 'env'), # XML options xml_pretty = (True, 'env'), @@ -214,8 +221,11 @@ class Config(object): self.overrides = overrides self.values = Config.config_values.copy() config = {} - if "extensions" in overrides: - config["extensions"] = overrides["extensions"] + if 'extensions' in overrides: + if isinstance(overrides['extensions'], string_types): + config['extensions'] = overrides.pop('extensions').split(',') + else: + config['extensions'] = overrides.pop('extensions') if dirname is not None: config_file = path.join(dirname, filename) config['__file__'] = config_file @@ -225,7 +235,7 @@ class Config(object): # config file is executed try: execfile_(filename, config) - except SyntaxError, err: + except SyntaxError as err: raise ConfigError(CONFIG_SYNTAX_ERROR % err) self._raw_config = config @@ -237,19 +247,43 @@ class Config(object): def check_unicode(self, warn): # check all string values for non-ASCII characters in bytestrings, # since that can result in UnicodeErrors all over the place - for name, value in self._raw_config.iteritems(): - if isinstance(value, bytes) and nonascii_re.search(value): + for name, value in iteritems(self._raw_config): + if isinstance(value, binary_type) and nonascii_re.search(value): warn('the config value %r is set to a string with non-ASCII ' 'characters; this can lead to Unicode errors occurring. ' 'Please use Unicode strings, e.g. %r.' % (name, u'Content') ) - def init_values(self): + def init_values(self, warn): config = self._raw_config - for valname, value in self.overrides.iteritems(): + for valname, value in iteritems(self.overrides): if '.' in valname: realvalname, key = valname.split('.', 1) config.setdefault(realvalname, {})[key] = value + continue + elif valname not in self.values: + warn('unknown config value %r in override, ignoring' % valname) + continue + defvalue = self.values[valname][0] + if isinstance(value, string_types): + if isinstance(defvalue, dict): + warn('cannot override dictionary config setting %r, ' + 'ignoring (use %r to set individual elements)' % + (valname, valname + '.key=value')) + continue + elif isinstance(defvalue, list): + config[valname] = value.split(',') + elif isinstance(defvalue, integer_types): + try: + config[valname] = int(value) + except ValueError: + warn('invalid number %r for config value %r, ignoring' + % (value, valname)) + elif defvalue is not None and not isinstance(defvalue, string_types): + warn('cannot override config setting %r with unsupported type, ' + 'ignoring' % valname) + else: + config[valname] = value else: config[valname] = value for name in config: |