Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

load_subconfig supports profiles

closes gh-523
  • Loading branch information...
commit a7380bdac7ae2dc42eb74421671ca78cd40b10cf 1 parent 1d02df3
@minrk minrk authored
View
29 IPython/config/loader.py
@@ -23,7 +23,7 @@
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 @@ def _find_file(self):
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():
View
5 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 *
View
5 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
View
5 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
View
5 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> '
View
9 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 @@
# 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']
View
1  IPython/core/profileapp.py
@@ -194,7 +194,6 @@ def init_config_files(self):
app.profile = self.profile
app.init_profile_dir()
app.init_config_files()
- print 'tic'
def stage_default_config_file(self):
pass
Please sign in to comment.
Something went wrong with that request. Please try again.