From fd12dbf19a5c5736712bbf395f9c699ffc78229b Mon Sep 17 00:00:00 2001 From: Aleksey Maksimov Date: Thu, 16 Aug 2012 10:42:58 +0200 Subject: [PATCH] Fix: full pathname will be shown on exception * instead of 'library' actual module will be shown * instead of 'recipe' actual module will be shown --- kokki/command.py | 6 +++--- kokki/kitchen.py | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/kokki/command.py b/kokki/command.py index e7086b7..97d0f9e 100644 --- a/kokki/command.py +++ b/kokki/command.py @@ -61,7 +61,7 @@ def main(): globs["__file__"] = os.path.abspath(fname) with open(fname, "rb") as fp: source = fp.read() - exec compile(source, fname, 'exec') in globs + exec compile(source, os.path.abspath(fname), 'exec') in globs del globs['__file__'] kit = Kitchen() @@ -74,7 +74,7 @@ def main(): sys.exit(1) for r in roles: r(kit) - + for over in options.overrides: name, value = over.split('=', 1) try: @@ -82,7 +82,7 @@ def main(): except ValueError: pass kit.update_config({name: value}) - + if options.dump: if ':' in options.dump: fmt, filename = options.dump.split(':', 1) diff --git a/kokki/kitchen.py b/kokki/kitchen.py index dbd16e7..0f1a042 100644 --- a/kokki/kitchen.py +++ b/kokki/kitchen.py @@ -47,8 +47,8 @@ def library(self): path = os.path.join(libpath, f) with open(path, "rb") as fp: source = fp.read() - exec compile(source, libpath, "exec") in globs - + exec compile(source, path, "exec") in globs + self._library = AttributeDictionary(globs) return self._library @@ -58,7 +58,7 @@ def get_recipe(self, name): raise Fail("Recipe %s in cookbook %s not found" % (name, self.name)) with open(path, "rb") as fp: - return fp.read() + return fp.read(), path def __getattr__(self, name): return self.library[name] @@ -76,7 +76,7 @@ def __unicode__(self): class Kitchen(Environment): def __init__(self): super(Kitchen, self).__init__() - self.included_recipes_order = [] + self.included_recipes_order = [] self.included_recipes = {} self.sourced_recipes = set() self.cookbooks = AttributeDictionary() @@ -121,7 +121,7 @@ def include_recipe(self, *args): cookbook, recipe = name.split('.') except ValueError: cookbook, recipe = name, "default" - + try: cb = self.cookbooks[cookbook] except KeyError: @@ -142,10 +142,10 @@ def source_recipe(self, cookbook, recipe): self.sourced_recipes.add(name) cookbook.loader(self) - rc = cookbook.get_recipe(recipe) + rc, path = cookbook.get_recipe(recipe) globs = {'env': self} with self: - exec compile(rc, name, 'exec') in globs + exec compile(rc, path, 'exec') in globs def prerun(self): for name in self.included_recipes_order: