Show More
@@ -525,19 +525,19 b' class Application(SingletonConfigurable):' | |||
|
525 | 525 | filename, exc_info=True) |
|
526 | 526 | else: |
|
527 | 527 | log.debug("Loaded config file: %s", loader.full_filename) |
|
528 |
if config |
|
|
528 | if config: | |
|
529 | 529 | yield config |
|
530 | 530 | |
|
531 |
if not config_found |
|
|
532 |
raise ConfigFileNotFound('Neither .json, no |
|
|
531 | if not config_found: | |
|
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 |
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 | 541 | self.update_config(config) |
|
542 | 542 | |
|
543 | 543 |
@@ -292,12 +292,12 b' 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 |
@@ -324,10 +324,10 b' class ConfigLoader(object):' | |||
|
324 | 324 | {} |
|
325 | 325 | """ |
|
326 | 326 | self.clear() |
|
327 |
if log is None |
|
|
327 | if log is None: | |
|
328 | 328 | self.log = self._log_default() |
|
329 | 329 | self.log.debug('Using default logger') |
|
330 |
else |
|
|
330 | else: | |
|
331 | 331 | self.log = log |
|
332 | 332 | |
|
333 | 333 | def clear(self): |
@@ -375,7 +375,7 b' 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() |
@@ -386,32 +386,31 b' class JSONFileConfigLoader(FileConfigLoader):' | |||
|
386 | 386 | return self.config |
|
387 | 387 | |
|
388 | 388 | def _read_file_as_dict(self): |
|
389 |
with open(self.full_filename) as f |
|
|
389 | with open(self.full_filename) as f: | |
|
390 | 390 | return json.load(f) |
|
391 | 391 | |
|
392 | 392 | def _convert_to_config(self, dictionary): |
|
393 | 393 | if 'version' in dictionary: |
|
394 | 394 | version = dictionary.pop('version') |
|
395 |
else |
|
|
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 |
else |
|
|
402 |
raise ValueError('Unknown version of JSON config file |
|
|
401 | else: | |
|
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 b' 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 b' 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 b' 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 b' 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