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