##// END OF EJS Templates
add extra_config_file...
MinRK -
Show More
@@ -39,7 +39,7 b' from IPython.config.loader import ConfigFileNotFound'
39 39 from IPython.core import release, crashhandler
40 40 from IPython.core.profiledir import ProfileDir, ProfileDirError
41 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 45 # Classes and functions
@@ -56,6 +56,7 b' base_aliases = {'
56 56 'profile' : 'BaseIPythonApplication.profile',
57 57 'ipython-dir' : 'BaseIPythonApplication.ipython_dir',
58 58 'log-level' : 'Application.log_level',
59 'config' : 'BaseIPythonApplication.extra_config_file',
59 60 }
60 61
61 62 base_flags = dict(
@@ -84,14 +85,14 b' class BaseIPythonApplication(Application):'
84 85
85 86 # Track whether the config_file has changed,
86 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 90 config_file_name = Unicode(u'ipython_config.py')
90 91 def _config_file_name_default(self):
91 92 return self.name.replace('-','_') + u'_config.py'
92 93 def _config_file_name_changed(self, name, old, new):
93 94 if new != old:
94 self.config_file_specified = True
95 self.config_file_specified.add(new)
95 96
96 97 # The directory that contains IPython's builtin profiles.
97 98 builtin_profile_dir = Unicode(
@@ -102,6 +103,19 b' class BaseIPythonApplication(Application):'
102 103 def _config_file_paths_default(self):
103 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 119 profile = Unicode(u'default', config=True,
106 120 help="""The IPython profile to use."""
107 121 )
@@ -216,30 +230,31 b' class BaseIPythonApplication(Application):'
216 230 # ignore errors loading parent
217 231 self.log.debug("Config file %s not found", base_config)
218 232 pass
219 if self.config_file_name == base_config:
220 # don't load secondary config
221 return
222 self.log.debug("Attempting to load config file: %s" %
223 self.config_file_name)
224 try:
225 Application.load_config_file(
226 self,
227 self.config_file_name,
228 path=self.config_file_paths
229 )
230 except ConfigFileNotFound:
231 # Only warn if the default config file was NOT being used.
232 if self.config_file_specified:
233 msg = self.log.warn
234 else:
235 msg = self.log.debug
236 msg("Config file not found, skipping: %s", self.config_file_name)
237 except:
238 # For testing purposes.
239 if not suppress_errors:
240 raise
241 self.log.warn("Error loading config file: %s" %
242 self.config_file_name, exc_info=True)
233
234 for config_file_name in self.config_files:
235 if not config_file_name or config_file_name == base_config:
236 continue
237 self.log.debug("Attempting to load config file: %s" %
238 self.config_file_name)
239 try:
240 Application.load_config_file(
241 self,
242 config_file_name,
243 path=self.config_file_paths
244 )
245 except ConfigFileNotFound:
246 # Only warn if the default config file was NOT being used.
247 if config_file_name in self.config_file_specified:
248 msg = self.log.warn
249 else:
250 msg = self.log.debug
251 msg("Config file not found, skipping: %s", config_file_name)
252 except:
253 # For testing purposes.
254 if not suppress_errors:
255 raise
256 self.log.warn("Error loading config file: %s" %
257 self.config_file_name, exc_info=True)
243 258
244 259 def init_profile_dir(self):
245 260 """initialize the profile dir"""
General Comments 0
You need to be logged in to leave comments. Login now