-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_notebooks.py
More file actions
executable file
·39 lines (30 loc) · 1.02 KB
/
run_notebooks.py
File metadata and controls
executable file
·39 lines (30 loc) · 1.02 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
#! /usr/bin/env python3
import subprocess
import os
pipeline_steps = [
'cleaning',
'integration',
'transformation',
'classification'
]
def pipeline_step(step_dir):
notebook_paths = []
for file in os.listdir(step_dir):
if file.endswith(".ipynb"):
notebook_paths.append(os.path.join(step_dir, file))
for path in notebook_paths:
print(f"Executing notebook: {path}")
execute_notebook(path)
def execute_notebook(notebook_path):
try:
subprocess.run(['jupyter', 'nbconvert', '--to', 'notebook', '--execute', notebook_path])
converted_notebook = os.path.splitext(notebook_path)[0] + '.nbconvert.ipynb'
if os.path.exists(converted_notebook):
os.remove(converted_notebook)
print(f"Deleted: {converted_notebook}")
except Exception as e:
print(f"Error executing notebook {notebook_path}: {e}")
for step in pipeline_steps:
print(f"Executing step: {step}")
pipeline_step(step)
print("Pipeline execution complete.")