Show More
@@ -529,13 +529,13 b' class Application(SingletonConfigurable):' | |||||
529 | yield config |
|
529 | yield config | |
530 |
|
530 | |||
531 |
if not config_found |
|
531 | if not config_found: | |
532 |
raise ConfigFileNotFound('Neither .json, no |
|
532 | raise ConfigFileNotFound('Neither .json, nor .py config file found.') | |
533 | raise StopIteration |
|
533 | raise StopIteration | |
534 |
|
534 | |||
535 |
|
535 | |||
536 | @catch_config_error |
|
536 | @catch_config_error | |
537 | def load_config_file(self, filename, path=None): |
|
537 | def load_config_file(self, filename, path=None): | |
538 |
"""Load config files |
|
538 | """Load config files by filename and path.""" | |
539 | filename, ext = os.path.splitext(filename) |
|
539 | filename, ext = os.path.splitext(filename) | |
540 |
for config in self._load_config_files(filename, path=path |
|
540 | for config in self._load_config_files(filename, path=path, log=self.log): | |
541 | self.update_config(config) |
|
541 | self.update_config(config) |
@@ -292,12 +292,12 b' class Config(dict):' | |||||
292 | class ConfigLoader(object): |
|
292 | class ConfigLoader(object): | |
293 | """A object for loading configurations from just about anywhere. |
|
293 | """A object for loading configurations from just about anywhere. | |
294 |
|
294 | |||
295 |
The resulting configuration is packaged as a :class:` |
|
295 | The resulting configuration is packaged as a :class:`Config`. | |
296 |
|
296 | |||
297 | Notes |
|
297 | Notes | |
298 | ----- |
|
298 | ----- | |
299 | A :class:`ConfigLoader` does one thing: load a config from a source |
|
299 | A :class:`ConfigLoader` does one thing: load a config from a source | |
300 |
(file, command line arguments) and returns the data as a :class:` |
|
300 | (file, command line arguments) and returns the data as a :class:`Config` object. | |
301 | There are lots of things that :class:`ConfigLoader` does not do. It does |
|
301 | There are lots of things that :class:`ConfigLoader` does not do. It does | |
302 | not implement complex logic for finding config files. It does not handle |
|
302 | not implement complex logic for finding config files. It does not handle | |
303 | default values or merge multiple configs. These things need to be |
|
303 | default values or merge multiple configs. These things need to be | |
@@ -375,7 +375,7 b' class JSONFileConfigLoader(FileConfigLoader):' | |||||
375 | """A Json file loader for config""" |
|
375 | """A Json file loader for config""" | |
376 |
|
376 | |||
377 | def load_config(self): |
|
377 | def load_config(self): | |
378 |
"""Load the config from a file and return it as a |
|
378 | """Load the config from a file and return it as a Config object.""" | |
379 | self.clear() |
|
379 | self.clear() | |
380 | try: |
|
380 | try: | |
381 | self._find_file() |
|
381 | self._find_file() | |
@@ -394,24 +394,23 b' class JSONFileConfigLoader(FileConfigLoader):' | |||||
394 | version = dictionary.pop('version') |
|
394 | version = dictionary.pop('version') | |
395 |
else |
|
395 | else: | |
396 | version = 1 |
|
396 | version = 1 | |
397 |
self.log.warn("Unrecognized JSON config file version, assuming version |
|
397 | self.log.warn("Unrecognized JSON config file version, assuming version {}".format(version)) | |
398 |
|
398 | |||
399 | if version == 1: |
|
399 | if version == 1: | |
400 | return Config(dictionary) |
|
400 | return Config(dictionary) | |
401 |
else |
|
401 | else: | |
402 |
raise ValueError('Unknown version of JSON config file |
|
402 | raise ValueError('Unknown version of JSON config file: {version}'.format(version=version)) | |
403 |
|
403 | |||
404 |
|
404 | |||
405 | class PyFileConfigLoader(FileConfigLoader): |
|
405 | class PyFileConfigLoader(FileConfigLoader): | |
406 | """A config loader for pure python files. |
|
406 | """A config loader for pure python files. | |
407 |
|
407 | |||
408 | This is responsible for locating a Python config file by filename and |
|
408 | This is responsible for locating a Python config file by filename and | |
409 | profile name, then executing it in a namespace where it could have access |
|
409 | path, then executing it to construct a Config object. | |
410 | to subconfigs. |
|
|||
411 | """ |
|
410 | """ | |
412 |
|
411 | |||
413 | def load_config(self): |
|
412 | def load_config(self): | |
414 |
"""Load the config from a file and return it as a |
|
413 | """Load the config from a file and return it as a Config object.""" | |
415 | self.clear() |
|
414 | self.clear() | |
416 | try: |
|
415 | try: | |
417 | self._find_file() |
|
416 | self._find_file() | |
@@ -645,7 +644,7 b' class KeyValueConfigLoader(CommandLineConfigLoader):' | |||||
645 | lhs = aliases[lhs] |
|
644 | lhs = aliases[lhs] | |
646 | if '.' not in lhs: |
|
645 | if '.' not in lhs: | |
647 | # probably a mistyped alias, but not technically illegal |
|
646 | # probably a mistyped alias, but not technically illegal | |
648 |
self.log.warn("Unrecognized alias: '%s', it will probably have no effect. |
|
647 | self.log.warn("Unrecognized alias: '%s', it will probably have no effect.", raw) | |
649 | try: |
|
648 | try: | |
650 | self._exec_config_str(lhs, rhs) |
|
649 | self._exec_config_str(lhs, rhs) | |
651 | except Exception: |
|
650 | except Exception: |
@@ -90,8 +90,8 b' A configuration *file* is simply a mechanism for producing that object.' | |||||
90 | The main IPython configuration file is a plain Python script, |
|
90 | The main IPython configuration file is a plain Python script, | |
91 | which can perform extensive logic to populate the config object. |
|
91 | which can perform extensive logic to populate the config object. | |
92 | IPython 2.0 introduces a JSON configuration file, |
|
92 | IPython 2.0 introduces a JSON configuration file, | |
93 |
which is just a direct JSON serialization of the config dictionary |
|
93 | which is just a direct JSON serialization of the config dictionary, | |
94 |
|
|
94 | which is easily processed by external software. | |
95 |
|
95 | |||
96 | When both Python and JSON configuration file are present, both will be loaded, |
|
96 | When both Python and JSON configuration file are present, both will be loaded, | |
97 | with JSON configuration having higher priority. |
|
97 | with JSON configuration having higher priority. | |
@@ -131,7 +131,7 b' subclass::' | |||||
131 | # The rest of the class implementation would go here.. |
|
131 | # The rest of the class implementation would go here.. | |
132 |
|
132 | |||
133 | In this example, we see that :class:`MyClass` has three attributes, two |
|
133 | In this example, we see that :class:`MyClass` has three attributes, two | |
134 | of (``name``, ``ranking``) can be configured. All of the attributes |
|
134 | of which (``name``, ``ranking``) can be configured. All of the attributes | |
135 | are given types and default values. If a :class:`MyClass` is instantiated, |
|
135 | are given types and default values. If a :class:`MyClass` is instantiated, | |
136 | but not configured, these default values will be used. But let's see how |
|
136 | but not configured, these default values will be used. But let's see how | |
137 | to configure this class in a configuration file:: |
|
137 | to configure this class in a configuration file:: | |
@@ -189,12 +189,12 b' attribute of ``c`` is not the actual class, but instead is another' | |||||
189 | JSON configuration Files |
|
189 | JSON configuration Files | |
190 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
|
190 | ~~~~~~~~~~~~~~~~~~~~~~~~ | |
191 |
|
191 | |||
192 | A JSON configuration file is simply a file that contain a |
|
192 | A JSON configuration file is simply a file that contains a | |
193 | :class:`~IPython.config.loader.Config` dictionary serialized to JSON. |
|
193 | :class:`~IPython.config.loader.Config` dictionary serialized to JSON. | |
194 | A JSON configuration file has the same base name as a Python configuration file, |
|
194 | A JSON configuration file has the same base name as a Python configuration file, | |
195 |
|
|
195 | but with a .json extension. | |
196 |
|
196 | |||
197 | Configuration described in previous section could be written as follow in a |
|
197 | Configuration described in previous section could be written as follows in a | |
198 | JSON configuration file: |
|
198 | JSON configuration file: | |
199 |
|
199 | |||
200 | .. sourcecode:: json |
|
200 | .. sourcecode:: json |
General Comments 0
You need to be logged in to leave comments.
Login now