pre-commit 给 mirrors-mypy 错误,我该如何解决?

pre-commit giving error with mirrors-mypy, how do I fix it?

我在 运行 宁“预提交 运行 --all-files” 时收到以下错误,并且在尝试提交时出现一些 python 错误, python 使用的版本是“Python 2.7.16”.

[INFO] Installing environment for https://github.com/pre-commit/mirrors-mypy.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/Users/user/.cache/pre-commit/repoq_mv31g8/py_env-default/bin/python', '-mpip', 'install', '.', 'tokenize-rt==3.2.0', 'pydantic')
return code: 1
expected return code: 0
stdout:
    Processing /Users/user/.cache/pre-commit/repoq_mv31g8
      Preparing metadata (setup.py): started
      Preparing metadata (setup.py): finished with status 'done'
    Collecting tokenize-rt==3.2.0
      Using cached tokenize_rt-3.2.0-py2.py3-none-any.whl (6.1 kB)
    Collecting pydantic
      Using cached pydantic-1.9.0-cp310-cp310-macosx_11_0_arm64.whl (2.4 MB)
    Collecting mypy==0.782
      Using cached mypy-0.782-py3-none-any.whl (2.4 MB)
    Collecting mypy-extensions<0.5.0,>=0.4.3
      Using cached mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
    Collecting typing-extensions>=3.7.4
      Using cached typing_extensions-4.1.1-py3-none-any.whl (26 kB)
    Collecting typed-ast<1.5.0,>=1.4.0
      Using cached typed_ast-1.4.3.tar.gz (210 kB)
      Preparing metadata (setup.py): started
      Preparing metadata (setup.py): finished with status 'done'
    Building wheels for collected packages: pre-commit-dummy-package, typed-ast
      Building wheel for pre-commit-dummy-package (setup.py): started
      Building wheel for pre-commit-dummy-package (setup.py): finished with status 'done'
      Created wheel for pre-commit-dummy-package: filename=pre_commit_dummy_package-0.0.0-py3-none-any.whl size=1154 sha256=ea7d756fd19dee0f5f03851e3e343db4194f4b306f21fecb796b4d6d89d266fb
      Stored in directory: /private/var/folders/v4/nlc505k12rn9pf4c9kntz8qm0000gn/T/pip-ephem-wheel-cache-4jcph5rz/wheels/80/78/0d/746d1697141e342b257e21c980fc51ac134e6b6400568c3646
      Building wheel for typed-ast (setup.py): started
      Building wheel for typed-ast (setup.py): finished with status 'error'
      Running setup.py clean for typed-ast
    Successfully built pre-commit-dummy-package
    Failed to build typed-ast
    Installing collected packages: typed-ast, mypy-extensions, typing-extensions, tokenize-rt, pydantic, mypy, pre-commit-dummy-package
      Running setup.py install for typed-ast: started
      Running setup.py install for typed-ast: finished with status 'error'
    
stderr:
      error: subprocess-exited-with-error
      
      × python setup.py bdist_wheel did not run successfully.
      │ exit code: 1
      ╰─> [22 lines of output]
          running bdist_wheel
          running build
          running build_py
          package init file 'ast3/tests/__init__.py' not found (or not a regular file)
          running build_ext
          building '_ast27' extension
          building '_ast3' extension
          ast3/Python/ast.c:844:5: warning: code will never be executed [-Wunreachable-code]
              abort();
              ^~~~~
          ast3/Python/ast.c:4514:9: error: implicit declaration of function '_PyUnicode_DecodeUnicodeEscape' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
              v = _PyUnicode_DecodeUnicodeEscape(s, len, NULL, &first_invalid_escape);
                  ^
          ast3/Python/ast.c:4514:9: note: did you mean 'PyUnicode_DecodeUnicodeEscape'?
          /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10/unicodeobject.h:608:23: note: 'PyUnicode_DecodeUnicodeEscape' declared here
          PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape(
                                ^
          ast3/Python/ast.c:4514:7: warning: incompatible integer to pointer conversion assigning to 'PyObject *' (aka 'struct _object *') from 'int' [-Wint-conversion]
              v = _PyUnicode_DecodeUnicodeEscape(s, len, NULL, &first_invalid_escape);
                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          2 warnings and 1 error generated.
          error: command '/usr/bin/clang' failed with exit code 1
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
      ERROR: Failed building wheel for typed-ast
      error: subprocess-exited-with-error
      
      × Running setup.py install for typed-ast did not run successfully.
      │ exit code: 1
      ╰─> [24 lines of output]
          running install
          /Users/user/.cache/pre-commit/repoq_mv31g8/py_env-default/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
            warnings.warn(
          running build
          running build_py
          package init file 'ast3/tests/__init__.py' not found (or not a regular file)
          running build_ext
          building '_ast27' extension
          building '_ast3' extension
          ast3/Python/ast.c:844:5: warning: code will never be executed [-Wunreachable-code]
              abort();
              ^~~~~
          ast3/Python/ast.c:4514:9: error: implicit declaration of function '_PyUnicode_DecodeUnicodeEscape' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
              v = _PyUnicode_DecodeUnicodeEscape(s, len, NULL, &first_invalid_escape);
                  ^
          ast3/Python/ast.c:4514:9: note: did you mean 'PyUnicode_DecodeUnicodeEscape'?
          /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10/unicodeobject.h:608:23: note: 'PyUnicode_DecodeUnicodeEscape' declared here
          PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape(
                                ^
          ast3/Python/ast.c:4514:7: warning: incompatible integer to pointer conversion assigning to 'PyObject *' (aka 'struct _object *') from 'int' [-Wint-conversion]
              v = _PyUnicode_DecodeUnicodeEscape(s, len, NULL, &first_invalid_escape);
                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          2 warnings and 1 error generated.
          error: command '/usr/bin/clang' failed with exit code 1
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: legacy-install-failure
    
    × Encountered error while trying to install package.
    ╰─> typed-ast
    
    note: This is an issue with the package mentioned above, not pip.
    hint: See above for output from the failure.
    
Check the log at /Users/user/.cache/pre-commit/pre-commit.log

我运行在 Apple M1 Air (macOS Big Sur) 上安装它,我遗漏了什么或者这是一个已知的 M1 问题? 我试过手动安装 pydantic,pre-commit 是由 brew 安装的。 提前致谢

预提交配置:

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.0.1
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-yaml
    -   id: check-added-large-files

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

-   repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.782
    hooks:
    -   id: mypy
        additional_dependencies: [pydantic]

您正在安装一个非常旧版本的 mypy (0.782),它依赖于不支持 M1

的旧版本 typed-ast (<1.5.0)

您通常可以通过 运行 pre-commit autoupdate 获取最新版本——或者选择比 0.900 更新的版本(mypy 开始支持 M1)


免责声明:我创建了 pre-commit