Skip to content

Commit

Permalink
fixed the caller_global extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwlouse committed Sep 1, 2014
1 parent 21129cd commit 54516e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sacred/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

from __about__ import *

from experiment import Experiment
from experiment import Experiment, Ingredient

15 changes: 9 additions & 6 deletions sacred/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ class CircularDependencyError(Exception):


class Ingredient(object):
def __init__(self, path, ingredients=(), gen_seed=False):
def __init__(self, path, ingredients=(), gen_seed=False,
caller_globals=None):
self.path = path
self.cfgs = []
self.ingredients = list(ingredients)
self.gen_seed = gen_seed
self.captured_functions = []
self._is_traversing = False
main_globals = inspect.stack()[2][0].f_globals
self.doc = main_globals.get('__doc__') or ""
self.mainfile = main_globals.get('__file__') or ""
caller_globals = caller_globals or inspect.stack()[1][0].f_globals
self.doc = caller_globals.get('__doc__') or ""
self.mainfile = caller_globals.get('__file__') or ""
if self.mainfile:
self.mainfile = os.path.abspath(self.mainfile)
self.dependencies = get_dependencies(main_globals)
self.dependencies = get_dependencies(caller_globals)

############################## Decorators ##################################
# def command(self, f):
Expand Down Expand Up @@ -70,9 +71,11 @@ def traverse_ingredients(self):

class Experiment(Ingredient):
def __init__(self, name, ingredients=()):
caller_globals = inspect.stack()[1][0].f_globals
super(Experiment, self).__init__(path=name,
ingredients=ingredients,
gen_seed=True)
gen_seed=True,
caller_globals=caller_globals)
self.name = name
self.default_command = None
self.logger = None
Expand Down

0 comments on commit 54516e2

Please sign in to comment.