18

When using https://pre-commit.com with VSCode hooks that depend on packages installed in a Python venv. In pre-commit on can specify to use "system" as environment. This works great from the terminal with desired venv active.

However using the integrated source control it seems that global interpeter is accessed and thus required packages are not available.

Is there a workaround here? As for now I specify the entrypoint "path/to/bin/python -m package" in pre-commit config. However I do think that also the integrated source control should respect at least the selected interpeter.

Any thoughts?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Martin Gran
  • 241
  • 1
  • 2
  • 5

1 Answers1

2

VSCode seems to choose willy-nilly what it respects and what it doesn't. I have the same situation - committing on the integrated terminal works fine; doing it from the Source Control sidebar gives me a "Python can't be found" message (which only appeared after installing a pre-commit hook).

My guess is you'll have to, by trial and error, install pre-commit in every Python installation in your system until you find which one the sidebar is invoking.

darda
  • 3,597
  • 6
  • 36
  • 49
  • I have no solution, but a similar problem here. I have a pre-commit hook installed, commitlint, along with other hooks (eslint...). When I try to commit from the Source Control sidebar, eslint passes while commitlint fails because "Executable `commitlint` not found". However, I have no problem commiting with the integrated terminal. Somewhere, the Source Control doesn't search the executable where it should. – ToddEmon Aug 09 '21 at 14:50
  • 1
    VSCode seems to use the venv it is started in. If you open a terminal, activate a venv and start code from inside the venv git uses the activated venv. – Arigion Nov 24 '21 at 14:55
  • Has anyone found a solution for this? I have JS projects, where the git hook works when using the terminal, but using the vscode source control, the hook is ignored. – nerz Jun 08 '22 at 20:24