forked from dptech-corp/dflow
-
Notifications
You must be signed in to change notification settings - Fork 26
/
test_slices.py
74 lines (61 loc) · 1.8 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
from typing import List
from dflow import Step, Workflow, argo_range
from dflow.python import OP, OPIO, Artifact, OPIOSign, PythonOPTemplate, Slices
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="python:3.8",
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="python:3.8"),
artifacts={"foo": hello.outputs.artifacts["foo"]})
wf.add(check)
wf.submit()