##// END OF EJS Templates
add extra_config_file...
MinRK -
Show More
@@ -39,7 +39,7 b' from IPython.config.loader import ConfigFileNotFound'
39 from IPython.core import release, crashhandler
39 from IPython.core import release, crashhandler
40 from IPython.core.profiledir import ProfileDir, ProfileDirError
40 from IPython.core.profiledir import ProfileDir, ProfileDirError
41 from IPython.utils.path import get_ipython_dir, get_ipython_package_dir
41 from IPython.utils.path import get_ipython_dir, get_ipython_package_dir
42 from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict
42 from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, Set
43
43
44 #-----------------------------------------------------------------------------
44 #-----------------------------------------------------------------------------
45 # Classes and functions
45 # Classes and functions
@@ -56,6 +56,7 b' base_aliases = {'
56 'profile' : 'BaseIPythonApplication.profile',
56 'profile' : 'BaseIPythonApplication.profile',
57 'ipython-dir' : 'BaseIPythonApplication.ipython_dir',
57 'ipython-dir' : 'BaseIPythonApplication.ipython_dir',
58 'log-level' : 'Application.log_level',
58 'log-level' : 'Application.log_level',
59 'config' : 'BaseIPythonApplication.extra_config_file',
59 }
60 }
60
61
61 base_flags = dict(
62 base_flags = dict(
@@ -84,14 +85,14 b' class BaseIPythonApplication(Application):'
84
85
85 # Track whether the config_file has changed,
86 # Track whether the config_file has changed,
86 # because some logic happens only if we aren't using the default.
87 # because some logic happens only if we aren't using the default.
87 config_file_specified = Bool(False)
88 config_file_specified = Set()
88
89
89 config_file_name = Unicode(u'ipython_config.py')
90 config_file_name = Unicode(u'ipython_config.py')
90 def _config_file_name_default(self):
91 def _config_file_name_default(self):
91 return self.name.replace('-','_') + u'_config.py'
92 return self.name.replace('-','_') + u'_config.py'
92 def _config_file_name_changed(self, name, old, new):
93 def _config_file_name_changed(self, name, old, new):
93 if new != old:
94 if new != old:
94 self.config_file_specified = True
95 self.config_file_specified.add(new)
95
96
96 # The directory that contains IPython's builtin profiles.
97 # The directory that contains IPython's builtin profiles.
97 builtin_profile_dir = Unicode(
98 builtin_profile_dir = Unicode(
@@ -102,6 +103,19 b' class BaseIPythonApplication(Application):'
102 def _config_file_paths_default(self):
103 def _config_file_paths_default(self):
103 return [os.getcwdu()]
104 return [os.getcwdu()]
104
105
106 extra_config_file = Unicode(config=True,
107 help="""Path to an extra config file to load.
108
109 If specified, load this config file in addition to any other IPython config.
110 """)
111 def _extra_config_file_changed(self, name, old, new):
112 try:
113 self.config_files.remove(old)
114 except ValueError:
115 pass
116 self.config_file_specified.add(new)
117 self.config_files.append(new)
118
105 profile = Unicode(u'default', config=True,
119 profile = Unicode(u'default', config=True,
106 help="""The IPython profile to use."""
120 help="""The IPython profile to use."""
107 )
121 )
@@ -216,30 +230,31 b' class BaseIPythonApplication(Application):'
216 # ignore errors loading parent
230 # ignore errors loading parent
217 self.log.debug("Config file %s not found", base_config)
231 self.log.debug("Config file %s not found", base_config)
218 pass
232 pass
219 if self.config_file_name == base_config:
233
220 # don't load secondary config
234 for config_file_name in self.config_files:
221 return
235 if not config_file_name or config_file_name == base_config:
222 self.log.debug("Attempting to load config file: %s" %
236 continue
223 self.config_file_name)
237 self.log.debug("Attempting to load config file: %s" %
224 try:
238 self.config_file_name)
225 Application.load_config_file(
239 try:
226 self,
240 Application.load_config_file(
227 self.config_file_name,
241 self,
228 path=self.config_file_paths
242 config_file_name,
229 )
243 path=self.config_file_paths
230 except ConfigFileNotFound:
244 )
231 # Only warn if the default config file was NOT being used.
245 except ConfigFileNotFound:
232 if self.config_file_specified:
246 # Only warn if the default config file was NOT being used.
233 msg = self.log.warn
247 if config_file_name in self.config_file_specified:
234 else:
248 msg = self.log.warn
235 msg = self.log.debug
249 else:
236 msg("Config file not found, skipping: %s", self.config_file_name)
250 msg = self.log.debug
237 except:
251 msg("Config file not found, skipping: %s", config_file_name)
238 # For testing purposes.
252 except:
239 if not suppress_errors:
253 # For testing purposes.
240 raise
254 if not suppress_errors:
241 self.log.warn("Error loading config file: %s" %
255 raise
242 self.config_file_name, exc_info=True)
256 self.log.warn("Error loading config file: %s" %
257 self.config_file_name, exc_info=True)
243
258
244 def init_profile_dir(self):
259 def init_profile_dir(self):
245 """initialize the profile dir"""
260 """initialize the profile dir"""
General Comments 0
You need to be logged in to leave comments. Login now