]> mj.ucw.cz Git - moe.git/commitdiff
Better error reporting on the pipeline
authorMartin Mares <mj@ucw.cz>
Sun, 9 Aug 2009 13:11:25 +0000 (15:11 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 9 Aug 2009 13:11:25 +0000 (15:11 +0200)
t/moe/pipeline.py
t/test.py

index 1804c5bec732562b718fee667d0b78c4e606a634..30c4c587e4417bb71c0d0114b1a1a7c65951729f 100644 (file)
@@ -5,6 +5,9 @@ import bisect
 import imp
 import moe.log
 
+class MoePipeError(Exception):
+    """Failure of the MoePipeline."""
+
 class MoePipeline:
     """Moe pipeline."""
 
@@ -17,7 +20,7 @@ class MoePipeline:
        triple = (pri,name,fun)
        pos = bisect.bisect(self.pipe, triple)
        if pos <= self.index:
-           raise RuntimeError, "MoePipeline.insert cannot alter the past"
+           raise MoePipeError, "Pipeline insert cannot alter the past"
        self.pipe.insert(pos, triple)
 
     def dump(self, file=sys.stdout):
@@ -38,7 +41,11 @@ class MoePipeline:
        modname = "moe.hooks." + name
        moe.log.verbose(">> Loading hook %s\n" % name)
        if not sys.modules.has_key(modname):
-           fp, path, desc = imp.find_module(name, ["moe/hooks"])
+           ## FIXME: Configuration variable for the hook directory?
+           try:
+               fp, path, desc = imp.find_module(name, ["moe/hooks"])
+           except ImportError:
+               raise MoePipeError, "Cannot find hook module " + modname
            try:
                imp.load_module(modname, fp, path, desc)
            finally:
index 17403958e76dac023be73c2d407b540243327562..72507206d3178eda0c8c0d934b78a99b97363f02 100755 (executable)
--- a/t/test.py
+++ b/t/test.py
@@ -6,6 +6,7 @@ sys.path.append('.')
 import moe.meta
 import moe.config
 import moe.eval
+import moe.pipeline
 
 #m = moe.meta.MoeMeta()
 #m['a'] = '1'
@@ -29,4 +30,9 @@ s.dump_defs()
 print "***"
 s.dump()
 
-print moe.eval.init_pipeline(s, 'stk_')
+p = moe.pipeline.MoePipeline('test')
+p.insert(10, 'brum', lambda x: p.insert(30, 'xyzzy', lambda y:y))
+p.insert(20, 'brummm', lambda x: x)
+p.configure("y")
+p.dump()
+p.run(5)