diff --git a/IPython/config/application.py b/IPython/config/application.py index a6bda10..b6fea3d 100644 --- a/IPython/config/application.py +++ b/IPython/config/application.py @@ -525,19 +525,19 @@ class Application(SingletonConfigurable): filename, exc_info=True) else: log.debug("Loaded config file: %s", loader.full_filename) - if config : + if config: yield config - if not config_found : - raise ConfigFileNotFound('Neither .json, not .py file found.') + if not config_found: + raise ConfigFileNotFound('Neither .json, nor .py config file found.') raise StopIteration @catch_config_error def load_config_file(self, filename, path=None): - """Load config files (json/py) by filename and path.""" + """Load config files by filename and path.""" filename, ext = os.path.splitext(filename) - for config in self._load_config_files(filename, path=path , log=self.log): + for config in self._load_config_files(filename, path=path, log=self.log): self.update_config(config) diff --git a/IPython/config/loader.py b/IPython/config/loader.py index 3d1a60a..a5eae75 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -292,12 +292,12 @@ class Config(dict): class ConfigLoader(object): """A object for loading configurations from just about anywhere. - The resulting configuration is packaged as a :class:`Struct`. + The resulting configuration is packaged as a :class:`Config`. Notes ----- A :class:`ConfigLoader` does one thing: load a config from a source - (file, command line arguments) and returns the data as a :class:`Struct`. + (file, command line arguments) and returns the data as a :class:`Config` object. There are lots of things that :class:`ConfigLoader` does not do. It does not implement complex logic for finding config files. It does not handle default values or merge multiple configs. These things need to be @@ -324,10 +324,10 @@ class ConfigLoader(object): {} """ self.clear() - if log is None : + if log is None: self.log = self._log_default() self.log.debug('Using default logger') - else : + else: self.log = log def clear(self): @@ -375,7 +375,7 @@ class JSONFileConfigLoader(FileConfigLoader): """A Json file loader for config""" def load_config(self): - """Load the config from a file and return it as a Struct.""" + """Load the config from a file and return it as a Config object.""" self.clear() try: self._find_file() @@ -386,32 +386,31 @@ class JSONFileConfigLoader(FileConfigLoader): return self.config def _read_file_as_dict(self): - with open(self.full_filename) as f : + with open(self.full_filename) as f: return json.load(f) def _convert_to_config(self, dictionary): if 'version' in dictionary: version = dictionary.pop('version') - else : + else: version = 1 - self.log.warn("Unrecognized JSON config file version, assuming version : {}".format(version)) + self.log.warn("Unrecognized JSON config file version, assuming version {}".format(version)) if version == 1: return Config(dictionary) - else : - raise ValueError('Unknown version of JSON config file : version number {version}'.format(version=version)) + else: + raise ValueError('Unknown version of JSON config file: {version}'.format(version=version)) class PyFileConfigLoader(FileConfigLoader): """A config loader for pure python files. This is responsible for locating a Python config file by filename and - profile name, then executing it in a namespace where it could have access - to subconfigs. + path, then executing it to construct a Config object. """ def load_config(self): - """Load the config from a file and return it as a Struct.""" + """Load the config from a file and return it as a Config object.""" self.clear() try: self._find_file() @@ -645,7 +644,7 @@ class KeyValueConfigLoader(CommandLineConfigLoader): lhs = aliases[lhs] if '.' not in lhs: # probably a mistyped alias, but not technically illegal - self.log.warn("Unrecognized alias: '%s', it will probably have no effect. %s,-- %s"%(lhs,raw, aliases)) + self.log.warn("Unrecognized alias: '%s', it will probably have no effect.", raw) try: self._exec_config_str(lhs, rhs) except Exception: diff --git a/docs/source/development/config.rst b/docs/source/development/config.rst index 674ad5b..3fb45cc 100644 --- a/docs/source/development/config.rst +++ b/docs/source/development/config.rst @@ -90,8 +90,8 @@ A configuration *file* is simply a mechanism for producing that object. The main IPython configuration file is a plain Python script, which can perform extensive logic to populate the config object. IPython 2.0 introduces a JSON configuration file, -which is just a direct JSON serialization of the config dictionary. -The JSON format is easily processed by external software. +which is just a direct JSON serialization of the config dictionary, +which is easily processed by external software. When both Python and JSON configuration file are present, both will be loaded, with JSON configuration having higher priority. @@ -131,7 +131,7 @@ subclass:: # The rest of the class implementation would go here.. In this example, we see that :class:`MyClass` has three attributes, two -of (``name``, ``ranking``) can be configured. All of the attributes +of which (``name``, ``ranking``) can be configured. All of the attributes are given types and default values. If a :class:`MyClass` is instantiated, but not configured, these default values will be used. But let's see how to configure this class in a configuration file:: @@ -189,12 +189,12 @@ attribute of ``c`` is not the actual class, but instead is another JSON configuration Files ~~~~~~~~~~~~~~~~~~~~~~~~ -A JSON configuration file is simply a file that contain a +A JSON configuration file is simply a file that contains a :class:`~IPython.config.loader.Config` dictionary serialized to JSON. A JSON configuration file has the same base name as a Python configuration file, -just with a .json extension. +but with a .json extension. -Configuration described in previous section could be written as follow in a +Configuration described in previous section could be written as follows in a JSON configuration file: .. sourcecode:: json