Python Doit - Use Arguments In Dependent Tasks
I have 2 doit tasks, one having a dependency on the other. For example: def task_deploy(): return { 'actions': ['do some deploy commands'], 'file_dep': ['dist']
Solution 1:
Is there a way to share or pass the arguments of a task to another one?
Yes. Using getargs
: http://pydoit.org/dependencies.html#getargs
In your example, you would need to add another action to the task deploy
just to save the passed parameter.
Solution 2:
You could just use a global variable like commonCommand. If you have more complex needs, create a class to handle it.
class ComplexCommonParams(object):
def __init__(self):
self.command = 'echo'
params = ComplexCommonParams()
commonCommand='echo'
def task_x():
global commonCommand
return {
'actions': [ commonCommand + ' Hello2 > asdf' ],
'targets': ['asdf']
}
def task_y():
global commonCommand
return {
'actions': [ commonCommand+' World' ],
'file_dep': ['asdf'],
'verbosity':2}
Post a Comment for "Python Doit - Use Arguments In Dependent Tasks"