Skip to content

Commit

Permalink
Fix result_dep, use result **after** its execution
Browse files Browse the repository at this point in the history
  • Loading branch information
schettino72 committed Apr 14, 2019
1 parent 0fc00d5 commit 3873759
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -19,6 +19,7 @@ Changes
- Fix #267: `doit list` now has a `--sort` parameter to determine the order in which the tasks are listed.
- Make it possible to use a custom encoder when using config_changed with a dict.
- Add configuration `DOIT_CONFIG` `action_string_formatting` to control command action formatter.
- Fix `result_dep`, use result **after** its execution


0.31.1 (*2018-03-18*)
Expand Down
22 changes: 13 additions & 9 deletions doit/task.py
Expand Up @@ -6,7 +6,6 @@
import sys
import inspect
from collections import OrderedDict
from functools import partial
from pathlib import PurePath

from .cmdparse import CmdOption, TaskParse
Expand Down Expand Up @@ -595,9 +594,6 @@ def clean_targets(task, dryrun):
os.rmdir(dir_)


def _return_param(val):
'''just return passed parameter - make a callable from any value'''
return val

# uptodate
class result_dep(UptodateCalculator):
Expand Down Expand Up @@ -635,15 +631,23 @@ def _result_group(self, dep_task):
sub_tasks[sub] = self.get_val(sub, 'result:')
return sub_tasks

def __call__(self, task, values):
"""return True if result is the same as last run"""
dep_task = self.tasks_dict[self.dep_name]
def _get_dep_result(self, dep_task):
if not dep_task.has_subtask:
dep_result = self._result_single()
else:
dep_result = self._result_group(dep_task)
func = partial(_return_param, {self.result_name: dep_result})
task.value_savers.append(func)
return dep_result


def __call__(self, task, values):
"""return True if result is the same as last run"""
dep_task = self.tasks_dict[self.dep_name]
dep_result = self._get_dep_result(dep_task)

def result_saver():
# get latest value after execution of dependent task
return {self.result_name: self._get_dep_result(dep_task)}
task.value_savers.append(result_saver)

last_success = values.get(self.result_name)
if last_success is None:
Expand Down
6 changes: 0 additions & 6 deletions tests/test_task.py
Expand Up @@ -611,9 +611,6 @@ def test_single(self, dep_manager):
# t2 result changed
tasks['t2'].result = '222'
dep_manager.save_success(tasks['t2'])

tasks['t1'].save_extra_values()
dep_manager.save_success(tasks['t1'])
assert 'run' == dep_manager.get_status(tasks['t1'], tasks).status

tasks['t1'].save_extra_values()
Expand Down Expand Up @@ -645,9 +642,6 @@ def test_group(self, dep_manager):
# t2 result changed
tasks['t2:a'].result = '222'
dep_manager.save_success(tasks['t2:a'])

tasks['t1'].save_extra_values()
dep_manager.save_success(tasks['t1'])
assert 'run' == dep_manager.get_status(tasks['t1'], tasks).status

tasks['t1'].save_extra_values()
Expand Down

0 comments on commit 3873759

Please sign in to comment.