COMP: Run kw commit-msg hooks via pre-commit-managed Python#6522
COMP: Run kw commit-msg hooks via pre-commit-managed Python#6522hjmjohnson wants to merge 1 commit into
Conversation
The kw-commit-msg and kw-prose-budget hooks invoked Utilities/Hooks/run-pixi-python.sh, which hardcoded the CWD-relative path ./.pixi/envs/pre-commit/bin/python. That pixi environment is per-worktree and only exists where `pixi install -e pre-commit` has run, so the hooks failed in fresh git worktrees that built with a different pixi environment. Use pre-commit's own managed Python environment (language: python), matching the other repo hooks whose envs live in the shared pre-commit cache. The scripts are stdlib-only, so no additional dependencies are required. Remove the now-unused launcher.
|
| Filename | Overview |
|---|---|
| .pre-commit-config.yaml | Updates the two commit-message hook entries to use pre-commit-managed Python while keeping the same script invocation shape. |
| Utilities/Hooks/run-pixi-python.sh | Removes the pixi-specific launcher after the changed hook entries no longer reference it. |
Reviews (1): Last reviewed commit: "COMP: Run kw commit-msg hooks via pre-co..." | Re-trigger Greptile
dzenanz
left a comment
There was a problem hiding this comment.
LGTM, but I am unfamiliar with this.
|
@hjmjohnson I had looked into this issue before. As I recall Matt reported a specific issue in certain windows environments with which python was used. As I looked into it as I recall pre-commit invokes installed python hooks differently than local hooks that are marked as python. |
|
@thewtex Can you provide any more information related to @blowekamp comments? The issue I keep having is that worktrees keep hanging on kwstyle pre-commit. If you have an alternate strategy, I'd like to document that. |
The
kw-commit-msgandkw-prose-budgethooks ran viaUtilities/Hooks/run-pixi-python.sh, which hardcoded the CWD-relative path./.pixi/envs/pre-commit/bin/python. That pixi environment is per-worktree and only exists wherepixi install -e pre-commithas run, so the hooks fail in freshgit worktrees built with a different pixi environment. This moves the two hooks onto pre-commit's own managed-environment mechanism (language: python) — the same one already used by gersemi/clang-format/black — and removes the launcher.Why this is the right mechanism
~/.cache/pre-commit(keyed to the repo, reused across all worktrees), not in per-worktree.pixi/envs/.kw-commit-msg.pyandkw-prose-budget.pyimport only the standard library (os,re,subprocess,sys,pathlib), so noadditional_dependenciesare needed.run-pixi-python.sh, added 2025-06-26) post-dated pre-commit adoption (2024-12-04); it reached for the pixi env instead of pre-commit's own env management.Local verification
Reproduced the original failure in a fresh worktree, then with the pixi
pre-commitenv deleted confirmed pre-commit builds its own venv and both hooks pass:pre-commit run --all-filesis green (gersemi, clang-format, black, all checks).