I use pre-commit
to run black
flake8
and isort
on my code.
I ran pre-commit install
and as expected it created .git/hooks/pre-commit
which starts like:
#!/usr/bin/env python3.9
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
import os
import sys
...
The hook works fine in the terminal:
$ git commit -am "remove commented block"
isort....................................................................Passed
black....................................................................Passed
flake8...................................................................Passed
[main f30007d] remove commented block
1 file changed, 4 deletions(-)
But running it from VSCode's Source Control Panel yields an error (command output):
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
env: python3.9: No such file or directory
Not sure where that comes from. In addition (not sure it matters though) I double checked: both the terminal's python
and VSCode's selected Python interpreter point to the same /Users/victor/.pyenv/shims/python
CodePudding user response:
It seemed to be an issue with pyenv
not being loaded by VSCode's source control panel when executing the git
commands.
I tried moving some stuff (like $(pyenv init -)
) into an earlier zsh configuration file like .zshenv
but that did not help.
In the end, specifying the complete path fixed it
#!/usr/bin/env /Users/victor/.pyenv/shims/python3.9
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
import os
import sys
...