Skip to content

feat: inject Colab setup cell into every generated notebook#125

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/colab-maturity
Jul 9, 2026
Merged

feat: inject Colab setup cell into every generated notebook#125
Jammy2211 merged 1 commit into
mainfrom
feature/colab-maturity

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Census (#124) found only 9 of 489 published notebooks carry a Colab setup cell, while docs/READMEs link 100+ notebooks to Colab — every other notebook dies on ModuleNotFoundError. This makes coverage structural: build_util.inject_colab_setup(notebook, project) prepends the standard setup cell pair (markdown explainer + setup_colab.setup("<project>") code cell) after the title cell of every notebook generated by generate.py / generate_autofit.py. Hand-written setups are detected and skipped; an unknown project fails generation loudly. At the next release, all notebooks regenerate Colab-ready with zero per-script maintenance.

Also documents the end-to-end Colab architecture (bootstrap → injection → URL bumper → Heart sweep) in docs/internals.md.

Part of #124 (Colab maturity, phase 1).

Release coupling: merge together with the PyAutoConf registry PR (same branch name there) — the injected cell calls setup_colab.setup(), which ships in the next autoconf release; notebooks only regenerate at release time, so ordering is safe by construction.

API Changes

None — internal changes only (notebook generation pipeline; no published package API).

Test Plan

  • python3 -m pytest tests/ — 78 passed (7 new in test_inject_colab_setup.py: placement after title cell, top placement without title, skip on hand-written setup, idempotency, all six projects, unknown-project error, valid nbformat JSON)
  • End-to-end locally: py_to_notebook + injection on HowToLens/.../tutorial_1_grids_and_galaxies.py (cells placed correctly) and skip verified on autolens_workspace/.../imaging/start_here.py (hand-written setup preserved)
  • First CI exercise: next release's generate_notebooks jobs

🤖 Generated with Claude Code

build_util.inject_colab_setup(notebook, project) prepends a markdown
explainer + code cell calling setup_colab.setup("<project>") after the
notebook's title cell; notebooks whose script hand-writes a setup_colab
call are left untouched, and an unknown project fails generation loudly
(COLAB_PROJECTS must track the PyAutoConf registry). Wired into both
generate.py conversion sites and generate_autofit.py, so every notebook
published at the next release is Colab-runnable by construction
(previously 9 of 489 had a setup cell).

docs/internals.md gains a "Google Colab architecture" section covering
the four pieces (bootstrap, injection, URL bumper, Heart sweep); the
bump_colab_urls entry now lists HowToFit.

Part of #124

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release Merged PR awaiting inclusion in the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant