import moe.log
import moe.status
import moe.pipeline
-import moe.batch
import moe.util
import os.path
import shutil
self.debug_dump_config()
# insert hooks into main pipeline
- self.main_pipe.insert(5, "Eval.hook_init_dirs", hook_init_dirs)
- self.main_pipe.insert(15, "Eval.hook_load_task_config", hook_load_task_config)
- self.main_pipe.insert(20, "Eval.hook_init_tasktype", hook_init_tasktype)
- self.main_pipe.insert(90, "Eval.hook_write_metadata", hook_write_metadata)
+ self.main_pipe.insert(5, hook_init_dirs, "Initialize working directories")
+ self.main_pipe.insert(15, hook_load_task_config, "Load task config")
+ self.main_pipe.insert(20, hook_init_tasktype, "Load tasktype module")
+ self.main_pipe.insert(90, hook_write_metadata, "Write final metadata file")
# ininialize extensions (let them insert hooks)
self.config.fix('EXTENSIONS')
e.log.debug('Writing status file %s', e['STATUS_FILE'])
with open(e['STATUS_FILE'], 'w') as f:
e.status.write(f)
- # TODO: dump to ddebug
def hook_m_0(e):
e.log.info('Hey! It\'s me, the dummy extension in your main pipeline! (at time 0)')
- e.main_pipe.insert(0, 'exts.dummy.hook_m_0', hook_m_0)
+ e.main_pipe.insert(0, hook_m_0)
def hook_m_79(e):
e.log.info('Me, the dummy extension, requies no cleanup! (at time 79)')
- e.main_pipe.insert(79, 'exts.dummy.hook_m_79', hook_m_79)
+ e.main_pipe.insert(79, hook_m_79)
def hook_t_42(e):
t = 'It\'s test %s and the dummy extension did nothing! (at time 42)' % e['TEST']
e.log.info(t)
e.log.user.info(t)
- e.test_pipe.insert(42, 'exts.dummy.hook_t_42', hook_t_42)
+ e.test_pipe.insert(42, hook_t_42)
self.name = name
self.skip_to = skip_to
- def insert(self, pri, name, fun):
- "Insert callable `fun` to time `pri`, `name` is only informative."
+ def insert(self, pri, fun, desc='', name=None):
+ """Insert callable `fun` to time `pri`,
+ `desc` is optional description,
+ `name` is the "module.function" name, guessed by default.
+ """
assert(isinstance(pri, int))
assert(callable(fun))
- triple = (pri, name, fun)
+ if name is None:
+ name = fun.__module__ + '.' + fun.__name__
+ if desc:
+ desc += ' '
+ desc += '[' + name + ']'
+
+ triple = (pri, desc, fun)
pos = bisect.bisect(self.pipe, triple)
if pos <= self.index:
raise MoePipeError, "Pipeline %r at time %d: Insert cannot alter the past (time %d)" \
"""
l=["%s >>> Pipeline %s" % (prefix, self.name)]
for pri, name, fun in self.pipe:
- l.append("%s% 3d %s, %s" % (prefix, pri, name, fun))
+ l.append("%s% 3d %s" % (prefix, pri, name))
return l
def run(self, *args, **kwargs):
"""
import moe.config
+import moe.testutils
def init(e):
def hook_m_50(e):
e.log.info('Here should be compiling')
- e.main_pipe.insert(50, 'dummy tasktype hook_m_50', hook_m_50)
+ e.main_pipe.insert(50, hook_m_50)
- def hook_m_60(e):
- e.log.info('Here we run test pipeline')
- tests = e['TESTS'].split()
- for t in tests:
- e.log.info('Running test %s' % t)
- e.log.user.info('TEST %s ...' % t)
- with e.config.parse("TEST='"+t+"'", level=70, source='<dummy tasktype>'):
- e.test_pipe.run(e=e)
- ## The old (but proper, as the above is vulnerable to injections by including "'" !) way was:
- #op = moe.config.Operation('SET', None, moe.config.ConfigExpression([t]), level=70, source='<dummy tasktype>')
- #testvar = e.config.lookup('TEST')
- ## Add and remove operation setting 'TEST="..."'
- #testvar.add_operation(op)
- #e.test_pipe.run(e=e)
- #testvar.remove_operation(op)
-
- e.main_pipe.insert(60, 'dummy tasktype hook_m_60', hook_m_60)
+ e.main_pipe.insert(60, moe.testutils.hook_run_tests, desc='Run testcases')
def hook_t_30(e):
e.log.info("Maybe we should do something? Nah...")
- e.test_pipe.insert(30, 'dummy tasktype hook_t_30', hook_t_30)
+ e.test_pipe.insert(30, hook_t_30)