pre-commit使用black最新版本运行 python23.11.0会导致有线InvalidManifestError.
摘自.pre-commit-config.yaml
repos:\n-   repo: https://github.com/psf/black\n    rev: 23.11.0\n    hooks:\n    -   id: black\n        types: []\n        files: ^.*.pyi?$  # format .py and .pyi files`\n输出消息:
\n\xe2\x94\x82 \xe2\x94\x82      stdout = \'An error has occurred: InvalidManifestError: \\n==> File                       \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82               /Users/robot/.cache/pre-c\'+329                                                 \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82 stdout_list = [                                                                              \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82               \xe2\x94\x82   \'An error has occurred: InvalidManifestError: \\n\',                         \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82               \xe2\x94\x82   \'==> File                                                                  \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82               /Users/robot/.cache/pre-commit/repoxhmwyits/.pre-commit-hooks.yaml\\n\',         \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82               \xe2\x94\x82 …我已经开始使用 Python 和 Django,我在这个领域很新。这是我第一次在这里提问……如果有已知的解决方案,我会提前道歉……
当我安装并设置 VSCode 格式化程序“黑色”(将 linter 设置为 flake8 之后)时,教程视频导师的一面会弹出类似“未安装格式化程序 autopep8”的弹出窗口。安装?'。& 我的没有显示该消息。
所以我所做的是...
底部代码来自 settings.json(在 vscode 文件夹中)。
{
  "python.linting.pylintEnabled": false,
  "python.linting.flake8Enabled": true,
  "python.linting.enabled": true,
  "python.formatting.provider": "black", # input manually
  "python.linting.flake8Args": ["--max-line-length=88"] # input manually
}
我找到了一个“黑色格式化程序”文档。https://github.com/psf/black & 它说... python -m black {source_file_or_directory} & 我收到以下错误消息。
    Usage: __main__.py [OPTIONS] [SRC]...
Try '__main__.py -h' for help.
Error: …我正在运行 git pre-commit并运行 black 作为钩子之一。
现在,当我运行时commit,黑色失败并说:
All done! ?  ?
15 files reformatted, 1 file left unchanged.
我查看了重新格式化的文件,我对它们很好。所以我暂存这些文件并commit再次尝试运行,但我不断收到与上述相同的消息。我尝试了以下命令但没有成功。
git add .
git add -A
git add -u
这是我的.pre-commit-config.yaml文件:
repos:
    -   repo: https://github.com/psf/black
        rev: 19.10b0
        hooks:
            - id: black
              language_version: python3.6
    -   repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v2.5.0
        hooks:
            -   id: check-merge-conflict
            -   id: check-docstring-first
            -   id: check-json
            -   id: check-yaml
            -   id: debug-statements
            -   id: double-quote-string-fixer
            -   id: end-of-file-fixer
            -   id: name-tests-test
                args: [--django]
            - …black每当我在 Sublime Text 3 中保存 Python 文件时,我都想申请。我该怎么做?
(如果有快速禁用它的方法可以加分)
此代码由black创建:
def test_schema_org_script_from_list():
    assert (
        schema_org_script_from_list([1, 2])
        == '<script type="application/ld+json">1</script>\n<script type="application/ld+json">2</script>'
    )
但现在 flake8 抱怨:
tests/test_utils.py:59:9: 二元运算符前的 W503 换行符
测试/test_utils.py:59:101: E501 行太长(105 > 100 个字符)
如何格式化上面的行并使 flake8 快乐?
我用这个 .pre-commit-config.yaml
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
  - repo: 'https://github.com/pre-commit/pre-commit-hooks'
    rev: v3.2.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-added-large-files
  - repo: 'https://gitlab.com/pycqa/flake8'
    rev: 3.8.4
    hooks:
      - id: flake8
  - repo: 'https://github.com/pre-commit/mirrors-isort'
    rev: v5.7.0
    hooks:
      - id: …我使用Black with Python 3.7(在VS Code中).
当我格式化我的代码时,数字文字用下划线标准化(例如1562202=> 1_562_202).
如何使用黑色格式而不使用下划线进行格式化?
注意 从黑色版本19.2b,这个问题已经过时了.
python-black ×7
python ×5
pre-commit ×2
flake8 ×1
git ×1
macros ×1
pycharm ×1
python-3.x ×1
sublimetext3 ×1