##// END OF EJS Templates
add system-wide IPython config...
Min RK -
Show More
@@ -501,27 +501,32 b' class Application(SingletonConfigurable):'
501
501
502 yield each config object in turn.
502 yield each config object in turn.
503 """
503 """
504 pyloader = PyFileConfigLoader(basefilename+'.py', path=path, log=log)
504
505 jsonloader = JSONFileConfigLoader(basefilename+'.json', path=path, log=log)
505 if not isinstance(path, list):
506 config = None
506 path = [path]
507 for loader in [pyloader, jsonloader]:
507 for path in path[::-1]:
508 try:
508 # path list is in descending priority order, so load files backwards:
509 config = loader.load_config()
509 pyloader = PyFileConfigLoader(basefilename+'.py', path=path, log=log)
510 except ConfigFileNotFound:
510 jsonloader = JSONFileConfigLoader(basefilename+'.json', path=path, log=log)
511 pass
511 config = None
512 except Exception:
512 for loader in [pyloader, jsonloader]:
513 # try to get the full filename, but it will be empty in the
513 try:
514 # unlikely event that the error raised before filefind finished
514 config = loader.load_config()
515 filename = loader.full_filename or basefilename
515 except ConfigFileNotFound:
516 # problem while running the file
516 pass
517 if log:
517 except Exception:
518 log.error("Exception while loading config file %s",
518 # try to get the full filename, but it will be empty in the
519 filename, exc_info=True)
519 # unlikely event that the error raised before filefind finished
520 else:
520 filename = loader.full_filename or basefilename
521 if log:
521 # problem while running the file
522 log.debug("Loaded config file: %s", loader.full_filename)
522 if log:
523 if config:
523 log.error("Exception while loading config file %s",
524 yield config
524 filename, exc_info=True)
525 else:
526 if log:
527 log.debug("Loaded config file: %s", loader.full_filename)
528 if config:
529 yield config
525
530
526 raise StopIteration
531 raise StopIteration
527
532
@@ -1,27 +1,18 b''
1 # coding: utf-8
1 # coding: utf-8
2 """
2 """
3 Tests for IPython.config.application.Application
3 Tests for IPython.config.application.Application
4
5 Authors:
6
7 * Brian Granger
8 """
4 """
9
5
10 #-----------------------------------------------------------------------------
6 # Copyright (c) IPython Development Team.
11 # Copyright (C) 2008-2011 The IPython Development Team
7 # Distributed under the terms of the Modified BSD License.
12 #
13 # Distributed under the terms of the BSD License. The full license is in
14 # the file COPYING, distributed as part of this software.
15 #-----------------------------------------------------------------------------
16
17 #-----------------------------------------------------------------------------
18 # Imports
19 #-----------------------------------------------------------------------------
20
8
21 import logging
9 import logging
10 import os
22 from io import StringIO
11 from io import StringIO
23 from unittest import TestCase
12 from unittest import TestCase
24
13
14 pjoin = os.path.join
15
25 import nose.tools as nt
16 import nose.tools as nt
26
17
27 from IPython.config.configurable import Configurable
18 from IPython.config.configurable import Configurable
@@ -31,13 +22,11 b' from IPython.config.application import ('
31 Application
22 Application
32 )
23 )
33
24
25 from IPython.utils.tempdir import TemporaryDirectory
34 from IPython.utils.traitlets import (
26 from IPython.utils.traitlets import (
35 Bool, Unicode, Integer, List, Dict
27 Bool, Unicode, Integer, List, Dict
36 )
28 )
37
29
38 #-----------------------------------------------------------------------------
39 # Code
40 #-----------------------------------------------------------------------------
41
30
42 class Foo(Configurable):
31 class Foo(Configurable):
43
32
@@ -189,5 +178,21 b' class TestApplication(TestCase):'
189 def test_unicode_argv(self):
178 def test_unicode_argv(self):
190 app = MyApp()
179 app = MyApp()
191 app.parse_command_line(['ünîcødé'])
180 app.parse_command_line(['ünîcødé'])
192
181
182 def test_multi_file(self):
183 app = MyApp()
184 app.log = logging.getLogger()
185 name = 'config.py'
186 with TemporaryDirectory('_1') as td1:
187 with open(pjoin(td1, name), 'w') as f1:
188 f1.write("get_config().MyApp.Bar.b = 1")
189 with TemporaryDirectory('_2') as td2:
190 with open(pjoin(td2, name), 'w') as f2:
191 f2.write("get_config().MyApp.Bar.b = 2")
192 app.load_config_file(name, path=[td2, td1])
193 app.init_bar()
194 self.assertEqual(app.bar.b, 2)
195 app.load_config_file(name, path=[td1, td2])
196 app.init_bar()
197 self.assertEqual(app.bar.b, 1)
193
198
@@ -7,25 +7,10 b' handling configuration and creating configurables.'
7
7
8 The job of an :class:`Application` is to create the master configuration
8 The job of an :class:`Application` is to create the master configuration
9 object and then create the configurable objects, passing the config to them.
9 object and then create the configurable objects, passing the config to them.
10
11 Authors:
12
13 * Brian Granger
14 * Fernando Perez
15 * Min RK
16
17 """
10 """
18
11
19 #-----------------------------------------------------------------------------
12 # Copyright (c) IPython Development Team.
20 # Copyright (C) 2008 The IPython Development Team
13 # Distributed under the terms of the Modified BSD License.
21 #
22 # Distributed under the terms of the BSD License. The full license is in
23 # the file COPYING, distributed as part of this software.
24 #-----------------------------------------------------------------------------
25
26 #-----------------------------------------------------------------------------
27 # Imports
28 #-----------------------------------------------------------------------------
29
14
30 import atexit
15 import atexit
31 import glob
16 import glob
@@ -42,15 +27,19 b' from IPython.utils.path import get_ipython_dir, get_ipython_package_dir, ensure_'
42 from IPython.utils import py3compat
27 from IPython.utils import py3compat
43 from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, Set, Instance
28 from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, Set, Instance
44
29
45 #-----------------------------------------------------------------------------
30 if os.name == 'nt':
46 # Classes and functions
31 programdata = os.environ.get('PROGRAMDATA', None)
47 #-----------------------------------------------------------------------------
32 if programdata:
33 SYSTEM_CONFIG_DIRS = [pjoin(programdata, 'ipython')]
34 else: # PROGRAMDATA is not defined by default on XP.
35 SYSTEM_CONFIG_DIRS = []
36 else:
37 SYSTEM_CONFIG_DIRS = [
38 "/usr/local/etc/ipython",
39 "/etc/ipython",
40 ]
48
41
49
42
50 #-----------------------------------------------------------------------------
51 # Base Application Class
52 #-----------------------------------------------------------------------------
53
54 # aliases and flags
43 # aliases and flags
55
44
56 base_aliases = {
45 base_aliases = {
@@ -100,7 +89,7 b' class BaseIPythonApplication(Application):'
100 builtin_profile_dir = Unicode(
89 builtin_profile_dir = Unicode(
101 os.path.join(get_ipython_package_dir(), u'config', u'profile', u'default')
90 os.path.join(get_ipython_package_dir(), u'config', u'profile', u'default')
102 )
91 )
103
92
104 config_file_paths = List(Unicode)
93 config_file_paths = List(Unicode)
105 def _config_file_paths_default(self):
94 def _config_file_paths_default(self):
106 return [py3compat.getcwd()]
95 return [py3compat.getcwd()]
@@ -336,6 +325,7 b' class BaseIPythonApplication(Application):'
336
325
337 def init_config_files(self):
326 def init_config_files(self):
338 """[optionally] copy default config files into profile dir."""
327 """[optionally] copy default config files into profile dir."""
328 self.config_file_paths.extend(SYSTEM_CONFIG_DIRS)
339 # copy config files
329 # copy config files
340 path = self.builtin_profile_dir
330 path = self.builtin_profile_dir
341 if self.copy_config_files:
331 if self.copy_config_files:
General Comments 0
You need to be logged in to leave comments. Login now