Skip to content

MAINT: Add pre-commit hook to strip kernelspec from jupytext .py files#1637

Merged
romanlutz merged 1 commit intomicrosoft:mainfrom
romanlutz:strip-py-kernelspec
Apr 22, 2026
Merged

MAINT: Add pre-commit hook to strip kernelspec from jupytext .py files#1637
romanlutz merged 1 commit intomicrosoft:mainfrom
romanlutz:strip-py-kernelspec

Conversation

@romanlutz
Copy link
Copy Markdown
Contributor

Summary


bstripout\ already strips \metadata.kernelspec\ from .ipynb\ files, but jupytext .py\ files can accumulate kernelspec blocks (\display_name, \language,
ame) that leak local environment details into the repo.

This adds a new pre-commit hook (\strip-py-kernelspec) that automatically removes these blocks from \doc/**/*.py\ files.

Changes

  • New: \�uild_scripts/strip_py_kernelspec.py\ — script that strips # kernelspec:\ blocks from jupytext YAML headers
  • Updated: .pre-commit-config.yaml\ — added hook entry for \doc/**/*.py\ files
  • Cleaned up: Stripped existing kernelspec blocks from 21 doc .py\ files

Motivation

Discovered during PR #1633 review — a contributor's local kernelspec (\pyrit-dev) was committed via a jupytext .py\ file. This hook prevents it from happening again.

nbstripout already strips metadata.kernelspec from .ipynb files, but
jupytext .py files can accumulate kernelspec blocks (display_name,
language, name) that leak local environment details into the repo.

This adds a new pre-commit hook (strip-py-kernelspec) that automatically
removes these blocks from doc/**/*.py files. Also strips existing
kernelspec blocks from the 21 files that had them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@jbolor21 jbolor21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! thanks Roman!!

@romanlutz romanlutz merged commit 64b97e4 into microsoft:main Apr 22, 2026
39 checks passed
@romanlutz romanlutz deleted the strip-py-kernelspec branch April 22, 2026 15:46
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.

2 participants