Skip to content

Commit

Permalink
Bind delayed task creating functions to the object instance.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rbdixon committed Jun 30, 2019
1 parent f103784 commit a5b8f99
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions doit/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand All @@ -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()

Expand Down

0 comments on commit a5b8f99

Please sign in to comment.