Python 黑钩(语言:系统)

Python Black hooks (language: system)

我在预提交时使用黑色 这是钩子

- repo: https://github.com/psf/black
    rev: 19.10b0
    hooks:
      - id: black

这是我用于黑色的CI配置

 black --check .

它会在预提交中重新格式化一些文件 并在 CI

上构建项目时使其失败
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/migrations/0007_auto_20190616_0310.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/migrations/0011_auto_20190620_0517.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/migrations/0020_auto_20191030_0712.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/migrations/0021_auto_20191106_0013.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/migrations/0026_delete_comparison.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/migrations/0004_auto_20190613_1032.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/migrations/0005_auto_20190614_0405.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/views/session.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore_api_server/logger.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore_api_server/settings/base.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore_api_server/settings/local.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/models.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore_api_server/settings/production.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore_api_server/settings/test.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/migrations/0001_initial.py
reformatted /Users/rzuhairi/Documents/Anymotion/encore-api-server/encore/tests/serializers/test_drawing.py
All done! ✨  ✨
16 files reformatted, 119 files left unchanged.

然后当我把钩子改成这个

- repo: https://github.com/psf/black
    rev: 19.10b0
    hooks:
      - id: black
        language: system
        language_version: python3

它不会重新格式化文件

我有两个问题:

  1. 这个钩子是什么意思:'language: system' 因为当我阅读 文档应该是 language: python?
  2. 有谁知道为什么我的 第一个钩子没有用,我的预提交保持黑色 自动更新我的文件?

what is this hooks means: 'language: system' because when I read the documentation it should be language: python?

这意味着它将只使用 black 在您的系统上指向的任何内容,而不是创建一个新的 virtualenv。

is anyone know why my first hook didn't work, and black in my pre-commit keep auto-updating my files?

不,但我最好的猜测是您使用的是 black 的不同版本。 black --version 的输出是什么?