]> mj.ucw.cz Git - eval.git/commitdiff
First attempts at the evaluation overlord
authorMartin Mares <mj@ucw.cz>
Sun, 9 Aug 2009 14:33:30 +0000 (16:33 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 9 Aug 2009 14:33:30 +0000 (16:33 +0200)
t/config [new file with mode: 0644]
t/moe/batch.py [new file with mode: 0644]
t/moe/config.py
t/moe/eval.py
t/test.py

diff --git a/t/config b/t/config
new file mode 100644 (file)
index 0000000..910dfcb
--- /dev/null
+++ b/t/config
@@ -0,0 +1,8 @@
+# HOME set automatically
+# CONTESTANT set automatically
+# TASK set automatically
+TASK_DIR="${HOME}/problems/${TASK}"
+SOL_DIR="${HOME}/solutions/${CONTESTANT}/${TASK}"
+TEST_DIR="${HOME}/testing/${CONTESTANT}/${TASK}"
+
+TASK_TYPE=batch
diff --git a/t/moe/batch.py b/t/moe/batch.py
new file mode 100644 (file)
index 0000000..7fcfd7a
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+
+def compile(e):
+    pass
+
+def tests(e):
+    pass
+
+def locate(e, file=None):
+    pass
index 7d9da30fb66a53b6205cac4f01589bfdd9294d96..4baee06494fb2d675ef3db4be9955701a24b9549 100644 (file)
@@ -28,6 +28,9 @@ class MoeConfig:
            else:
                self.load(file)
 
+    def set(self, k, v):
+       self.vars[k] = [("s", v)]
+
     def parse_line(self, x):
        x = x.rstrip("\n").lstrip(" \t")
        if x=="" or x.startswith("#"):
@@ -138,7 +141,8 @@ class MoeConfigStack:
        self.in_progress[k] = 1;
         v = self.do_get(k, len(self.stk)-1)
        del self.in_progress[k]
-       self.cache[k] = v
+       ## FIXME: This is disabled, because the immutability invariant is broken!
+       # self.cache[k] = v
        return v
 
     def do_get(self, k, pos):
index e5d8d0410764c1e4d8012202222fd418cbff485d..9dd4c8287d96d700f5572f4d991f1f78519f61d8 100644 (file)
@@ -1,3 +1,65 @@
 #!/usr/bin/env python
 
 import moe.config
+import moe.log
+import moe.meta
+import moe.pipeline
+import moe.batch
+import moe.util
+import os.path
+import shutil
+
+class MoeEvalErr(Exception):
+    pass
+
+class Eval:
+
+    def __init__(self):
+       self.cfgs = moe.config.MoeConfigStack()
+       self.builtins = moe.config.MoeConfig()
+       self.cfgs.push(self.builtins)
+       self.main_pipe = moe.pipeline.MoePipeline("main")
+       self.meta = moe.meta.MoeMeta()
+       pass
+
+    def init(self):
+       self.init_global()
+       ## FIXME: Configuration overrides
+       self.init_test()
+       ## FIXME: Initialize logging early on
+       self.init_task()
+
+    def init_global(self):
+       main_cfg = moe.config.MoeConfig(name = os.path.join(self.cfgs['HOME'], "config"))
+       self.cfgs.push(main_cfg)
+
+    def init_test(self):
+       test = self.cfgs['TEST_DIR']
+       if os.path.isdir(test):
+           shutil.rmtree(test)
+       try:
+           moe.util.mkdir_tree(test)   
+       except OSError, e:
+           raise MoeEvalErr, "Cannot create %s: %s" % (test, e.strerror)
+
+    def init_task(self):
+       task = self.cfgs['TASK']
+       task_dir = self.cfgs['TASK_DIR']
+       if not os.path.isdir(task_dir):
+           raise MoeEvalErr, "No such task %s" % task
+       task_cfg = moe.config.MoeConfig(name = os.path.join(task_dir, "config"))
+       self.cfgs.push(task_cfg)
+
+       type = self.cfgs['TASK_TYPE']
+       if type == "batch" or type == "interactive":
+           self.main_pipe.insert(100, "compile", moe.batch.compile)
+           self.main_pipe.insert(200, "batch-tests", moe.batch.tests)
+       elif type == "opendata":
+           raise MoeEvalErr, "Opendata tasks not implemented yet"
+       else:
+           raise MoeEvalErr, "Unknown task type " + type
+
+    def run(self):
+       self.main_pipe.configure(self.cfgs["HOOKS"])
+       self.main_pipe.dump()
+       self.main_pipe.run(self)
index 72507206d3178eda0c8c0d934b78a99b97363f02..005ba39f77ee16455f57e24d40db30a0feb4efbc 100755 (executable)
--- a/t/test.py
+++ b/t/test.py
@@ -7,32 +7,18 @@ import moe.meta
 import moe.config
 import moe.eval
 import moe.pipeline
+import moe.batch
 
-#m = moe.meta.MoeMeta()
-#m['a'] = '1'
-#m.write()
+e = moe.eval.Eval()
+e.builtins.set("HOME", ".")
+e.builtins.set("TASK", "sum")
+e.builtins.set("CONTESTANT", "somebody")
+e.init()
 
-c = moe.config.MoeConfig(name='/dev/stdin')
-c.dump()
+print "Task configuration:"
+e.cfgs.dump()
+print
 
-#d = moe.config.MoeConfig(name='/dev/stdin')
-#d.dump()
+moe.batch.locate(e)
 
-s = moe.config.MoeConfigStack()
-s.push(c)
-#s.push(d)
-
-s.dump_defs()
-
-#s.apply_overrides("x_")
-#s.dump_defs()
-
-print "***"
-s.dump()
-
-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)
+e.run()