我pre-commit用來運行black flake8和isort我的代碼。
我跑了pre-commit install,正如預期的那樣,它創建了.git/hooks/pre-commit它,開頭如下:
#!/usr/bin/env python3.9
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
import os
import sys
...
鉤子在終端中作業正常:
$ git commit -am "remove commented block"
isort....................................................................Passed
black....................................................................Passed
flake8...................................................................Passed
[main f30007d] remove commented block
1 file changed, 4 deletions(-)
但是從 VSCode 的源代碼控制面板運行它會產生一個錯誤(命令輸出):
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
env: python3.9: No such file or directory
不知道這是從哪里來的。另外(雖然不確定這很重要)我python再次檢查:終端和 VSCode 選擇的 Python 解釋器都指向相同的/Users/victor/.pyenv/shims/python
uj5u.com熱心網友回復:
pyenv執行git命令時,VSCode 的源代碼控制面板未加載似乎是一個問題。
我嘗試將一些內容(如$(pyenv init -))移動到較早的 zsh 組態檔中.zshenv,但沒有幫助。
最后,指定完整路徑修復它
#!/usr/bin/env /Users/victor/.pyenv/shims/python3.9
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
import os
import sys
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/346817.html
標籤:Python 混帐 视觉工作室代码 预提交 预提交.com
