Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode integrated source control and pre-commit

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?

like image 993
Martin Gran Avatar asked Oct 15 '20 10:10

Martin Gran


People also ask

How do I enable Source Control in VS Code?

If your workspace is on your local machine, you can enable Git source control by creating a Git repository with the Initialize Repository command. When VS Code doesn't detect an existing Git repository, the Source Control view will give you the options to Initialize Repository or Publish to GitHub.

How do you put a pre-commit on a hook?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.

What is VS Code integrated terminal?

Terminal Basics. Visual Studio Code includes a fully-featured integrated terminal that conveniently starts at the root of your workspace. It provides integration with the editor to support features like links and error detection. To open the terminal: Use the Ctrl+` keyboard shortcut with the backtick character.

How do I bypass pre-commit?

Quick tip if you want to skip the pre-commit validations and quickly want to get a commit out there. To get your commit through without running that pre-commit hook, use the --no-verify option. Voila, without pre-commit hooks running!


1 Answers

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.

like image 190
darda Avatar answered Oct 07 '22 22:10

darda