Skip to content

Commit e7db08c

Browse files
authored
Merge pull request #596 from JohT/feature/improve-plots
Improve plots and fix exploratory notebook issues
2 parents d1b9819 + 9347997 commit e7db08c

17 files changed

Lines changed: 982 additions & 796 deletions
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Check Jupyter Notebooks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
# Run when notebooks, Python dependencies, or this workflow change
8+
paths:
9+
- 'domains/**/explore/*.ipynb'
10+
- 'pyproject.toml'
11+
- 'uv.lock'
12+
- 'scripts/activateUvEnvironment.sh'
13+
- '.github/workflows/internal-check-notebooks.yml'
14+
15+
jobs:
16+
check-notebook-syntax-and-imports:
17+
runs-on: ubuntu-22.04
18+
19+
steps:
20+
- name: Checkout GIT Repository
21+
uses: actions/checkout@v6
22+
23+
- name: (uv Setup) Install uv
24+
uses: astral-sh/setup-uv@v6
25+
with:
26+
python-version: '3.12'
27+
28+
- name: (uv Setup) Sync dependencies from lockfile
29+
run: uv sync --frozen
30+
31+
- name: Check notebook syntax and imports
32+
# For each notebook: parse each Python code cell as Python AST to catch SyntaxErrors,
33+
# then collect every unique import statement across all notebooks and run them
34+
# in a single Python process to catch ModuleNotFoundError / ImportError.
35+
# Cell magics (%%html, %%bash, …) and line magics (%matplotlib, …) are skipped —
36+
# they are not Python and would cause false-positive SyntaxErrors.
37+
# No kernel execution — no Neo4j needed, finishes in seconds.
38+
run: |
39+
uv run python3 - <<'PYEOF'
40+
import ast, json, sys
41+
from pathlib import Path
42+
43+
notebooks = sorted(Path("domains").glob("**/explore/*.ipynb"))
44+
import_lines = set()
45+
syntax_failures = []
46+
47+
for notebook in notebooks:
48+
print(f"Parsing {notebook}", flush=True)
49+
nb = json.loads(notebook.read_text())
50+
for cell in nb["cells"]:
51+
if cell["cell_type"] != "code":
52+
continue
53+
source = "".join(cell["source"]).strip()
54+
if not source:
55+
continue
56+
# Skip cell magics (%%html, %%bash, etc.) — not Python code
57+
if source.startswith("%%"):
58+
continue
59+
# Remove line magics (%matplotlib, %time, etc.) — not valid Python syntax
60+
python_source = "\n".join(line for line in source.split("\n") if not line.lstrip().startswith("%"))
61+
if not python_source.strip():
62+
continue
63+
try:
64+
tree = ast.parse(python_source)
65+
except SyntaxError as e:
66+
syntax_failures.append(f"{notebook}: SyntaxError line {e.lineno}: {e.msg}")
67+
continue
68+
for node in ast.walk(tree):
69+
if isinstance(node, ast.Import):
70+
for alias in node.names:
71+
import_lines.add(f"import {alias.name}")
72+
elif isinstance(node, ast.ImportFrom) and node.module:
73+
names = ", ".join(a.name for a in node.names)
74+
import_lines.add(f"from {node.module} import {names}")
75+
76+
if syntax_failures:
77+
print("Syntax errors found:", file=sys.stderr)
78+
for f in syntax_failures:
79+
print(f" {f}", file=sys.stderr)
80+
sys.exit(1)
81+
82+
import_script = "\n".join(sorted(import_lines))
83+
print(f"\nRunning {len(import_lines)} unique import statements from {len(notebooks)} notebooks...", flush=True)
84+
try:
85+
exec(import_script) # noqa: S102
86+
except Exception as e:
87+
print("Import check failed:", file=sys.stderr)
88+
print(str(e), file=sys.stderr)
89+
sys.exit(1)
90+
91+
print(f"All {len(notebooks)} notebooks OK: syntax valid, {len(import_lines)} unique imports resolved.")
92+
PYEOF

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
This document describes the changes to the Code Graph Analysis Pipeline. The changes are grouped by version and date. The latest version is at the top.
44

5+
## v4.0.1 Improve charts to look more similar to previous Jupyter notebook charts and add pipeline to validate Jupyter notebooks
6+
7+
### 🎨 Improvements
8+
9+
* **Python charts improved** — Python charts now look more similar to the previous Jupyter notebooks with improved visual presentation by @JohT
10+
* **Jupyter notebook validation pipeline** — Add pipeline to quickly validate Jupyter notebooks by @JohT
11+
* **Python dependency improvements** — Add `nbformat` library for plotly support in Jupyter notebooks and remove `setuptools` dependency since opentsne is removed by @JohT
12+
513
## v4.0.0 - Vertical slice domains, uv as Python package manager, Jupyter removed
614

715
### ✨ Highlights

0 commit comments

Comments
 (0)