##// END OF EJS Templates
Components now auto-load the configs of parent classes as well.
Brian Granger -
Show More
@@ -266,28 +266,36 b' class Component(HasTraitlets):'
266 "root != parent.root")
266 "root != parent.root")
267
267
268 def _config_changed(self, name, old, new):
268 def _config_changed(self, name, old, new):
269 """Update all the class traits having a config_key with the config.
269 """Update all the class traits having ``config=True`` as metadata.
270
270
271 For any class traitlet with a ``config_key`` metadata attribute, we
271 For any class traitlet with a ``config`` metadata attribute that is
272 update the traitlet with the value of the corresponding config entry.
272 ``True``, we update the traitlet with the value of the corresponding
273
273 config entry.
274 In the future, we might want to do a pop here so stale config info
275 is not passed onto children.
276 """
274 """
277 # Get all traitlets with a config metadata entry that is True
275 # Get all traitlets with a config metadata entry that is True
278 traitlets = self.traitlets(config=True)
276 traitlets = self.traitlets(config=True)
279
277
280 # Don't do a blind getattr as that would cause the config to
278 # We auto-load config section for this class as well as any parent
281 # dynamically create the section with name self.__class__.__name__.
279 # classes that are Component subclasses. This starts with Component
282 if new._has_section(self.__class__.__name__):
280 # and works down the mro loading the config for each section.
283 my_config = new[self.__class__.__name__]
281 section_names = [cls.__name__ for cls in \
284 for k, v in traitlets.items():
282 reversed(self.__class__.__mro__) if
285 try:
283 issubclass(cls, Component) and issubclass(self.__class__, cls)]
286 config_value = my_config[k]
284
287 except KeyError:
285 for sname in section_names:
288 pass
286 # Don't do a blind getattr as that would cause the config to
289 else:
287 # dynamically create the section with name self.__class__.__name__.
290 setattr(self, k, config_value)
288 if new._has_section(sname):
289 my_config = new[sname]
290 for k, v in traitlets.items():
291 try:
292 config_value = my_config[k]
293 except KeyError:
294 pass
295 else:
296 # print "Setting %s.%s from %s.%s=%r" % \
297 # (self.__class__.__name__,k,sname,k,config_value)
298 setattr(self, k, config_value)
291
299
292 @property
300 @property
293 def children(self):
301 def children(self):
General Comments 0
You need to be logged in to leave comments. Login now