forked from dptech-corp/dflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_subpath_slices.py
94 lines (76 loc) · 2.29 KB
/
test_subpath_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
82
83
84
85
86
87
88
89
90
91
92
93
94
import time
from typing import List
from dflow import Step, Workflow # , upload_artifact
from dflow.python import (OP, OPIO, Artifact, OPIOSign, PythonOPTemplate,
Slices, upload_packages)
if "__file__" in locals():
upload_packages.append(__file__)
class Prepare(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
})
@classmethod
def get_output_sign(cls):
return OPIOSign({
'foo': Artifact(List[str], archive=None)
})
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
with open("foo1.txt", "w") as f:
f.write("foo1")
with open("foo2.txt", "w") as f:
f.write("foo2")
op_out = OPIO({
'foo': ["foo1.txt", "foo2.txt"]
})
return op_out
class Hello(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign({
'foo': Artifact(str)
})
@classmethod
def get_output_sign(cls):
return OPIOSign()
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
with open(op_in["foo"], "r") as f:
print(f.read())
return OPIO()
def test_subpath_slices():
wf = Workflow("subpath-slices")
# with open("foo1.txt", "w") as f:
# f.write("foo1")
# with open("foo2.txt", "w") as f:
# f.write("foo2")
# artifact = upload_artifact(["foo1.txt", "foo2.txt"], archive=None)
prepare = Step("prepare",
PythonOPTemplate(Prepare, image="python:3.8"))
wf.add(prepare)
hello = Step("hello",
PythonOPTemplate(Hello, image="python:3.8",
slices=Slices(sub_path=True,
input_artifact=["foo"]
)
),
artifacts={"foo": prepare.outputs.artifacts["foo"]})
# artifacts={"foo": artifact})
wf.add(hello)
wf.submit()
while wf.query_status() in ["Pending", "Running"]:
time.sleep(1)
assert(wf.query_status() == "Succeeded")
if __name__ == "__main__":
test_subpath_slices()