From 184a1d862089a66f7cab486c607f428b098c94af Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Fri, 24 Sep 2010 16:10:46 +0200 Subject: [PATCH] Changed pipeline.insert syntax - now guesses the function name --- t/moe/eval.py | 10 ++++------ t/moe/exts/dummy.py | 6 +++--- t/moe/pipeline.py | 17 +++++++++++++---- t/moe/tasktypes/dummy.py | 23 ++++------------------- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/t/moe/eval.py b/t/moe/eval.py index 5eaa110..3e22c82 100644 --- a/t/moe/eval.py +++ b/t/moe/eval.py @@ -6,7 +6,6 @@ import moe.box import moe.log import moe.status import moe.pipeline -import moe.batch import moe.util import os.path import shutil @@ -52,10 +51,10 @@ class Eval: 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') @@ -139,7 +138,6 @@ def hook_write_metadata(e): 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 diff --git a/t/moe/exts/dummy.py b/t/moe/exts/dummy.py index 3ec5816..b6be3bb 100644 --- a/t/moe/exts/dummy.py +++ b/t/moe/exts/dummy.py @@ -10,16 +10,16 @@ def init(e): 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) diff --git a/t/moe/pipeline.py b/t/moe/pipeline.py index e813820..1b2d98a 100644 --- a/t/moe/pipeline.py +++ b/t/moe/pipeline.py @@ -22,11 +22,20 @@ class Pipeline: 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)" \ @@ -40,7 +49,7 @@ class Pipeline: """ 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): diff --git a/t/moe/tasktypes/dummy.py b/t/moe/tasktypes/dummy.py index 72293c3..b8fa942 100644 --- a/t/moe/tasktypes/dummy.py +++ b/t/moe/tasktypes/dummy.py @@ -7,33 +7,18 @@ Runs the test pipeline for each TEST """ 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=''): - 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='') - #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) -- 2.39.2