fix(ci): green main again — notebooks extra is an aggregate; no Dockerfile heredoc
Some checks failed
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / notebooks-smoke (push) Has been cancelled
Deploy / api (push) Has been cancelled
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled
Deploy / zotero (push) Has been cancelled
Deploy / docs (push) Has been cancelled
Deploy / changes (push) Has been cancelled
Deploy / notebooks (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Deploy / report (push) Has been cancelled
Infra CI / notebooks (push) Successful in 1m24s
Infra CI / zotero (push) Successful in 18s
Infra CI / docs (push) Successful in 31s
Infra CI / api (push) Successful in 27s
Infra CI / llm (push) Successful in 48s
Infra CI / bcda (push) Successful in 55s
Infra CI / mc (push) Successful in 48s

Both breaks came from my notebooks-deps change (718db68) and went red on
every push since:

- ci/lint: gen_config.py --check requires each optional-dependency group
  to name a module; `notebooks` is an aggregate like `all` and `lake`, so
  it joins meta_groups.
- infra-ci/notebooks: hadolint 2.12 can't parse a RUN heredoc. The
  requirements expander moves to infra/images/notebooks/
  notebook_requirements.py; its output is byte-identical, the rebuilt
  image's layers match the running one, and hadolint is clean.

Neither is covered by the pre-commit hook, which is how they got past it.
This commit is contained in:
kert
2026-10-29 16:58:50 -04:00
parent 154fff36c2
commit a497075ba5
3 changed files with 51 additions and 36 deletions

View File

@@ -185,7 +185,7 @@ def check_modules() -> list[str]:
)
opt_deps = set(pyproject.get("project", {}).get("optional-dependencies", {}).keys())
# Groups that are aggregates or cloud providers, not Python modules
meta_groups = {"all", "lake", "dev", "aws", "gcp", "azure"}
meta_groups = {"all", "lake", "dev", "aws", "gcp", "azure", "notebooks"}
errors = []
for mod in sorted(module_names):

View File

@@ -72,43 +72,16 @@ RUN uv build --wheel
# ---- stage 2b: notebook requirements ----------------------------------------
#
# Notebooks import src/ (bind-mounted, on PYTHONPATH), so the image needs the
# stack's base dependencies plus pyproject's `notebooks` extra. Expand its
# stack[...] self-references into plain requirements here; the heavy install
# layer below then rebuilds only when that list changes, not on every
# pyproject edit. `uv add` keeps just the last spec it sees per package, so
# repeated names (duckdb comes from four extras) fold into one requirement.
# stack's base dependencies plus pyproject's `notebooks` extra, expanded by
# infra/images/notebooks/notebook_requirements.py. Generating the list in
# its own stage means the heavy install layer below rebuilds only when the
# list changes, not on every pyproject edit. (A script file, not a RUN
# heredoc: hadolint can't parse heredocs.)
FROM ghcr.io/astral-sh/uv:0.13.2-python3.13-trixie-slim AS nbreqs
COPY pyproject.toml /pyproject.toml
RUN python3 - > /notebooks-requirements.txt <<'PY'
import re, tomllib
project = tomllib.load(open("/pyproject.toml", "rb"))["project"]
extras = project["optional-dependencies"]
reqs, seen = list(project["dependencies"]), set()
def walk(extra):
if extra in seen:
return
seen.add(extra)
for req in extras[extra]:
if m := re.fullmatch(r"stack\[([\w,-]+)\]", req):
for sub in m.group(1).split(","):
walk(sub)
else:
reqs.append(req)
walk("notebooks")
merged = {}
for req in reqs:
name, ext, spec = re.fullmatch(r"([\w.-]+)(?:\[([^\]]*)\])?\s*([^;]*)", req).groups()
_, e, s = merged.setdefault(re.sub(r"[-_.]+", "-", name).lower(), [name, set(), []])
e.update(x.strip() for x in (ext or "").split(",") if x.strip())
s.extend(c.strip() for c in spec.split(",") if c.strip() and c.strip() not in s)
for name, e, s in merged.values():
print(name + (f"[{','.join(sorted(e))}]" if e else "") + ",".join(s))
PY
RUN cat /notebooks-requirements.txt
COPY pyproject.toml infra/images/notebooks/notebook_requirements.py /
RUN python3 /notebook_requirements.py /pyproject.toml > /notebooks-requirements.txt \
&& cat /notebooks-requirements.txt
# ---- stage 3: runtime -------------------------------------------------------

View File

@@ -0,0 +1,42 @@
"""Print the notebooks image's requirements from pyproject.toml.
The base dependencies plus the `notebooks` extra, with its stack[...]
self-references expanded into plain requirements. `uv add` keeps just the
last spec it sees per package, so repeated names (duckdb comes from four
extras) fold into one requirement with every clause kept.
python3 notebook_requirements.py pyproject.toml > requirements.txt
"""
import re
import sys
import tomllib
project = tomllib.load(open(sys.argv[1], "rb"))["project"]
extras = project["optional-dependencies"]
reqs, seen = list(project["dependencies"]), set()
def walk(extra: str) -> None:
if extra in seen:
return
seen.add(extra)
for req in extras[extra]:
if m := re.fullmatch(r"stack\[([\w,-]+)\]", req):
for sub in m.group(1).split(","):
walk(sub)
else:
reqs.append(req)
walk("notebooks")
merged: dict[str, list] = {}
for req in reqs:
name, ext, spec = re.fullmatch(
r"([\w.-]+)(?:\[([^\]]*)\])?\s*([^;]*)", req
).groups()
_, e, s = merged.setdefault(re.sub(r"[-_.]+", "-", name).lower(), [name, set(), []])
e.update(x.strip() for x in (ext or "").split(",") if x.strip())
s.extend(c.strip() for c in spec.split(",") if c.strip() and c.strip() not in s)
for name, e, s in merged.values():
print(name + (f"[{','.join(sorted(e))}]" if e else "") + ",".join(s))