-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathexecute-convert.py
More file actions
52 lines (43 loc) · 1.11 KB
/
execute-convert.py
File metadata and controls
52 lines (43 loc) · 1.11 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
42
43
44
45
46
47
48
49
50
51
52
import subprocess
import sys
import glob
slug = sys.argv[1]
def run_command(command, verbose=1):
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
print(f"Error building book: {e.stderr}")
sys.exit(1)
if verbose > 0:
print(f"Output: {result.stdout}")
return result
notebooks = glob.glob("*.ipynb")
if len(notebooks) > 1:
print("More than one .ipynb notebook found --> assuming this is a book")
# build book
command = [
"jb",
"build",
"--config",
"_config.yml",
"--toc",
"_toc.yml",
".",
]
run_command(command)
# copy build outputs to 'html' dir
command = ["cp", "-r", "_build/html", "html"]
run_command(command)
else:
# build single notebook
command = [
"jb",
"build",
"--config",
"_config.yml",
f"{slug}.ipynb",
]
run_command(command)
# copy build outputs to 'html' dir
command = ["cp", "-r", f"_build/_page/{slug}/html", "html"]
run_command(command)