Cor*_*yer 7 python git pre-commit pre-commit-hook pre-commit.com
我们使用预提交来使用黑色格式化我们的 Python 代码,并在以下配置中进行配置.pre-commit-config.yaml:
repos:\n - repo: https://github.com/ambv/black\n rev: 20.8b1\n hooks:\n - id: black\n language_version: python3.7\nRun Code Online (Sandbox Code Playgroud)\n由于我们的包在不同的 Python 版本(例如,,3.7)中进行测试和使用,我希望能够在不同的 Python 版本上使用预提交 Hook。但是,当在 Python 上提交代码时,由于我的配置(见上文),我收到错误:3.83.93.8language_version
C:\\Users\\FooBar\\Documents\\Programmierung\\foo (dev -> origin)\n\xce\xbb git commit -m "Black file with correct black version"\n[INFO] Initializing environment for https://github.com/ambv/black.\n[INFO] Installing environment for https://github.com/ambv/black.\n[INFO] Once installed this environment will be reused.\n[INFO] This may take a few minutes...\nAn unexpected error has occurred: CalledProcessError: command: (\'c:\\\\users\\\\FooBar\\\\anaconda\\\\python.exe\', \'-mvirtualenv\', \'C:\\\\Users\\\\FooBar\\\\.cache\\\\pre-commit\\\\repobmlg3b_m\\\\py_env-python3.7\', \'-p\', \'python3.7\')\nreturn code: 1\nexpected return code: 0\nstdout:\n RuntimeError: failed to find interpreter for Builtin discover of python_spec=\'python3.7\'\n\nstderr: (none)\nCheck the log at C:\\Users\\FooBar\\.cache\\pre-commit\\pre-commit.log\nRun Code Online (Sandbox Code Playgroud)\n如何在不同的 Python 版本上启用预提交 Hook,例如仅在 Python 3 上?
\n提前致谢!
\nAnt*_*ile 13
一种方法是设置language_version: python3(这曾经是 的默认设置black)——language_version您实际使用的内容并不重要,因为黑色不使用它来选择格式化的语言目标(这是一个单独的选项)
一般来说,你不需要设置language_version为(1)钩子本身将设置一个合适的钩子或(2)它将默认为你当前运行的python
另请注意:您正在使用两次已弃用的黑色网址 - 现在是psf/black
__
免责声明:我创建了预提交,并且我是黑人贡献者
| 归档时间: |
|
| 查看次数: |
4237 次 |
| 最近记录: |