Repository navigation
Expand file tree
/
Copy pathbuild.py
More file actions
79 lines (65 loc) · 1.68 KB
/
Copy pathbuild.py
File metadata and controls
79 lines (65 loc) · 1.68 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from pathlib import Path
from subprocess import CalledProcessError, run
from loguru import logger
from typer import Typer, echo
BASE_DIR = Path(__file__).parent
main = Typer()
def _export(
*,
notebook_path: Path,
output_dir: Path,
) -> bool:
output_path = output_dir / notebook_path.with_suffix(".html").name
args = [
"uv",
"run",
"marimo",
"export",
"html-wasm",
str(notebook_path),
"-o",
str(output_path),
"--mode",
"run",
"--no-show-code",
# "--include-cloudflare",
]
try:
run(
args,
check=True,
capture_output=True,
text=True,
)
return True
except CalledProcessError as e:
logger.error(f"Error exporting {notebook_path}:")
logger.error(e.stderr)
return False
except Exception as e:
logger.error(f"Unexpected error {notebook_path}:")
logger.error(e)
return True
@main.command()
def build_wasm_html(
notebook_dir: Path = BASE_DIR / "notebooks",
output_dir: Path = BASE_DIR / "_site",
) -> None:
errors = [
not _export(
notebook_path=notebook_fn,
output_dir=output_dir,
)
for notebook_fn in notebook_dir.glob("*.py")
]
n_errors = sum(errors)
n_total = len(errors)
frac_errors = n_errors / n_total
if n_errors != 0:
echo(
f"The export failed for {n_errors} / {n_total} ({frac_errors:.1%}) notebooks. Increase the log level for more details."
)
exit(1)
echo("Export succeeded without any errors.")
if __name__ == "__main__":
main()