本文介绍了Python doit-在相关任务中使用参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个doit任务,一个任务依赖于另一个任务.例如:

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'],
        'params': [{'name': 'projectName',
                    'short': 'p',
                    'long': 'projectName',
                    'default': 'project',
                    'type': str,
                    'help': 'The project name to deploy.'}]
        }

def task_create_distibution_archive():
    return {
        'actions': ['do something that requires projectName'],
        'doc': 'Creates a zip archive of the application in "dist"',
        'targets': ['dist']
    }

是否有一种方法可以共享或传递任务的参数给另一个任务?我已经阅读了关于任务创建和 pydoit.org 的所有内容,但没有找到任何与我想要的东西相似的东西.

Is there a way to share or pass the arguments of a task to another one? I have read pretty much everything I could on task creation and dependency on pydoit.org, but haven't found anything similar to what I want.

我知道我可以同时使用yield来创建这两个任务,但是我想在执行任务时使用参数,而不是在创建任务时使用它.

I am aware that I could use yield to create these two tasks at the same time, but I'd like to use a parameter when executing the task, not when I am creating it.

推荐答案

是的.使用getargs: http://pydoit.org/dependencies.html#getargs

在您的示例中,您将需要向任务deploy添加另一个 action ,只是为了保存传递的参数.

In your example, you would need to add another action to the task deploy just to save the passed parameter.

这篇关于Python doit-在相关任务中使用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 06:50