Closed rbdixon closed 2 years ago
Task parameters defined with @task_param()
are passed down to the task and any subtasks right now. This could be a feature or a bug? What do you think?
8/13: Absent any input I decided this is a feature.
hmm... well, I've got a bug buried down there coping with @create_after tasks. I'll fix that soon.
I believe this is ready to merge. I'm using this locally with my own doit-based automations and nikola. So far, so good.
Hmmm.... I've found a wrinkle and I think I'd like input on what the best behavior would be:
Given dodo.py
:
from doit import task_param
DRYRUN = {
'name': 'dry_run',
'short': 'n',
'long': 'dry-run',
'type': bool,
'default': False,
'help': 'Do not commit database changes.',
}
@task_param([DRYRUN])
def task_test(dry_run):
def _subtask(i, dry_run):
print(f'subtask {i}, dry_run=={dry_run}')
print(f'Task creation, dry_run == {dry_run}')
yield {'name': None, 'verbosity': 2}
for i in range(1):
yield {
'name': f'subtask_{i}',
'actions': [(_subtask, (i,), {})],
'verbosity': 2,
}
Run:
$ doit test -n
Task creation, dry_run == True
. test:subtask_0
subtask 0, dry_run==False
The parameter definition was propagated to the subtask but not the value. The task dry_run
value can be pushed to the subtask in code, of course.
Two options:
@task_param
definitions propagate to subtasks but not the runtime value.Option 2 seems "least surprising". Opinions?
@schettino72 ^ just checking in to see if you had comments on the above. Thanks.
@rbdixon sorry for very long delay. I should be able to merge this and release and next few weeks.
Task parameters defined with @task_param() are passed down to the task and any subtasks right now. This could be a feature or a bug? What do you think?
I dont think it desirable to pass to subtasks. And since params is a simple dict it would be trivial to explicitly pass it into subtasks.
But I think it should be part of base task. So it is documented by help command. Of course things get a bit complicated if base are explicitly defined. For those I would just not bother unless explicitly set.
Thanks for the comment. I'll work on this in January to:
@task_param()
definitions down to subtasks.@task_param()
definitions included in the task help output.@rbdixon could youp please rebase the PR to latest master? some commits already merged. its a bit messy...
New branch rebased to master implementing only the #311. Still need to implement below as discussed in December:
@task_param()
defined command line arguments from the parent task.@task_param()
defined parameters are include in info
command output:$ doit info subtask
Task parameter foo=bar available at task definition time.
Task parameter foo=bar available at task definition time.
When the task action runs it will print bar
Generating 1 subtasks
subtask
status : run
* The task has no dependencies.
task_dep :
- subtask:task0
params :
- {'name': 'num_tasks', 'default': 1, 'type': <class 'int'>, 'long': 'num_tasks'}
I believe this final version satisfies all requests and comments and is ready to merge to master.
@schettino72 Any further work required for this PR?
sorry, i will have time only in march (hopefully)
That’s OK... I understand. I appreciate your dedication to doit!
Bump.... would love to see this merged. Thanks.
I have merged this. I did some clean-up and fixes but still not complete.
params
on dict data together with task_param
does not work as there is no way to parse when you have not read task dict.
As described in #311 this decorator can be used to pass command line arguments to the task generator. The same parameter definitions are also passed to the generated tasks.
This branch also includes pull request #307 which implements
@create_after()
semantics for tasks defined in a class. As discussed on #307 @schettino72 asked to see code for #311 as well. If this PR is merged then #307 will be closed.Quick implementation to see if this is what was intended by the issue and to open discussion.
Work to be done:
auto
compatibilityDemo: