-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathrun_models_cli.py
More file actions
41 lines (33 loc) · 1.07 KB
/
Copy pathrun_models_cli.py
File metadata and controls
41 lines (33 loc) · 1.07 KB
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
import os
import sys
import subprocess
from pathlib import Path
def main():
if len(sys.argv) != 2:
print("Usage: python run_models_cli.py <path-or-url-to-parameters.yaml>")
sys.exit(1)
params_arg = sys.argv[1]
# Handle local path vs URL
if params_arg.startswith("http://") or params_arg.startswith("https://"):
params_path = params_arg
else:
params_path = str(Path(params_arg).expanduser().resolve())
# Set as environment variable for the notebook
env = os.environ.copy()
env["PARAMETERS_YAML_PATH"] = params_path
notebook = "models/Run-Models-bkup.ipynb"
output_nb = "Run-Models-output.ipynb"
cmd = [
"jupyter",
"nbconvert",
"--to", "notebook",
"--execute",
"--ExecutePreprocessor.timeout=0",
"--output", output_nb,
notebook,
]
print(f"Running {notebook} with PARAMETERS_YAML_PATH={params_path}")
subprocess.run(cmd, check=True, env=env)
print(f"✅ Done! Executed notebook saved as {output_nb}")
if __name__ == "__main__":
main()