Microsoft/vscode

Better integration of pre-commit hooks with Python virtual environments.

Open

#265,613 建立於 2025年9月8日

在 GitHub 查看
 (0 留言) (2 反應) (1 負責人)TypeScript (10,221 fork)batch import
feature-requestgithelp wanted

倉庫指標

Star
 (74,848 star)
PR 合併指標
 (平均合併 11小時 43分鐘) (30 天內合併 1,000 個 PR)

描述

Currently, pre-commit hooks inside VS Code cannot find tools installed in a project’s virtual environment unless VS Code itself is launched from within that environment.

Example

  • I have a pre-commit hook configured to run isort.
  • If I open the project directly in VS Code, pre-commit fails because isort cannot be found.
  • If instead I activate the virtual environment in a terminal and then start VS Code with code ., the environment is inherited correctly and pre-commit works.

This makes the workflow inconvenient since developers must remember to always launch VS Code from an activated venv.


Steps to Reproduce

  1. Create a Python project with a virtual environment.
  2. Install isort (or another tool) in the venv.
  3. Add a .pre-commit-config.yaml with a hook that uses the tool.
  4. Open the project in VS Code without starting from the venv.
  5. Run a commit → pre-commit fails with tool not found.

Expected Behavior / Feature Proposal

It would be very useful if VS Code could automatically detect and use the project’s Python virtual environment when running pre-commit hooks.
This way, pre-commit would always work consistently regardless of how VS Code was launched.


Why This Matters

  • Improves developer experience by reducing friction.
  • Makes pre-commit integration more reliable for Python projects.
  • Aligns with how VS Code already handles selecting Python interpreters for debugging and linting.

貢獻者指南