-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtrigger.py
29 lines (28 loc) · 853 Bytes
/
trigger.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
import pathlib
import papermill as pm
def trigger_run(notebook_filepath, params={}, id=None, output_path=None):
'''
Trigger the notebook filepath
'''
input_path = pathlib.Path(notebook_filepath)
if not input_path.exists():
return []
stdout_file = None
if output_path is None:
fname = input_path.stem
suffix = input_path.suffix
output_dir = input_path.parent / "outputs"
output_dir.mkdir(parents=True, exist_ok=True)
output_path = output_dir / f"{fname}-output{suffix}"
stdout_file = open(output_dir / f"{fname}-stdout", "a+")
rs = pm.execute_notebook(
input_path,
output_path,
stdout_file=stdout_file,
parameters={"id": id, **params}
)
try:
stdout_file.close()
except:
pass
return rs, output_path