Permalink
Browse files

added feature selection helpers select(..) and select_equation(..)

  • Loading branch information...
1 parent ffa92bc commit dcacab766a0012033f032e50e7c6d5dcdecba4d3 @henzk committed Mar 26, 2012
Showing with 34 additions and 3 deletions.
  1. +2 −1 featuremonkey/__init__.py
  2. +32 −2 featuremonkey/composer.py
View
3 featuremonkey/__init__.py
@@ -1 +1,2 @@
-from featuremonkey.composer import compose, compose_later
+from featuremonkey.composer import compose, compose_later,\
+ select, select_equation
View
34 featuremonkey/composer.py
@@ -11,8 +11,6 @@ def original_wrapper(throwaway, *args, **kws):
return to(*args, **kws)
return original_wrapper
-#class
-
def is_class_instance(obj):
return not inspect.isclass(obj) and not inspect.ismodule(obj)
@@ -127,9 +125,41 @@ def load_module(self, module_name):
return module
def compose_later(*things):
+ """
+ register list of things for composition using compose()
+
+ compose_later takes a list of fsts. The last element specifies the base module as string
+ things are composed directly after the base module is imported by application code
+ """
if len(things) == 1:
return things[0]
module_name = things[-1]
LazyComposer.add(module_name, things[:-1])
+#register import hook
sys.meta_path.append(LazyComposer())
+
+def select(*features):
+ """
+ selects the features given as string
+ e.g
+ passing 'hello' and 'world' will result in imports of 'hello' and 'world'.
+ Then, if possible 'hello.feature' and 'world.feature' are imported and select is called
+ in each feature module.
+ """
+ for feature_name in features:
+ feature_module = importlib.import_module(feature_name)
+ #if available, import feature.py and select the feature
+ try:
+ feature_spec_module = importlib.import_module(feature_name + '.feature')
+ feature_spec_module.select()
+ except ImportError:
+ pass
+
+def select_equation(filename):
+ features = []
+ for line in open(filename):
+ line = line.strip()
+ if line and not line.startswith('#'):
+ features.append(line)
+ select(*features)

0 comments on commit dcacab7

Please sign in to comment.