How can i pass task_params when using task_dep?

31 views
Skip to first unread message

Suh Junmin

unread,
Dec 13, 2021, 9:44:20 PM12/13/21
to python-doit
Hello,

I want to pass task_params in task_dep task.

The example code is below.

How can I pass param_b when executing task_a?

```
from doit import task_params
from doit.exceptions import TaskFailed

import subprocess

@task_params([{"name": "param_b", "default": "", "type": str, "long": "param_b"}])
def task_b(param_b: str):
    def _execute():
        if not param_b:
            return TaskFailed("param_b must be defined")

        ret = subprocess.call(["echo", param_b])

        if ret == 0:
            return True

        return ret

    return {
        "actions": [_execute]
    }


@task_params([{"name": "param_a", "default": "", "type": str, "long": "param_a"}])
def task_a(param_a: str):
    return {
        "actions": [f"echo {param_a}"],
        "task_dep": ["b"]
    }
```

doit help a
a  
  --param_a=ARG               (config: param_a)

thanks

Eduardo Schettino

unread,
Dec 13, 2021, 9:51:26 PM12/13/21
to python-doit
Hi

`task_params` get its values from the command line. You would need to specify both them like

> doit a --param_a foo b --param_b bar

`task_params` are used to modify and control how you create the task metadata.
You only need to pass a result when EXECUTING the task's actions you could use `result_dep`.

Regards

--
You received this message because you are subscribed to the Google Groups "python-doit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-doit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-doit/22bf4241-2a15-41dc-950f-ecea2661e59fn%40googlegroups.com.

Suh Junmin

unread,
Dec 16, 2021, 1:51:41 PM12/16/21
to python-doit
thanks!

I have one more question.

My use case is to publish artifacts on the web. and I need to log in before publishing an artifact.

so, I create task_login and task_publish

task_login is simply login to a private repository

and I can check the login status with cli

task_publish is upload an artifact to a private repository.

In this scenario, is my first question a possible valid solution?

Best Regards
2021년 12월 14일 화요일 오전 11시 51분 26초 UTC+9에 schettino72님이 작성:
Reply all
Reply to author
Forward
0 new messages