Show More
@@ -529,13 +529,13 class Application(SingletonConfigurable): | |||
|
529 | 529 | yield config |
|
530 | 530 | |
|
531 | 531 |
if not config_found |
|
532 |
raise ConfigFileNotFound('Neither .json, no |
|
|
532 | raise ConfigFileNotFound('Neither .json, nor .py config file found.') | |
|
533 | 533 | raise StopIteration |
|
534 | 534 | |
|
535 | 535 | |
|
536 | 536 | @catch_config_error |
|
537 | 537 | def load_config_file(self, filename, path=None): |
|
538 |
"""Load config files |
|
|
538 | """Load config files by filename and path.""" | |
|
539 | 539 | filename, ext = os.path.splitext(filename) |
|
540 | 540 |
for config in self._load_config_files(filename, path=path |
|
541 | 541 | self.update_config(config) |
@@ -292,12 +292,12 class Config(dict): | |||
|
292 | 292 | class ConfigLoader(object): |
|
293 | 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 | 297 | Notes |
|
298 | 298 | ----- |
|
299 | 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 | 301 | There are lots of things that :class:`ConfigLoader` does not do. It does |
|
302 | 302 | not implement complex logic for finding config files. It does not handle |
|
303 | 303 | default values or merge multiple configs. These things need to be |
@@ -375,7 +375,7 class JSONFileConfigLoader(FileConfigLoader): | |||
|
375 | 375 | """A Json file loader for config""" |
|
376 | 376 | |
|
377 | 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 | 379 | self.clear() |
|
380 | 380 | try: |
|
381 | 381 | self._find_file() |
@@ -394,24 +394,23 class JSONFileConfigLoader(FileConfigLoader): | |||
|
394 | 394 | version = dictionary.pop('version') |
|
395 | 395 |
else |
|
396 | 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 | 399 | if version == 1: |
|
400 | 400 | return Config(dictionary) |
|
401 | 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 | 405 | class PyFileConfigLoader(FileConfigLoader): |
|
406 | 406 | """A config loader for pure python files. |
|
407 | 407 | |
|
408 | 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 | |
|
410 | to subconfigs. | |
|
409 | path, then executing it to construct a Config object. | |
|
411 | 410 | """ |
|
412 | 411 | |
|
413 | 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 | 414 | self.clear() |
|
416 | 415 | try: |
|
417 | 416 | self._find_file() |
@@ -645,7 +644,7 class KeyValueConfigLoader(CommandLineConfigLoader): | |||
|
645 | 644 | lhs = aliases[lhs] |
|
646 | 645 | if '.' not in lhs: |
|
647 | 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 | 648 | try: |
|
650 | 649 | self._exec_config_str(lhs, rhs) |
|
651 | 650 | except Exception: |
@@ -90,8 +90,8 A configuration *file* is simply a mechanism for producing that object. | |||
|
90 | 90 | The main IPython configuration file is a plain Python script, |
|
91 | 91 | which can perform extensive logic to populate the config object. |
|
92 | 92 | IPython 2.0 introduces a JSON configuration file, |
|
93 |
which is just a direct JSON serialization of the config dictionary |
|
|
94 |
|
|
|
93 | which is just a direct JSON serialization of the config dictionary, | |
|
94 | which is easily processed by external software. | |
|
95 | 95 | |
|
96 | 96 | When both Python and JSON configuration file are present, both will be loaded, |
|
97 | 97 | with JSON configuration having higher priority. |
@@ -131,7 +131,7 subclass:: | |||
|
131 | 131 | # The rest of the class implementation would go here.. |
|
132 | 132 | |
|
133 | 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 | 135 | are given types and default values. If a :class:`MyClass` is instantiated, |
|
136 | 136 | but not configured, these default values will be used. But let's see how |
|
137 | 137 | to configure this class in a configuration file:: |
@@ -189,12 +189,12 attribute of ``c`` is not the actual class, but instead is another | |||
|
189 | 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 | 193 | :class:`~IPython.config.loader.Config` dictionary serialized to JSON. |
|
194 | 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 | 198 | JSON configuration file: |
|
199 | 199 | |
|
200 | 200 | .. sourcecode:: json |
General Comments 0
You need to be logged in to leave comments.
Login now