[Python-checkins] r63946 - in doctools/trunk/sphinx: application.py config.py environment.py

georg.brandl python-checkins at python.org
Wed Jun 4 22:25:27 CEST 2008


Author: georg.brandl
Date: Wed Jun 4 22:25:27 2008
New Revision: 63946
Log:
Fix the handling of extensions' config values.
Modified:
 doctools/trunk/sphinx/application.py
 doctools/trunk/sphinx/config.py
 doctools/trunk/sphinx/environment.py
Modified: doctools/trunk/sphinx/application.py
==============================================================================
--- doctools/trunk/sphinx/application.py	(original)
+++ doctools/trunk/sphinx/application.py	Wed Jun 4 22:25:27 2008
@@ -74,10 +74,7 @@
 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 @@
 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 @@
 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:
Modified: doctools/trunk/sphinx/config.py
==============================================================================
--- doctools/trunk/sphinx/config.py	(original)
+++ doctools/trunk/sphinx/config.py	Wed Jun 4 22:25:27 2008
@@ -30,11 +30,7 @@
 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 @@
 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 @@
 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 @@
 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 @@
 delattr(self, name)
 
 def __contains__(self, name):
- return name in self.valuenames
+ return name in self.config_values
Modified: doctools/trunk/sphinx/environment.py
==============================================================================
--- doctools/trunk/sphinx/environment.py	(original)
+++ doctools/trunk/sphinx/environment.py	Wed Jun 4 22:25:27 2008
@@ -397,9 +397,7 @@
 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


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /