Skip to content

fix: remove hardcoded Unix venv activation from pre-commit hooks - #6884

Open
shubandaniil-beep wants to merge 1 commit into
crewAIInc:mainfrom
shubandaniil-beep:fix/precommit-windows-venv-activate
Open

fix: remove hardcoded Unix venv activation from pre-commit hooks#6884
shubandaniil-beep wants to merge 1 commit into
crewAIInc:mainfrom
shubandaniil-beep:fix/precommit-windows-venv-activate

Conversation

@shubandaniil-beep

Copy link
Copy Markdown

Summary

  • The local pre-commit hooks (ruff, ruff-format, mypy, pip-audit) sourced .venv/bin/activate directly, which doesn't exist on Windows (activation script lives under .venv\Scripts\ there), so all hooks failed before running.
  • uv run already resolves the project's virtual environment on its own, so the explicit source .venv/bin/activate && step is unnecessary and platform-specific. Removed it from all four hook entries.

Fixes #6863

Test plan

  • Ran uv run --with pre-commit pre-commit run ruff --all-files locally — hook executes and reports lint results instead of failing with .venv/bin/activate: No such file or directory
  • Validated .pre-commit-config.yaml still parses as valid YAML

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
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pre-commit configuration removes explicit .venv/bin/activate commands from Ruff, Ruff Format, Mypy, and pip-audit hooks. Existing command arguments and vulnerability ignore settings remain unchanged.

Changes

Pre-commit hook execution

Layer / File(s) Summary
Update pre-commit command execution
.pre-commit-config.yaml
Ruff, Ruff Format, Mypy, and pip-audit hooks use uv run without explicit virtual-environment activation. Existing arguments and audit settings remain unchanged.

Suggested reviewers: greysonlalonde

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states that the change removes hardcoded Unix virtual environment activation from pre-commit hooks.
Description check ✅ Passed The description explains the Windows failure, the configuration change, the affected hooks, and the validation performed.
Linked Issues check ✅ Passed The changes directly resolve issue #6863 by removing the Unix-specific activation step from all affected pre-commit hooks.
Out of Scope Changes check ✅ Passed The changes are limited to the four pre-commit hook entries required to fix the Windows compatibility issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between f7ba8e3 and 196472e.

📒 Files selected for processing (1)
  • .pre-commit-config.yaml

Comment thread .pre-commit-config.yaml
Comment on lines +6 to +18
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 "$@"' --

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 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 || true

Repository: 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:


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.

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.

[BUG] pre-commit hooks fail on Windows due to hardcoded Unix virtual environment path

1 participant