-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtutorial.py
74 lines (59 loc) · 1.9 KB
/
tutorial.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
# ipython utils
import os
import sys
import time
import yaml
import datetime
from pathlib import Path
from IPython import get_ipython
from IPython.core.magic import (register_line_magic, register_cell_magic,
register_line_cell_magic)
import warnings; warnings.simplefilter('ignore')
start = time.time()
@register_line_cell_magic
def elapsed_time(line, cell=None):
if cell is not None:
get_ipython().run_cell(cell)
print(datetime.timedelta(seconds=round(time.time() - start)))
os.environ.update({
"GROUP": "tutorial",
"VERSION": "v1",
"KOPFLOG": "false",
"DOCKER_TLS_VERIFY": "1",
"DOCKER_HOST": "tcp://127.0.0.1:32770",
"DOCKER_CERT_PATH": str(Path(os.environ["HOME"], ".minikube/certs")),
"MINIKUBE_ACTIVE_DOCKERD": "minikube",
"IMAGEPULL": "Never",
"REPO": "tutorial",
})
workdir = (Path(os.environ["GOPATH"],
"src", "digi.dev",
"tutorial", "workdir"))
os.environ["WORKDIR"] = str(workdir)
def _rm_tree(pth):
pth = Path(pth)
for child in pth.glob('*'):
if child.is_file():
child.unlink()
else:
_rm_tree(child)
pth.rmdir()
def create(m: str, new=True):
y = yaml.load(m, Loader=yaml.FullLoader)
assert "kind" in y
_dir = Path(workdir, y["kind"].lower())
if _dir.is_dir() and new:
_rm_tree(_dir)
Path(_dir, "driver").mkdir(parents=True, exist_ok=True)
Path(_dir, "deploy").mkdir(parents=True, exist_ok=True)
Path(_dir, "deploy", "cr_run.yaml").touch()
Path(_dir, "driver", "handler.py").touch()
with open(Path(_dir, "model.yaml"), "w") as f:
f.write(m)
def handler_file(k):
return Path(workdir, k, "driver", "handler.py")
def model_file(k, new=True):
if new:
return Path(workdir, k, "deploy", "cr.yaml")
else:
return Path(workdir, k, "deploy", "cr_run.yaml")