diff --git a/sphinx/application.py b/sphinx/application.py index 68edd588c..fe2990836 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -74,10 +74,7 @@ class Sphinx(object): self._events = events.copy() # read config - self.config = Config(confdir, 'conf.py') - if confoverrides: - for key, val in confoverrides.items(): - setattr(self.config, key, val) + self.config = Config(confdir, 'conf.py', confoverrides) # load all extension modules for extension in self.config.extensions: @@ -86,6 +83,9 @@ class Sphinx(object): if self.config.setup: self.config.setup(self) + # now that we know all config values, collect them from conf.py + self.config.init_values() + if buildername is None: print >>status, 'No builder selected, using default: html' buildername = 'html' @@ -176,10 +176,9 @@ class Sphinx(object): self.builderclasses[builder.name] = builder def add_config_value(self, name, default, rebuild_env): - if name in self.config.valuenames: + if name in self.config.config_values: raise ExtensionError('Config value %r already present' % name) - self.config.valuenames.add(name) - self.config.__class__.config_values[name] = (default, rebuild_env) + self.config.config_values[name] = (default, rebuild_env) def add_event(self, name): if name in self._events: diff --git a/sphinx/config.py b/sphinx/config.py index dd6d12651..024a7f868 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -30,11 +30,7 @@ class Config(object): today = ('', True), today_fmt = ('%B %d, %Y', True), - # extensibility - templates_path = ([], False), - extensions = ([], True), - - # general reading options + # general options master_doc = ('contents', True), source_suffix = ('.rst', True), unused_docs = ([], True), @@ -44,6 +40,7 @@ class Config(object): add_module_names = (True, True), show_authors = (False, True), pygments_style = ('sphinx', False), + templates_path = ([], False), template_bridge = (None, False), # HTML options @@ -80,8 +77,8 @@ class Config(object): latex_use_modindex = (True, False), ) - def __init__(self, dirname, filename): - self.valuenames = set(self.config_values.keys()) + def __init__(self, dirname, filename, overrides): + self.overrides = overrides config = {'__file__': path.join(dirname, filename)} olddir = os.getcwd() try: @@ -89,15 +86,24 @@ class Config(object): execfile(config['__file__'], config) finally: os.chdir(olddir) - for name in config: - if name in self.valuenames: - self.__dict__[name] = config[name] + self._raw_config = config + # these two must be preinitialized because extensions can add their + # own config values self.setup = config.get('setup', None) + self.extensions = config.get('extensions', []) + + def init_values(self): + config = self._raw_config + config.update(self.overrides) + for name in self._raw_config: + if name in self.config_values: + self.__dict__[name] = config[name] + del self._raw_config def __getattr__(self, name): if name.startswith('_'): raise AttributeError(name) - if name not in self.valuenames: + if name not in self.config_values: raise AttributeError('No such config value: %s' % name) default = self.config_values[name][0] if callable(default): @@ -114,4 +120,4 @@ class Config(object): delattr(self, name) def __contains__(self, name): - return name in self.valuenames + return name in self.config_values diff --git a/sphinx/environment.py b/sphinx/environment.py index 8b3bca4a8..f1adf6ea6 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -397,9 +397,7 @@ class BuildEnvironment: for key, descr in config.config_values.iteritems(): if not descr[1]: continue - if not hasattr(self.config, key) or \ - self.config[key] != config[key]: - + if self.config[key] != config[key]: msg = '[config changed] ' config_changed = True break