##// END OF EJS Templates
Allow a raise on bad config using env variable....
Matthias Bussonnier -
Show More
@@ -43,6 +43,16 b' else:'
43 "/etc/ipython",
43 "/etc/ipython",
44 ]
44 ]
45
45
46 _envvar = os.environ.get('IPYTHON_SUPPRESS_ERRORS')
47 if _envvar in {None, ''}:
48 IPYTHON_SUPPRESS_ERRORS = None
49 else:
50 if _envvar.lower() in {'1','true'}:
51 IPYTHON_SUPPRESS_ERRORS = True
52 elif _envvar.lower() in {'0','false'} :
53 IPYTHON_SUPPRESS_ERRORS = False
54 else:
55 sys.exit("Unsupported value for environment variable: 'IPYTHON_SUPPRESS_ERRORS' is set to '%s' which is none of {'0', '1', 'false', 'true', ''}."% _envvar )
46
56
47 # aliases and flags
57 # aliases and flags
48
58
@@ -272,18 +282,33 b' class BaseIPythonApplication(Application):'
272 self.log.error("couldn't create path %s: %s", path, e)
282 self.log.error("couldn't create path %s: %s", path, e)
273 self.log.debug("IPYTHONDIR set to: %s" % new)
283 self.log.debug("IPYTHONDIR set to: %s" % new)
274
284
275 def load_config_file(self, suppress_errors=True):
285 def load_config_file(self, suppress_errors=IPYTHON_SUPPRESS_ERRORS):
276 """Load the config file.
286 """Load the config file.
277
287
278 By default, errors in loading config are handled, and a warning
288 By default, errors in loading config are handled, and a warning
279 printed on screen. For testing, the suppress_errors option is set
289 printed on screen. For testing, the suppress_errors option is set
280 to False, so errors will make tests fail.
290 to False, so errors will make tests fail.
291
292 `supress_errors` default value is to be `None` in which case the
293 behavior default to the one of `traitlets.Application`.
294
295 The default value can be changed :
296 - to `False` by setting 'IPYTHON_SUPPRESS_ERRORS' environment variable to '0', or 'false' (case insensitive).
297 - to `True` by setting 'IPYTHON_SUPPRESS_ERRORS' environment variable to '1' or 'true' (case insensitive).
298 - to `None` by setting 'IPYTHON_SUPPRESS_ERRORS' environment variable to '' (empty string) or leaving it unset.
299
300 Any other value are invalid, and will make IPython exit with a non-zero return code.
281 """
301 """
302
303
282 self.log.debug("Searching path %s for config files", self.config_file_paths)
304 self.log.debug("Searching path %s for config files", self.config_file_paths)
283 base_config = 'ipython_config.py'
305 base_config = 'ipython_config.py'
284 self.log.debug("Attempting to load config file: %s" %
306 self.log.debug("Attempting to load config file: %s" %
285 base_config)
307 base_config)
286 try:
308 try:
309 if suppress_errors is not None:
310 old_value = Application.raise_config_file_errors
311 Application.raise_config_file_errors = not suppress_errors;
287 Application.load_config_file(
312 Application.load_config_file(
288 self,
313 self,
289 base_config,
314 base_config,
@@ -293,6 +318,8 b' class BaseIPythonApplication(Application):'
293 # ignore errors loading parent
318 # ignore errors loading parent
294 self.log.debug("Config file %s not found", base_config)
319 self.log.debug("Config file %s not found", base_config)
295 pass
320 pass
321 if suppress_errors is not None:
322 Application.raise_config_file_errors = old_value
296
323
297 for config_file_name in self.config_files:
324 for config_file_name in self.config_files:
298 if not config_file_name or config_file_name == base_config:
325 if not config_file_name or config_file_name == base_config:
General Comments 0
You need to be logged in to leave comments. Login now