forked from dptech-corp/dflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_slices.py
81 lines (72 loc) · 1.72 KB
/
test_slices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from dflow import (
Workflow,
Step,
argo_range
)
from dflow.python import (
PythonOPTemplate,
OP,
OPIO,
OPIOSign,
Artifact,
Slices
)
from typing import List
class Hello(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'filename': str
})
@classmethod
def get_output_sign(cls):
return OPIOSign({
'foo' : Artifact(str)
})
@OP.exec_sign_check
def execute(
self,
op_in : OPIO,
) -> OPIO:
open(op_in["filename"], "w").write("foo")
op_out = OPIO({
'foo' : op_in["filename"]
})
return op_out
class Check(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'foo': Artifact(List[str])
})
@classmethod
def get_output_sign(cls):
return OPIOSign()
@OP.exec_sign_check
def execute(
self,
op_in : OPIO,
) -> OPIO:
print(op_in["foo"])
return OPIO()
if __name__ == "__main__":
wf = Workflow("slices")
hello = Step("hello",
PythonOPTemplate(Hello, image="dptechnology/dflow",
slices=Slices("{{item}}",
input_parameter=["filename"],
output_artifact=["foo"]
)
),
parameters={"filename": ["f1.txt", "f2.txt"]},
with_param=argo_range(2))
wf.add(hello)
check = Step("check",
PythonOPTemplate(Check, image="dptechnology/dflow"),
artifacts={"foo": hello.outputs.artifacts["foo"]})
wf.add(check)
wf.submit()