Describe the bug
Given a simple dodo.py
like this:
from doit.action import CmdAction
def action_thing():
print('I was called.')
return 'echo hello world!'
def task_testing():
return {
'actions': [
CmdAction(action_thing)
],
'verbosity': 2,
}
You can see that action_thing
gets called twice (the print line is run twice). The root cause appears to be that CmdAction.action
is defined as:
@property
def action(self):
if isinstance(self._action, (str, list)):
return self._action
else:
# action can be a callable that returns a string command
ref, args, kw = normalize_callable(self._action)
kwargs = self._prepare_kwargs(self.task, ref, args, kw)
return ref(*args, **kwargs)
so a self.action
call actually runs the callable. And self.action
is called in several places. For example, line 283 is:
if isinstance(self.action, list):
This can be problematic in some circumstances. For example, I have a callable that makes a REST call to get a version number and then uses that to do some other things. Obviously I don't want to make that call twice.
Environment
suggestion: call the callable once and cache the result. A @functools.cache
might do the trick.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too