Index: recipe_engine/loader.py |
diff --git a/recipe_engine/loader.py b/recipe_engine/loader.py |
index e8b67258781b23872108043f4f193f2370d3c147..7103daa3f6168a4008619367f7454a868a111ef4 100644 |
--- a/recipe_engine/loader.py |
+++ b/recipe_engine/loader.py |
@@ -131,9 +131,13 @@ class PackageDependency(PathDependency): |
class RecipeUniverse(object): |
- def __init__(self, package_deps): |
+ def __init__(self, package_deps, config_file): |
self._loaded = {} |
self._package_deps = package_deps |
+ self._config_file = config_file |
luqui
2015/11/16 20:47:59
I don't see where ._config_file is used.
martiniss
2015/11/18 01:00:00
Used for something else. Not needed, so I deleted.
|
+ |
+ def copy(self): |
+ return RecipeUniverse(self._package_deps, self._config_file) |
@property |
def module_dirs(self): |
@@ -406,6 +410,30 @@ class DependencyMapper(object): |
self._instances[mod] = self._instantiator(mod, deps_dict) |
return self._instances[mod] |
+def _invoke_with_properties(callable_obj, all_props, prop_defs, arg_names, |
+ **additional_args): |
+ for name, prop in prop_defs.items(): |
+ if not isinstance(prop, BoundProperty): |
+ raise ValueError( |
+ "You tried to invoke {} with an unbound Property {} named {}".format( |
+ callable, prop, name)) |
+ |
+ props = [] |
+ for arg in arg_names: |
+ if arg in additional_args: |
+ props.append(additional_args.pop(arg)) |
+ continue |
+ |
+ if arg not in prop_defs: |
+ raise UndefinedPropertyException( |
+ "Missing property definition for '{}'.".format(arg)) |
+ |
+ prop = prop_defs[arg] |
+ props.append(prop.interpret(all_props.get( |
+ prop.param_name, PROPERTY_SENTINEL))) |
+ |
+ return callable_obj(*props, **additional_args) |
+ |
def invoke_with_properties(callable_obj, all_props, prop_defs, |
**additional_args): |
""" |
@@ -428,39 +456,21 @@ def invoke_with_properties(callable_obj, all_props, prop_defs, |
""" |
# Check that we got passed BoundProperties, and not Properties |
- for name, prop in prop_defs.items(): |
- if not isinstance(prop, BoundProperty): |
- raise ValueError( |
- "You tried to invoke {} with an unbound Property {} named {}".format( |
- callable, prop, name)) |
# To detect when they didn't specify a property that they have as a |
# function argument, list the arguments, through inspection, |
# and then comparing this list to the provided properties. We use a list |
# instead of a dict because getargspec returns a list which we would have to |
# convert to a dictionary, and the benefit of the dictionary is pretty small. |
- props = [] |
if inspect.isclass(callable_obj): |
arg_names = inspect.getargspec(callable_obj.__init__).args |
arg_names.pop(0) |
else: |
arg_names = inspect.getargspec(callable_obj).args |
+ return _invoke_with_properties(callable_obj, all_props, prop_defs, arg_names, |
+ **additional_args) |
- for arg in arg_names: |
- if arg in additional_args: |
- props.append(additional_args.pop(arg)) |
- continue |
- |
- if arg not in prop_defs: |
- raise UndefinedPropertyException( |
- "Missing property definition for '{}'.".format(arg)) |
- |
- prop = prop_defs[arg] |
- props.append(prop.interpret(all_props.get( |
- prop.param_name, PROPERTY_SENTINEL))) |
- |
- return callable_obj(*props, **additional_args) |
def create_recipe_api(toplevel_deps, engine, test_data=DisabledTestData()): |
def instantiator(mod, deps): |