Skip to content

🐛 fix(patch): detect python -m pre_commit#115

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:main
Feb 18, 2026
Merged

🐛 fix(patch): detect python -m pre_commit#115
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:main

Conversation

@gaborbernat
Copy link
Member

@gaborbernat gaborbernat commented Feb 18, 2026

Running python -m pre_commit bypassed the uv patching entirely because the .pth file's detection logic didn't account for how Python populates sys.argv during module execution. When invoked with -m, Python sets sys.argv[0] to "-m" during site initialization (when the .pth file runs), stripping the module name from the arguments. This meant tox configs using {env_python} -m pre_commit would silently fall back to vanilla pre-commit without uv.

The fix uses sys.orig_argv (available since Python 3.10, which is the project's minimum) to inspect the original command line and detect when pre_commit is the -m target module. The detection logic was also extracted into a standalone function to keep the boolean expression count within linting limits.

Fixes #80

During .pth processing, sys.argv is ["-m", ...] without the module name.
The patch detection missed this case, so `python -m pre_commit` ran
without uv. Use sys.orig_argv (available since Python 3.10) to check
for the pre_commit module name.

Fixes tox-dev#80
@gaborbernat gaborbernat added the bug Something isn't working label Feb 18, 2026
@gaborbernat gaborbernat enabled auto-merge (squash) February 18, 2026 04:51
@gaborbernat gaborbernat merged commit ae408c3 into tox-dev:main Feb 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

python -m pre_commit does not work

1 participant