##// END OF EJS Templates
load_subconfig supports profiles...
MinRK -
Show More
@@ -23,7 +23,7 b' import re'
23 23 import sys
24 24
25 25 from IPython.external import argparse
26 from IPython.utils.path import filefind
26 from IPython.utils.path import filefind, get_ipython_dir
27 27
28 28 #-----------------------------------------------------------------------------
29 29 # Exceptions
@@ -269,23 +269,40 b' class PyFileConfigLoader(FileConfigLoader):'
269 269 def _read_file_as_dict(self):
270 270 """Load the config file into self.config, with recursive loading."""
271 271 # This closure is made available in the namespace that is used
272 # to exec the config file. This allows users to call
272 # to exec the config file. It allows users to call
273 273 # load_subconfig('myconfig.py') to load config files recursively.
274 274 # It needs to be a closure because it has references to self.path
275 275 # and self.config. The sub-config is loaded with the same path
276 276 # as the parent, but it uses an empty config which is then merged
277 277 # with the parents.
278 def load_subconfig(fname):
279 loader = PyFileConfigLoader(fname, self.path)
278
279 # If a profile is specified, the config file will be loaded
280 # from that profile
281
282 def load_subconfig(fname, profile=None):
283 # import here to prevent circular imports
284 from IPython.core.profiledir import ProfileDir, ProfileDirError
285 if profile is not None:
286 try:
287 profile_dir = ProfileDir.find_profile_dir_by_name(
288 get_ipython_dir(),
289 profile,
290 )
291 except ProfileDirError:
292 return
293 path = profile_dir.location
294 else:
295 path = self.path
296 loader = PyFileConfigLoader(fname, path)
280 297 try:
281 298 sub_config = loader.load_config()
282 299 except IOError:
283 300 # Pass silently if the sub config is not there. This happens
284 # when a user us using a profile, but not the default config.
301 # when a user s using a profile, but not the default config.
285 302 pass
286 303 else:
287 304 self.config._merge(sub_config)
288
305
289 306 # Again, this needs to be a closure and should be used in config
290 307 # files to get the config being loaded.
291 308 def get_config():
@@ -1,10 +1,9 b''
1 1 c = get_config()
2 app = c.IPythonApp
2 app = c.InteractiveShellApp
3 3
4 4 # This can be used at any point in a config file to load a sub config
5 5 # and merge it into the current one.
6 import os
7 load_subconfig(os.path.join('..','profile_default', 'ipython_config.py'))
6 load_subconfig('ipython_config.py', profile='default')
8 7
9 8 lines = """
10 9 from IPython.parallel import *
@@ -1,10 +1,9 b''
1 1 c = get_config()
2 app = c.IPythonApp
2 app = c.InteractiveShellApp
3 3
4 4 # This can be used at any point in a config file to load a sub config
5 5 # and merge it into the current one.
6 import os
7 load_subconfig(os.path.join('..','profile_default', 'ipython_config.py'))
6 load_subconfig('ipython_config.py', profile='default')
8 7
9 8 lines = """
10 9 import cmath
@@ -1,10 +1,9 b''
1 1 c = get_config()
2 app = c.IPythonApp
2 app = c.InteractiveShellApp
3 3
4 4 # This can be used at any point in a config file to load a sub config
5 5 # and merge it into the current one.
6 import os
7 load_subconfig(os.path.join('..','profile_default', 'ipython_config.py'))
6 load_subconfig('ipython_config.py', profile='default')
8 7
9 8 lines = """
10 9 import matplotlib
@@ -1,10 +1,9 b''
1 1 c = get_config()
2 app = c.IPythonApp
2 app = c.InteractiveShellApp
3 3
4 4 # This can be used at any point in a config file to load a sub config
5 5 # and merge it into the current one.
6 import os
7 load_subconfig(os.path.join('..','profile_default', 'ipython_config.py'))
6 load_subconfig('ipython_config.py', profile='default')
8 7
9 8 c.InteractiveShell.prompt_in1 = '\C_LightGreen\u@\h\C_LightBlue[\C_LightCyan\Y1\C_LightBlue]\C_Green|\#> '
10 9 c.InteractiveShell.prompt_in2 = '\C_Green|\C_LightGreen\D\C_Green> '
@@ -1,10 +1,9 b''
1 1 c = get_config()
2 app = c.IPythonApp
2 app = c.InteractiveShellApp
3 3
4 4 # This can be used at any point in a config file to load a sub config
5 5 # and merge it into the current one.
6 import os
7 load_subconfig(os.path.join('..','profile_default', 'ipython_config.py'))
6 load_subconfig('ipython_config.py', profile='default')
8 7
9 8 lines = """
10 9 from __future__ import division
@@ -25,7 +24,7 b' else:'
25 24
26 25 # Load the sympy_printing extension to enable nice printing of sympy expr's.
27 26 if hasattr(app, 'extensions'):
28 app.extensions.append('sympy_printing')
27 app.extensions.append('sympyprinting')
29 28 else:
30 app.extensions = ['sympy_printing']
29 app.extensions = ['sympyprinting']
31 30
@@ -194,7 +194,6 b' class ProfileCreate(BaseIPythonApplication):'
194 194 app.profile = self.profile
195 195 app.init_profile_dir()
196 196 app.init_config_files()
197 print 'tic'
198 197
199 198 def stage_default_config_file(self):
200 199 pass
General Comments 0
You need to be logged in to leave comments. Login now