使用mirrors-mypy 进行预提交错误,如何修复?

Par*_*ale 6 pre-commit pre-commit-hook mypy pre-commit.com apple-m1

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

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

我在 Apple M1 Air (macOS Big Sur) 上运行它,我缺少什么还是已知的 M1 问题?\n我已尝试手动安装 pydantic,预提交是由 brew 安装的。\n提前致谢

\n

预提交配置:

\n
repos:\n-   repo: https://github.com/pre-commit/pre-commit-hooks\n    rev: v4.0.1\n    hooks:\n    -   id: trailing-whitespace\n    -   id: end-of-file-fixer\n    -   id: check-yaml\n    -   id: check-added-large-files\n\n-   repo: https://github.com/psf/black\n    rev: 21.7b0\n    hooks:\n    -   id: black\n\n-   repo: https://github.com/pre-commit/mirrors-mypy\n    rev: v0.782\n    hooks:\n    -   id: mypy\n        additional_dependencies: [pydantic]\n
Run Code Online (Sandbox Code Playgroud)\n

Ant*_*ile 17

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

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


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