pre-commit 安装 isort 5.11.4 失败,报错 "RuntimeError: The Poetry configuration is invalid"。

70

pre-commit 在今天的构建中突然开始安装isort钩子失败,并出现以下错误

[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/builds/.../.cache/pre-commit/repo0_h0f938/py_env-python3.8/bin/python', '-mpip', 'install', '.')
return code: 1
expected return code: 0
[...]
stderr:
      ERROR: Command errored out with exit status 1:
[...]
        File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/masonry/api.py", line 40, in prepare_metadata_for_build_wheel
          poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
        File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/factory.py", line 57, in create_poetry
          raise RuntimeError("The Poetry configuration is invalid:\n" + message)
      RuntimeError: The Poetry configuration is invalid:
        - [extras.pipfile_deprecated_finder.2] 'pip-shims<=0.3.4' does not match '^[a-zA-Z-_.0-9]+$'

看起来与诗歌配置有关..

5个回答

77

升级到最新发布的isort 5.12.0似乎可以解决这个问题。

从isort仓库的提交栈来看,最近版本的Poetry与isort <= 5.11.4有不兼容的破坏性更改(commit)


1
在 pre-commit 中冻结 Poetry 版本是否可行? - Jirka
“显然不可能”,但我会向您展示具体方法, 请不要曲解我的意思。 - anthony sottile
抱歉,我只是想帮忙,但确实太快读了Github问题。无论如何,我已删除评论以避免混淆。在此重新链接有关在pre-commit中冻结poetry的Github问题,因为它仍然值得一提--> github.com/pre-commit/pre-commit/issues/2730#issue-1561600633 - bagerard
升级到isort 5.12.0几天前确实解决了问题,但昨天它突然又出现了。我正在使用Python 3.10.9。 - Salma Hassan
奇怪,它在我们的情况下没有重新出现。 - bagerard
1
谢谢,因为这个错误我整个下午都在撞墙,而你的答案解决了它。 - ribs2spare

37

在我的电脑上运行 pre-commit autoupdate 就足以解决问题。

这将更新.pre-commit-config.yaml中的isort版本至5.12.0+,以及所有其他的预提交工具。


1
我不知道你可以这样做!感谢您撰写这个答案。 - ribs2spare

22

这个回答可以与@bagerard的回答合并吗? - Erich

9
对我来说,解决方案是:
pre-commit autoupdate

1
这份文档应该是答案。它是一个根本原因的解决方案。不错! - Natacha
2
这份文件应该是答案。这是一个根本原因的解决方案。不错! - Natacha
2
这份记录应该是答案。这是一个根本原因的解决方案。不错! - undefined

7

因为我需要做更多的事情才能让我的系统正常工作,所以在这篇文章中进行补充...

项目修复

.pre-commit-config.yaml 基于 文档 进行了修改。

- repo: https://github.com/pycqa/isort
  rev: 5.12.0
  hooks:
  - id: isort
    args: ['--order-by-type', '--length-sort', "--profile", "black", "--filter-files"]
    name: isort (python)
  - id: isort
    name: isort (cython)
    types: [cython]
  - id: isort
    name: isort (pyi)
    types: [pyi]

针对特定的poetry-core版本(isort问题热修复

[build-system]
requires = ["poetry-core>=1.3.2"]
build-backend = "poetry.core.masonry.api"

系统修复

卸载/重新安装 poetry 使用官方安装程序

卸载

curl -sSL https://install.python-poetry.org | python3 - --uninstall
curl -sSL https://install.python-poetry.org | POETRY_UNINSTALL=1 python3 -

检查 .zshrc 并通过 cat ~/.zshrc | grep poetry 移除其他实例的诗歌。

安装

curl -sSL https://install.python-poetry.org | python3 -
echo "export PATH=\"/Users/$USER/.local/bin:\$PATH\"" >> "$HOME/.zshrc"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接