Skip to content

fix(hook): rewrite Windows python module invocations#2327

Open
fengjikui wants to merge 1 commit into
rtk-ai:developfrom
fengjikui:fix/hook-python-exe-rewrite
Open

fix(hook): rewrite Windows python module invocations#2327
fengjikui wants to merge 1 commit into
rtk-ai:developfrom
fengjikui:fix/hook-python-exe-rewrite

Conversation

@fengjikui

Copy link
Copy Markdown

Fixes #2326.

Summary

Windows Python invocations often use python.exe or a virtualenv interpreter path like .venv/Scripts/python.exe -m pytest. The rewrite registry only matched bare python / python3, so those canonical Windows forms bypassed the rtk pytest / rtk mypy rewrite rules.

This PR normalizes Python -m invocations before rule matching by:

  • taking the basename of the first command token, supporting both / and \ separators
  • stripping a trailing .exe case-insensitively
  • handling quoted interpreter paths with spaces, e.g. OneDrive-style paths
  • preserving the original command for exclusion checks, so user exclude_commands can still opt out of either the normalized or original form

The actual rewritten output remains the existing RTK command shape, e.g. rtk pytest tests/.

Validation

  • cargo fmt --check
  • cargo test discover::registry::tests
  • cargo clippy --all-targets -- -D warnings
  • cargo test -> 2148 passed, 8 ignored
  • CLI smoke:
    • python.exe -m pytest tests/ -> rtk pytest tests/
    • .venv/Scripts/python.exe -m pytest tests/ -> rtk pytest tests/
    • C:\repo\.venv\Scripts\python.exe -m pytest tests/ -> rtk pytest tests/
    • "C:\Users\me\OneDrive - Org\.venv\Scripts\python.exe" -m pytest tests/ -> rtk pytest tests/

The smoke commands returned exit code 3 because rtk rewrite uses that existing hook protocol for “rewrite available, ask for confirmation” when no explicit allow rule is configured.

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.

hook: python.exe and pathed venv interpreters bypass rewrite (Windows)

1 participant