Skip to content

Commit

Permalink
better error messages when defining an experiment in interactive envi…
Browse files Browse the repository at this point in the history
…ronment without a name.
  • Loading branch information
Qwlouse committed Dec 1, 2016
1 parent c4220c9 commit 958e50b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions sacred/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ def __init__(self, name=None, ingredients=(), interactive=False):
source-code or reliable reproduction of the runs.
"""
caller_globals = inspect.stack()[1][0].f_globals
if name is None and interactive:
raise(RuntimeError('name is required in interactive mode.'))
elif name is None:
name = os.path.basename(caller_globals['__file__'])
if name is None:
if interactive:
raise RuntimeError('name is required in interactive mode.')
mainfile = caller_globals.get('__file__')
if mainfile is None:
raise RuntimeError('No main-file found. Are you running in '
'interactive mode? If so please provide a '
'name and set interactive=True.')
name = os.path.basename(mainfile)
if name.endswith('.py'):
name = name[:-3]
elif name.endswith('.pyc'):
Expand Down
2 changes: 1 addition & 1 deletion sacred/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, path, ingredients=(), interactive=False,
self.commands = OrderedDict()
# capture some context information
_caller_globals = _caller_globals or inspect.stack()[1][0].f_globals
mainfile_name = _caller_globals.get('__file__')
mainfile_name = _caller_globals.get('__file__', '.')
self.base_dir = os.path.dirname(os.path.abspath(mainfile_name))
self.doc = _caller_globals.get('__doc__', "")
self.sources, self.dependencies = \
Expand Down

0 comments on commit 958e50b

Please sign in to comment.