Skip to content

chore(notebooks): a pre-commit hook that tidies the notebooks in a commit - #861

Merged
petercorke merged 1 commit into
mainfrom
chore/notebook-commit-hook
Oct 19, 2026
Merged

petercorke merged 1 commit into
mainfrom
chore/notebook-commit-hook

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Editing a notebook and committing it should be all there is to do. This adds a git pre-commit hook that does the notebook tidying (#859) for the notebooks in each commit, so that nobody has to remember to run clear_outputs.py. No change to the toolbox or to any notebook.

What changes

  • docs/notebooks/pre_commit.py: for each staged notebook it adds cell ids and regenerates the bootstrap cell (sync_bootstrap.py), then clears outputs, resets the editor metadata and writes the file as Jupyter does (clear_outputs.py), and stages the result. It refuses the commit, with a message, if a notebook still has merge conflict markers (before, the scripts failed with a JSON traceback).
  • python docs/notebooks/pre_commit.py --install writes a three-line stub into the git directory's hooks/ (shared by all worktrees), which runs the script in the repository being committed to. It does not overwrite a hook that is not its own. The code lives in the repository, so it survives a fresh clone.
  • docs/notebooks/README.md: the routine for editing a notebook is now "edit and commit", with the manual commands for anyone who does not install the hook. CI still runs both checks.

Tested with 3 new unit tests and by hand in a scratch git repository with the real hook installed: a notebook with outputs, an execution count and VS Code metadata was committed with none of them, with ids and canonical metadata; a commit of a notebook with conflict markers was refused. Written with AI assistance (Claude Code).

🤖 Generated with Claude Code

…mmit

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke enabled auto-merge (squash) October 19, 2026 21:22
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 8 high · 4 medium · 1 minor

Alerts:
⚠ 13 issues (≤ 0 issues of at least minor severity)

Results:
13 new issues

Category Results
Security 4 medium
1 minor
8 high

View in Codacy

🟢 Metrics 19 complexity · 0 duplication

Metric Results
Complexity 19
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit eee9488 into main Oct 19, 2026
22 of 23 checks passed
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (b853cb8) to head (8f4664f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #861   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        146     146           
  Lines      16846   16846           
=====================================
  Misses     16846   16846           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant