From a5b8f99d4e626557c71f4f6091ae67bec21aa339 Mon Sep 17 00:00:00 2001 From: Brad Dixon Date: Sun, 30 Jun 2019 12:40:26 -0400 Subject: [PATCH] Bind delayed task creating functions to the object instance. The @create_after decorator stashes a reference to the unbound method in a DelayedLoader instance. To work with tasks defined by methods the reference must be bound to the task creating class instance. --- doit/loader.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/doit/loader.py b/doit/loader.py index 5b7f2566..dd86e347 100644 --- a/doit/loader.py +++ b/doit/loader.py @@ -136,7 +136,15 @@ def load_tasks(namespace, command_names=(), allow_delayed=False): task_list = [] def _process_gen(): task_list.extend(generate_tasks(name, ref(), ref.__doc__)) - def _add_delayed(tname): + def _add_delayed(tname, ref): + # If ref is a bound method this updates the DelayedLoader specification + # so that when delayed.creator is executed later (control.py:469) the + # self parameter is provided. control.py:469 may execute this function + # with any additional parameters. + # + # If ref is NOT a method this this line simply re-assigns the + # same function. + delayed.creator = ref task_list.append(Task(tname, None, loader=delayed, doc=delayed.creator.__doc__)) @@ -147,9 +155,9 @@ def _add_delayed(tname): _process_gen() elif delayed.creates: # delayed with explicit task basename for tname in delayed.creates: - _add_delayed(tname) + _add_delayed(tname, ref) elif allow_delayed: # delayed no explicit name, cmd run - _add_delayed(name) + _add_delayed(name, ref) else: # delayed no explicit name, cmd list (run creator) _process_gen()