pydoit / doit

CLI task management & automation tool
http://pydoit.org
MIT License
1.87k stars 175 forks source link

Passing parameter to subtask or result_dep #270

Closed koliyo closed 6 years ago

koliyo commented 6 years ago

How can I pass a parameter to a dependency? In this example, I want to access the file parameter in the foo task.

def task_main():
    def main(file):
        print('main!', file)

    return {
        'actions': [main],
        'params': [{'name': 'file',
                    'long': 'file',
                    'default': None,
                    }],
        'task_dep': ['foo'],
    }

def task_foo():
    def foo():
        # I want to access the file parameter here!
        print('foo')

    return {
        'actions': [foo]
    }

I have looked at @create_after, result_dep, getargs, setup, but I have been unable to setup this configuration :/

FrankStain commented 6 years ago

@koliyo , hi! What is the params section of main task? I can't remember what it does, i even can't remember it is legal section of task description. Also it would be great if you describe the real problem you're trying to solve.

Any action parameter may be passed via getargs section ( desc. ).

'getargs': {
   'action_argument': ( 'task_name', 'name_of_saved_value' )
}

But here is some slight restriction. All action arguments should be serializable. So if you prefer to pass the file object this way, it's probably a bad idea due to serialization issue. I think, it would be much better to pass the file path instead of file object.

FrankStain commented 6 years ago

I had remember the meaning of params section. :) It's a command-line parameters, which may be passed to actions. File object especially can't be passed into actions this way.