From c059737c9b1f0c47b01384fd3b7ba233a3f84e15 Mon Sep 17 00:00:00 2001 From: magicpieh28 Date: Wed, 8 Jun 2022 17:05:21 +0900 Subject: [PATCH 1/7] Add explanation for arguments passing --- digdag-docs/src/operators/py.md | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/digdag-docs/src/operators/py.md b/digdag-docs/src/operators/py.md index be466f6bf3..19343b5bc5 100644 --- a/digdag-docs/src/operators/py.md +++ b/digdag-docs/src/operators/py.md @@ -76,6 +76,40 @@ See [Python API documents](../python_api.html) for details including variable ma print("simple execution") ``` + You can pass arguments to class for initialization using `_export` as the following: + + ```yaml + # sample.dig + _export: + arg: awsome execution + py>: tasks.MyWorkflow.my_task + ``` + + ```python + # tasks.py + class MyWorkflow(object): + def __init__(self, arg: str): + self.arg = arg + + def my_task(self): + print(self.arg) + ``` + + Or, you can pass arguments to function as the following: + + ```yaml + # simple_sample.dig + _export: + arg: simple execution + py>: simple_tasks.my_func + ``` + + ```python + # simple_tasks.py + def my_func(arg: str): + print(arg) + ``` + * **python**: PATH STRING or COMMAND ARGUMENTS LIST The python defaults to `python`. If an alternate python and options are desired, use the `python` option. From cf36b1e2f2307db4037fcf99ddf30ebd1f112467 Mon Sep 17 00:00:00 2001 From: magicpieh28 Date: Wed, 8 Jun 2022 17:46:09 +0900 Subject: [PATCH 2/7] correct a typo --- digdag-docs/src/operators/py.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/digdag-docs/src/operators/py.md b/digdag-docs/src/operators/py.md index 19343b5bc5..2b1181112e 100644 --- a/digdag-docs/src/operators/py.md +++ b/digdag-docs/src/operators/py.md @@ -81,7 +81,7 @@ See [Python API documents](../python_api.html) for details including variable ma ```yaml # sample.dig _export: - arg: awsome execution + arg: awesome execution py>: tasks.MyWorkflow.my_task ``` From a4c65727c1b0531a424fc9ad42c021721c001dde Mon Sep 17 00:00:00 2001 From: magicpieh28 Date: Wed, 6 Jul 2022 16:22:41 +0900 Subject: [PATCH 3/7] add example how to give python arguments using _export operator --- examples/python_args.dig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/python_args.dig b/examples/python_args.dig index 86cf108771..0cec0ac8f5 100644 --- a/examples/python_args.dig +++ b/examples/python_args.dig @@ -19,3 +19,9 @@ timezone: UTC key1: "a" key2: "val2" ++e: + _export: + key1: "a" + key2: {b: "c"} + py>: tasks.python_args.exported_arguments + From 26129a0cf62c4dce827becf9210feb0ee82c4800 Mon Sep 17 00:00:00 2001 From: magicpieh28 Date: Tue, 12 Jul 2022 17:05:08 +0900 Subject: [PATCH 4/7] add details - one more way how to pass arguments - data types of passed arguments --- digdag-docs/src/operators/py.md | 94 +++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 11 deletions(-) diff --git a/digdag-docs/src/operators/py.md b/digdag-docs/src/operators/py.md index 2b1181112e..a6ec864134 100644 --- a/digdag-docs/src/operators/py.md +++ b/digdag-docs/src/operators/py.md @@ -80,36 +80,108 @@ See [Python API documents](../python_api.html) for details including variable ma ```yaml # sample.dig - _export: - arg: awesome execution - py>: tasks.MyWorkflow.my_task + +some_task: + _export: + required1_1: awesome execution + required1_2: "awesome execution" + required2: {a: "a"} + required3: 1 + required4: 1.0 + required5: [a, 1, 1.0, "a"] + py>: tasks.MyWorkflow.my_task + ``` + + Also, you can do the same thing by defining arguments under the `py>:` operation as the following: + ```yaml + # sample.dig + +some_task: + py>: tasks.MyWorkflow.my_task + required1_1: awesome execution + required1_2: "awesome execution" + required2: {a: "a"} + required3: 1 + required4: 1.0 + required5: [a, 1, 1.0, "a"] ``` ```python # tasks.py class MyWorkflow(object): - def __init__(self, arg: str): - self.arg = arg + def __init__( + self, + required1_1: str, + required1_2: str, + required2: dict[str, str], + required3: int, + required4: float, + required5: list[Union[str, int, float]] + ): + print(f"{required1_1} same as {required1_2}") + self.arg2 = required2 + print(f"{float(required3)} same as {required4}") + self.arg5 = required5 def my_task(self): - print(self.arg) + pass ``` Or, you can pass arguments to function as the following: ```yaml # simple_sample.dig - _export: - arg: simple execution - py>: simple_tasks.my_func + +some_task: + _export: + required1: simple execution + required2: {a: "a"} + py>: simple_tasks.my_func + ``` + + ```yaml + # sample.dig + +some_task: + py>: simple_tasks.my_func + required1: simple execution + required2: {a: "a"} ``` ```python # simple_tasks.py - def my_func(arg: str): - print(arg) + def my_func(required1: str, required2: dict[str, str]): + print(f"{required1}: {required2}") ``` + Finally, you can pass combination of class and mehtod arguments to Python script as the following: + + ```yaml + # sample.dig + +some_task: + _export: + required_class_arg: awesome execution + required_method_arg: ["a", "b"] + py>: tasks.MyWorkflow.my_task + ``` + + ```yaml + # sample.dig + +some_task: + py>: tasks.MyWorkflow.my_task + required_class_arg: awesome execution + required_method_arg: ["a", "b"] + ``` + + This example assume following Python script: + + ```python + # tasks.py + class MyWorkflow: + def __init__(self, required_class_arg: str): + self.arg = required_class_arg + + def my_task(self, required_method_arg: list[str]): + print(f"{self.arg}: {required_method_arg}") + ``` + + * **python**: PATH STRING or COMMAND ARGUMENTS LIST The python defaults to `python`. If an alternate python and options are desired, use the `python` option. From 4fbf333c1c4172595a6eb73eb36672081b012d47 Mon Sep 17 00:00:00 2001 From: magicpieh28 Date: Wed, 27 Jul 2022 17:16:16 +0900 Subject: [PATCH 5/7] change order of examples --- digdag-docs/src/operators/py.md | 53 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/digdag-docs/src/operators/py.md b/digdag-docs/src/operators/py.md index a6ec864134..cfa7036db4 100644 --- a/digdag-docs/src/operators/py.md +++ b/digdag-docs/src/operators/py.md @@ -76,8 +76,20 @@ See [Python API documents](../python_api.html) for details including variable ma print("simple execution") ``` - You can pass arguments to class for initialization using `_export` as the following: + You can pass arguments to class for initialization by defining arguments under the `py>:` operation as the following: + ```yaml + # sample.dig + +some_task: + py>: tasks.MyWorkflow.my_task + required1_1: awesome execution + required1_2: "awesome execution" + required2: {a: "a"} + required3: 1 + required4: 1.0 + required5: [a, 1, 1.0, "a"] + ``` + Also, you can do the same thing using `_export` as the following: ```yaml # sample.dig +some_task: @@ -91,18 +103,7 @@ See [Python API documents](../python_api.html) for details including variable ma py>: tasks.MyWorkflow.my_task ``` - Also, you can do the same thing by defining arguments under the `py>:` operation as the following: - ```yaml - # sample.dig - +some_task: - py>: tasks.MyWorkflow.my_task - required1_1: awesome execution - required1_2: "awesome execution" - required2: {a: "a"} - required3: 1 - required4: 1.0 - required5: [a, 1, 1.0, "a"] - ``` + This example assume following Python script: ```python # tasks.py @@ -128,20 +129,20 @@ See [Python API documents](../python_api.html) for details including variable ma Or, you can pass arguments to function as the following: ```yaml - # simple_sample.dig + # sample.dig +some_task: - _export: - required1: simple execution - required2: {a: "a"} py>: simple_tasks.my_func + required1: simple execution + required2: {a: "a"} ``` ```yaml - # sample.dig + # simple_sample.dig +some_task: + _export: + required1: simple execution + required2: {a: "a"} py>: simple_tasks.my_func - required1: simple execution - required2: {a: "a"} ``` ```python @@ -155,22 +156,20 @@ See [Python API documents](../python_api.html) for details including variable ma ```yaml # sample.dig +some_task: - _export: - required_class_arg: awesome execution - required_method_arg: ["a", "b"] py>: tasks.MyWorkflow.my_task + required_class_arg: awesome execution + required_method_arg: ["a", "b"] ``` ```yaml # sample.dig +some_task: + _export: + required_class_arg: awesome execution + required_method_arg: ["a", "b"] py>: tasks.MyWorkflow.my_task - required_class_arg: awesome execution - required_method_arg: ["a", "b"] ``` - This example assume following Python script: - ```python # tasks.py class MyWorkflow: From 50807700fea99aa040fa3e2404f1e3e042933c6a Mon Sep 17 00:00:00 2001 From: magicpieh28 Date: Tue, 2 Aug 2022 13:56:10 +0900 Subject: [PATCH 6/7] add warning message to notice class and method arguments must have different names when we pass those through digdag --- digdag-docs/src/operators/py.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/digdag-docs/src/operators/py.md b/digdag-docs/src/operators/py.md index cfa7036db4..c29c1e605a 100644 --- a/digdag-docs/src/operators/py.md +++ b/digdag-docs/src/operators/py.md @@ -151,8 +151,8 @@ See [Python API documents](../python_api.html) for details including variable ma print(f"{required1}: {required2}") ``` - Finally, you can pass combination of class and mehtod arguments to Python script as the following: - + Finally, you can pass combination (must have different names) of class and mehtod arguments to Python script as the following: + ```yaml # sample.dig +some_task: From 08ac4a278ac78189f7ad72b525968ecb7efc2217 Mon Sep 17 00:00:00 2001 From: magicpieh28 Date: Thu, 13 Oct 2022 18:56:13 +0900 Subject: [PATCH 7/7] add import so that user can copy examples and run it directly --- digdag-docs/src/operators/py.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/digdag-docs/src/operators/py.md b/digdag-docs/src/operators/py.md index c29c1e605a..62eb3d9db7 100644 --- a/digdag-docs/src/operators/py.md +++ b/digdag-docs/src/operators/py.md @@ -107,6 +107,9 @@ See [Python API documents](../python_api.html) for details including variable ma ```python # tasks.py + from typing import Union + + class MyWorkflow(object): def __init__( self,