Skip to content

Commit a8b4907

Browse files
2 parents 778ae46 + c85b5c6 commit a8b4907

12 files changed

Lines changed: 2772 additions & 0 deletions

File tree

‎.github/sync-myst-toc.py‎

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Sync myst.yml TOC with notebooks on disk.
4+
Finds lec/lecNN/, lab/labNN/, hw/hwNN/, project/projectN.ipynb, and sandbox/sandbox.ipynb,
5+
builds the table of contents in order, and updates myst.yml.
6+
Run from repository root. Exits 0 if no change, 2 on error.
7+
"""
8+
import re
9+
import sys
10+
from pathlib import Path
11+
12+
try:
13+
import yaml
14+
except ImportError:
15+
print("PyYAML required: pip install pyyaml", file=sys.stderr)
16+
sys.exit(2)
17+
18+
REPO_ROOT = Path(__file__).resolve().parent.parent
19+
MYST_PATH = REPO_ROOT / "myst.yml"
20+
21+
EXIT_SUCCESS = 0
22+
EXIT_ERROR = 2
23+
24+
25+
def find_numbered_notebooks(parent_dir: str, prefix: str, title_fmt: str) -> list[dict]:
26+
"""Find all prefixNN/prefixNN.ipynb under parent_dir, sorted by NN."""
27+
base = REPO_ROOT / parent_dir
28+
if not base.is_dir():
29+
return []
30+
pattern = re.compile(rf"^{prefix}(\d+)$")
31+
entries = []
32+
for path in sorted(base.iterdir()):
33+
if not path.is_dir():
34+
continue
35+
m = pattern.match(path.name)
36+
if not m:
37+
continue
38+
num = m.group(1)
39+
nb = path / f"{path.name}.ipynb"
40+
if nb.is_file():
41+
rel = str(nb.relative_to(REPO_ROOT))
42+
title = title_fmt.format(num=int(num), znum=num.zfill(2))
43+
entries.append({"title": title, "file": rel})
44+
# Sort by number
45+
entries.sort(key=lambda e: int(re.search(r"\d+", e["file"]).group()))
46+
return entries
47+
48+
49+
def find_flat_numbered_notebooks(parent_dir: str, file_prefix: str, title_fmt: str) -> list[dict]:
50+
"""Find all parent_dir/file_prefixN.ipynb (flat), sorted by N."""
51+
base = REPO_ROOT / parent_dir
52+
if not base.is_dir():
53+
return []
54+
pattern = re.compile(rf"^{re.escape(file_prefix)}(\d+)\.ipynb$")
55+
entries = []
56+
for path in base.iterdir():
57+
if not path.is_file() or path.suffix != ".ipynb":
58+
continue
59+
m = pattern.match(path.name)
60+
if not m:
61+
continue
62+
num = m.group(1)
63+
rel = str(path.relative_to(REPO_ROOT))
64+
title = title_fmt.format(num=int(num), znum=num.zfill(2))
65+
entries.append({"title": title, "file": rel})
66+
entries.sort(key=lambda e: int(re.search(r"\d+", e["file"]).group()))
67+
return entries
68+
69+
70+
def main() -> int:
71+
if not MYST_PATH.is_file():
72+
print(f"Error: {MYST_PATH} not found", file=sys.stderr)
73+
return EXIT_ERROR
74+
75+
toc = []
76+
77+
# Intro (no title, just file)
78+
intro = REPO_ROOT / "intro.md"
79+
if intro.exists():
80+
toc.append({"file": "intro.md"})
81+
82+
# Lectures
83+
lectures = find_numbered_notebooks("lec", "lec", "Lecture {znum}")
84+
if lectures:
85+
toc.append({"title": "Lectures", "children": lectures})
86+
87+
# Labs
88+
labs = find_numbered_notebooks("lab", "lab", "Lab {znum}")
89+
if labs:
90+
toc.append({"title": "Labs", "children": labs})
91+
92+
# Homework
93+
homework = find_numbered_notebooks("hw", "hw", "Homework {znum}")
94+
if homework:
95+
toc.append({"title": "Homework", "children": homework})
96+
97+
# Projects (flat: project/project1.ipynb, project/project2.ipynb, ...)
98+
projects = find_flat_numbered_notebooks("project", "project", "Project {znum}")
99+
if projects:
100+
toc.append({"title": "Projects", "children": projects})
101+
102+
# Sandbox
103+
sandbox_nb = REPO_ROOT / "sandbox" / "sandbox.ipynb"
104+
if sandbox_nb.exists():
105+
toc.append({
106+
"title": "Sandbox",
107+
"children": [{"title": "Sandbox", "file": "sandbox/sandbox.ipynb"}],
108+
})
109+
110+
try:
111+
with open(MYST_PATH, "r") as f:
112+
data = yaml.safe_load(f)
113+
except yaml.YAMLError as e:
114+
print(f"Error: invalid YAML in {MYST_PATH}: {e}", file=sys.stderr)
115+
return EXIT_ERROR
116+
117+
if data is None:
118+
data = {}
119+
if "project" not in data:
120+
data["project"] = {}
121+
122+
old_toc = data["project"].get("toc", [])
123+
if old_toc == toc:
124+
return EXIT_SUCCESS
125+
126+
data["project"]["toc"] = toc
127+
with open(MYST_PATH, "w") as f:
128+
yaml.dump(data, f, default_flow_style=False, allow_unicode=True, sort_keys=False)
129+
130+
return EXIT_SUCCESS
131+
132+
133+
if __name__ == "__main__":
134+
try:
135+
sys.exit(main())
136+
except Exception as e:
137+
print(f"Error: {e}", file=sys.stderr)
138+
sys.exit(EXIT_ERROR)

‎.github/workflows/jupyter-book.yml‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Jupyter Book (MyST) GitHub Pages Deploy
2+
# Ensure your GitHub Pages settings for this repository are set to deploy with GitHub Actions.
3+
# On push to main, syncs myst.yml TOC with notebooks on disk (adds any new lec/lab/hw), then builds and deploys.
4+
5+
name: Jupyter Book (MyST) GitHub Pages Deploy
6+
7+
on:
8+
push:
9+
branches: [main]
10+
workflow_dispatch:
11+
12+
env:
13+
BASE_URL: /materials-sp26
14+
15+
permissions:
16+
contents: write # needed to push updated myst.yml when new notebooks are added
17+
pages: write
18+
id-token: write
19+
20+
concurrency:
21+
group: 'pages'
22+
cancel-in-progress: false
23+
24+
jobs:
25+
deploy:
26+
environment:
27+
name: github-pages
28+
url: ${{ steps.deployment.outputs.page_url }}
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
- name: Sync myst.yml TOC with notebooks
35+
run: |
36+
pip install pyyaml --quiet
37+
python3 .github/sync-myst-toc.py
38+
- name: Commit and push updated myst.yml
39+
run: |
40+
if ! git diff --exit-code myst.yml >/dev/null; then
41+
git config user.name "github-actions[bot]"
42+
git config user.email "github-actions[bot]@users.noreply.github.com"
43+
git add myst.yml
44+
git commit -m "chore: sync myst.yml TOC with notebooks"
45+
git push
46+
fi
47+
- name: Setup Pages
48+
uses: actions/configure-pages@v3
49+
- uses: actions/setup-node@v4
50+
with:
51+
node-version: 18.x
52+
- name: Install Jupyter Book (via myst)
53+
run: npm install -g jupyter-book
54+
- name: Build HTML Assets
55+
run: jupyter-book build --html
56+
- name: Upload artifact
57+
uses: actions/upload-pages-artifact@v3
58+
with:
59+
path: './_build/html'
60+
- name: Deploy to GitHub Pages
61+
id: deployment
62+
uses: actions/deploy-pages@v4

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ instance/
7171
# Sphinx documentation
7272
docs/_build/
7373

74+
# Jupyter Book / MyST build output
75+
_build/
76+
7477
# PyBuilder
7578
.pybuilder/
7679
target/

‎favicon.ico‎

14.7 KB
Loading

‎intro.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Data 8 Materials (Spring 2026)
2+
3+
Welcome to the **Data 8: Foundations of Data Science** course materials for Spring 2026 at UC Berkeley.
4+
5+
This book contains:
6+
7+
- **Lectures:** in-class demos and code
8+
- **Labs:** guided exercises
9+
- **Homework:** assignments
10+
- **Sandbox:** a playground notebook with datasets for exploration
11+
12+
Use the sidebar to navigate. To run notebooks interactively, use [DataHub](https://data8.datahub.berkeley.edu) (course students) or the "Run in Binder" link above.
13+
14+
For the full course website, see [Data 8 Spring 2026](https://www.data8.org/sp26/).

‎lec/lec10/cones.csv‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Flavor,Color,Price
2+
strawberry,pink,3.55
3+
chocolate,light brown,4.75
4+
chocolate,dark brown,5.25
5+
strawberry,pink,5.25
6+
chocolate,dark brown,5.25
7+
bubblegum,pink,4.75

0 commit comments

Comments
 (0)