From c335e4974f5e19effde8da28eca8adcc338e79ef 2011-06-20 23:40:23 From: MinRK Date: 2011-06-20 23:40:23 Subject: [PATCH] load_subconfig supports profiles closes gh-523 --- diff --git a/IPython/config/loader.py b/IPython/config/loader.py index 92df8c6..4999925 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -23,7 +23,7 @@ import re import sys from IPython.external import argparse -from IPython.utils.path import filefind +from IPython.utils.path import filefind, get_ipython_dir #----------------------------------------------------------------------------- # Exceptions @@ -269,23 +269,40 @@ class PyFileConfigLoader(FileConfigLoader): def _read_file_as_dict(self): """Load the config file into self.config, with recursive loading.""" # This closure is made available in the namespace that is used - # to exec the config file. This allows users to call + # to exec the config file. It allows users to call # load_subconfig('myconfig.py') to load config files recursively. # It needs to be a closure because it has references to self.path # and self.config. The sub-config is loaded with the same path # as the parent, but it uses an empty config which is then merged # with the parents. - def load_subconfig(fname): - loader = PyFileConfigLoader(fname, self.path) + + # If a profile is specified, the config file will be loaded + # from that profile + + def load_subconfig(fname, profile=None): + # import here to prevent circular imports + from IPython.core.profiledir import ProfileDir, ProfileDirError + if profile is not None: + try: + profile_dir = ProfileDir.find_profile_dir_by_name( + get_ipython_dir(), + profile, + ) + except ProfileDirError: + return + path = profile_dir.location + else: + path = self.path + loader = PyFileConfigLoader(fname, path) try: sub_config = loader.load_config() except IOError: # Pass silently if the sub config is not there. This happens - # when a user us using a profile, but not the default config. + # when a user s using a profile, but not the default config. pass else: self.config._merge(sub_config) - + # Again, this needs to be a closure and should be used in config # files to get the config being loaded. def get_config(): diff --git a/IPython/config/profile/cluster/ipython_config.py b/IPython/config/profile/cluster/ipython_config.py index a2780c2..e28144e 100644 --- a/IPython/config/profile/cluster/ipython_config.py +++ b/IPython/config/profile/cluster/ipython_config.py @@ -1,10 +1,9 @@ c = get_config() -app = c.IPythonApp +app = c.InteractiveShellApp # This can be used at any point in a config file to load a sub config # and merge it into the current one. -import os -load_subconfig(os.path.join('..','profile_default', 'ipython_config.py')) +load_subconfig('ipython_config.py', profile='default') lines = """ from IPython.parallel import * diff --git a/IPython/config/profile/math/ipython_config.py b/IPython/config/profile/math/ipython_config.py index a7f43b3..2b2fe2d 100644 --- a/IPython/config/profile/math/ipython_config.py +++ b/IPython/config/profile/math/ipython_config.py @@ -1,10 +1,9 @@ c = get_config() -app = c.IPythonApp +app = c.InteractiveShellApp # This can be used at any point in a config file to load a sub config # and merge it into the current one. -import os -load_subconfig(os.path.join('..','profile_default', 'ipython_config.py')) +load_subconfig('ipython_config.py', profile='default') lines = """ import cmath diff --git a/IPython/config/profile/pylab/ipython_config.py b/IPython/config/profile/pylab/ipython_config.py index b9205d4..d6abdfd 100644 --- a/IPython/config/profile/pylab/ipython_config.py +++ b/IPython/config/profile/pylab/ipython_config.py @@ -1,10 +1,9 @@ c = get_config() -app = c.IPythonApp +app = c.InteractiveShellApp # This can be used at any point in a config file to load a sub config # and merge it into the current one. -import os -load_subconfig(os.path.join('..','profile_default', 'ipython_config.py')) +load_subconfig('ipython_config.py', profile='default') lines = """ import matplotlib diff --git a/IPython/config/profile/pysh/ipython_config.py b/IPython/config/profile/pysh/ipython_config.py index 60d5c19..cf41388 100644 --- a/IPython/config/profile/pysh/ipython_config.py +++ b/IPython/config/profile/pysh/ipython_config.py @@ -1,10 +1,9 @@ c = get_config() -app = c.IPythonApp +app = c.InteractiveShellApp # This can be used at any point in a config file to load a sub config # and merge it into the current one. -import os -load_subconfig(os.path.join('..','profile_default', 'ipython_config.py')) +load_subconfig('ipython_config.py', profile='default') c.InteractiveShell.prompt_in1 = '\C_LightGreen\u@\h\C_LightBlue[\C_LightCyan\Y1\C_LightBlue]\C_Green|\#> ' c.InteractiveShell.prompt_in2 = '\C_Green|\C_LightGreen\D\C_Green> ' diff --git a/IPython/config/profile/sympy/ipython_config.py b/IPython/config/profile/sympy/ipython_config.py index cdb3522..fc07889 100644 --- a/IPython/config/profile/sympy/ipython_config.py +++ b/IPython/config/profile/sympy/ipython_config.py @@ -1,10 +1,9 @@ c = get_config() -app = c.IPythonApp +app = c.InteractiveShellApp # This can be used at any point in a config file to load a sub config # and merge it into the current one. -import os -load_subconfig(os.path.join('..','profile_default', 'ipython_config.py')) +load_subconfig('ipython_config.py', profile='default') lines = """ from __future__ import division @@ -25,7 +24,7 @@ else: # Load the sympy_printing extension to enable nice printing of sympy expr's. if hasattr(app, 'extensions'): - app.extensions.append('sympy_printing') + app.extensions.append('sympyprinting') else: - app.extensions = ['sympy_printing'] + app.extensions = ['sympyprinting'] diff --git a/IPython/core/profileapp.py b/IPython/core/profileapp.py index 86bbb20..a5e4003 100644 --- a/IPython/core/profileapp.py +++ b/IPython/core/profileapp.py @@ -194,7 +194,6 @@ class ProfileCreate(BaseIPythonApplication): app.profile = self.profile app.init_profile_dir() app.init_config_files() - print 'tic' def stage_default_config_file(self): pass