fix: remove hardcoded Unix venv activation from pre-commit hooks - #6884
fix: remove hardcoded Unix venv activation from pre-commit hooks#6884shubandaniil-beep wants to merge 1 commit into
Conversation
The local hooks sourced .venv/bin/activate directly, which doesn't exist on Windows (activation script lives under .venv\Scripts\ there). uv run already resolves the project's virtual environment on its own, so the explicit activation step is unnecessary and platform-specific. Fixes crewAIInc#6863
📝 WalkthroughWalkthroughThe pre-commit configuration removes explicit ChangesPre-commit hook execution
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.pre-commit-config.yaml:
- Around line 6-18: Remove the Unix-specific bash -c wrappers from the ruff,
ruff-format, and mypy hooks, replacing each entry with its direct uv run command
while preserving existing arguments and hook settings. Update the pip-audit
entry similarly, retaining the existing --skip-editable and complete
--ignore-vuln list and its pass_filenames behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 530a9555-b071-4e7b-a2ae-bae55fe99119
📒 Files selected for processing (1)
.pre-commit-config.yaml
| entry: bash -c 'uv run ruff check --config pyproject.toml "$@"' -- | ||
| language: system | ||
| pass_filenames: true | ||
| types: [python] | ||
| - id: ruff-format | ||
| name: ruff-format | ||
| entry: bash -c 'source .venv/bin/activate && uv run ruff format --config pyproject.toml "$@"' -- | ||
| entry: bash -c 'uv run ruff format --config pyproject.toml "$@"' -- | ||
| language: system | ||
| pass_filenames: true | ||
| types: [python] | ||
| - id: mypy | ||
| name: mypy | ||
| entry: bash -c 'source .venv/bin/activate && uv run mypy --config-file pyproject.toml "$@"' -- | ||
| entry: bash -c 'uv run mypy --config-file pyproject.toml "$@"' -- |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== files =="
git ls-files | sed -n '1,120p'
echo
echo "== pre-commit config =="
cat -n .pre-commit-config.yaml
echo
echo "== search for uv/pre-commit/windows bash =="
rg -n "language: system|entry: bash|bash|uv run|RUFF|MYPY|pre-commit|windows|GIT" .pre-commit-config.yaml pyproject.toml 2>/dev/null || trueRepository: crewAIInc/crewAI
Length of output: 8284
🌐 Web query:
pre-commit language: system entry bash executable Windows pass_filenames true appended files entry command
💡 Result:
When using language: system in pre-commit, filenames are automatically appended to the command specified in the entry field as a list of space-separated arguments [1][2][3]. Pre-commit does not provide a native configuration option to change this default behavior [2][4]. On Windows, if you are calling a bash script or a command that cannot handle multiple filenames passed as arguments, you can work around this by using a wrapper command in the entry field to process the filenames individually [1][2]. Common workarounds: 1. Use bash -c with a loop: If you have Git Bash available on Windows, you can use a bash command that iterates over the arguments [1][2]: entry: bash -c 'for file in "$@"; do mycommand "$file"; done' -- (Note: The -- at the end is important to ensure proper argument handling [2].) 2. Use xargs: Alternatively, you can use xargs to execute the command for each file individually [2]: entry: bash -c 'printf "%s\0" "$@" | xargs -0 -n1 mycommand' -- Important considerations: - Windows Compatibility: Using language: system with bash-specific commands requires that the user has a bash environment (like Git Bash) installed and accessible in their system PATH [5]. - Inefficiency: Pre-commit intentionally does not support one-file-at-a-time execution by default because it is less performant than batching files [2]. Using loops or xargs as shown above effectively bypasses this batching, which may increase execution time for large numbers of files [2]. - Command Limits: Be aware that operating systems have limits on the maximum length of command-line arguments, which is why pre-commit manages file batching automatically [6]. While you cannot guarantee a single-process execution for all files, you can use require_serial: true to force the hook to run in a single process, preventing parallel execution and often resulting in larger batches per call [6].
Citations:
- 1: Allow passing files as single arguments to system command pre-commit/pre-commit#1728
- 2: https://stackoverflow.com/questions/77245249/using-pre-commit-tool-is-there-a-way-to-pass-filenames-one-by-one-to-the-entry
- 3: https://deepwiki.com/pre-commit/pre-commit/3.6-system-languages
- 4: Add hook option to not pass matching files as arguments to the program pre-commit/pre-commit#527
- 5: https://tenthirtyam.org/dispatches/2026/03/28/elevate-your-git-workflow-a-guide-to-using-pre-commit/
- 6: https://stackoverflow.com/questions/78318051/run-pre-commit-hook-with-pass-filenames-true-only-once-with-all-filenames
Remove the remaining bash -c dependency.
These language: system hooks still call Unix-specific bash before uv run starts, so Windows users without Git Bash fail outside the tool execution. Use direct uv run ... entries for ruff, ruff-format, and mypy.
For pip-audit, remove the bash -c wrapper too; use the current --skip-editable ... --ignore-vuln GHSA-f4j7-r4q5-qw2c' -- entry without changing the long --ignore-vuln list, since it has pass_filenames: false.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.pre-commit-config.yaml around lines 6 - 18, Remove the Unix-specific bash
-c wrappers from the ruff, ruff-format, and mypy hooks, replacing each entry
with its direct uv run command while preserving existing arguments and hook
settings. Update the pip-audit entry similarly, retaining the existing
--skip-editable and complete --ignore-vuln list and its pass_filenames behavior.
Summary
pre-commithooks (ruff,ruff-format,mypy,pip-audit) sourced.venv/bin/activatedirectly, which doesn't exist on Windows (activation script lives under.venv\Scripts\there), so all hooks failed before running.uv runalready resolves the project's virtual environment on its own, so the explicitsource .venv/bin/activate &&step is unnecessary and platform-specific. Removed it from all four hook entries.Fixes #6863
Test plan
uv run --with pre-commit pre-commit run ruff --all-fileslocally — hook executes and reports lint results instead of failing with.venv/bin/activate: No such file or directory.pre-commit-config.yamlstill parses as valid YAML