【发布时间】:2022-01-10 09:19:08
【问题描述】:
我正在尝试运行 pre-commit 钩子,但是当它们遇到抛出以下错误的 isort 钩子时它们会失败:
File "/home/el/.cache/pre-commit/repoffrjhcx0/py_env-python3/lib/python3.10/site-packages/_distutils_hack/__init__.py", line 92, in create_module
return importlib.import_module('setuptools._distutils')
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'setuptools'
我正在使用 docker,并且我已经检查了 setuptools 是否已安装在我的全局机器上和我的 docker 上。我不明白为什么会发生此错误。我认为 isort 设置了它自己的环境,但是为什么不安装它,因为它是在他们的配置文件 pyproject.toml 中定义的。
以下是我的 pre-commit 和 isort 配置:
.pre-commit-config.yaml
repos:
- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: isort
args: ["--multi-line=5", "--line-length=120", "--use-parentheses", "--filter-files"]
exclude: "migrations"
stages: [commit]
tox.ini
[isort]
line_length=120
skip_glob=*migrations*
multi_line_output=5
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
use_parentheses=true
include_trailing_comma=true
lines_between_types=1
lines_after_imports=2
[testenv:isort]
deps =
isort
commands =
isort . --check-only --diff
系统上的 Python 版本:3.10.1
docker 上的 Python 版本:3.8
感谢您的帮助!
【问题讨论】:
-
pypi.org/project/setuptools这对你有帮助吗?
-
@VincentBénet 感谢您的回复。 setuptools 安装在系统范围和 docker 上,但 precommit isort 由于某种原因无法看到。
标签: python pre-commit-hook pre-commit pre-commit.com isort