Open joshuajorel opened 2 years ago
I think I just ran into something similar which is, I think, actually the root cause issue here: if an action generator uses yield
to generate tasks the params are ignored.
For example, given the following
from doit import task_params
@task_params([
{'name': 'version', 'long': 'version', 'default': 'v10'},
])
def task_testing(version):
print('version:', version)
return {
'actions': [f'echo {version}'],
'verbosity': 2,
}
It works as expected:
$ doit testing --version=hello
version: hello
. testing
hello
But change it to this:
from doit import task_params
@task_params([
{'name': 'version', 'long': 'version', 'default': 'v10'},
])
def task_testing(version):
print('version:', version)
yield {
'basename': 'test',
'actions': [f'echo {version}'],
'verbosity': 2,
}
and it ignores the command line argument:
$ doit test --version=hello
version: v10
. test
v10
You can get it to work again by putting the CLI args on the yielded task:
from doit import task_params
def task_testing():
yield {
'basename': 'test',
'actions': ['echo %(version)s'],
'verbosity': 2,
'params': [
{'name': 'version', 'long': 'version', 'default': 'v10'},
],
}
which works:
$ doit test --version=hello
. test
hello
But it has some drawbacks as the CLI argument isn't available as a regular Python variable so you can't use it except in the few places doit
will expand it (e.g. you couldn't use it in an f-string to generate a title
).
Hi,
When using a param of type
list
and adding default values in the definition of the param, when invoking the task with list values you specified in the command line, it does not create a new list, but appends to the default list.doit.py
Execution
Environment