pre-commit fails to install isort 5.11.4 with error "RuntimeError: The Poetry configuration is invalid"
Asked Answered
V

5

79

pre-commit suddenly started to fail installing the isort hook in our builds today with the following error

[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]+$'

It seems to be related with poetry configuration..

Vulgate answered 28/1, 2023 at 17:54 Comment(0)
V
85

Upgrading the hook to the freshly released isort 5.12.0 seems to be fixing the issue.

Looking at the commit stack from isort repo, it sounds like recent version of Poetry had a breaking change incompatible with isort <= 5.11.4 (commit)

Vulgate answered 28/1, 2023 at 17:54 Comment(6)
Is it possible to freeze Poetry version in pre-commit?Inlaid
@bagerard"apparently no" but I show you exactly how? please don't put words in my mouthVivacity
sorry, I was just trying to help but I indeed read the github issue too quickly. Anyway, I deleted the comment to avoid confusion. Re-linking the Github issue regarding freezing poetry in pre-commit here as it still good to mention it--> github.com/pre-commit/pre-commit/issues/2730#issue-1561600633Vulgate
Upgrading to isort 5.12.0 did fix the issue a few days ago, but suddenly it appeared again yesterday. I'm using Python 3.10.9Senskell
strange, it didn't reappear in our caseVulgate
Thank you, I was hitting my head on a wall all afternoon because of this error and your answer fixed it.Wearproof
T
42

Running pre-commit autoupdate was sufficient to fix it on my machine.

This will update isort version in .pre-commit-config.yaml to 5.12.0+, as well as all the other pre-commit utilities.

Treadway answered 8/2, 2023 at 12:41 Comment(1)
I didn't know you could do this! Thank you for writing this answer.Wearproof
Q
24

Additional note: For people who must use python3.7 (the support was dropped in isort 5.12.0), isort released the hotfix 5.11.5.

https://github.com/PyCQA/isort/releases/tag/5.11.5

5.11.5 January 30 2023 [hotfix]

Fixed incompatiblity with latest poetry version

Related isort issue: https://github.com/PyCQA/isort/issues/2083#issuecomment-1408300628

Quittor answered 31/1, 2023 at 9:33 Comment(1)
Could this answer be merged with @bagerard's answer?Forbiddance
A
12

For me the solution was:

pre-commit autoupdate
Anchovy answered 13/3, 2023 at 16:42 Comment(1)
This documented one should be the answer. It's a root cause solution. Good one!Oesophagus
W
7

Adding to this post because it took a few more things to get my system working...

Project fix

.pre-commit-config.yaml based on docs

- 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]

pin specific poetry-core version (isort issue & hot fix)

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

System fix

uninstall/reinstall poetry using official installer

uninstall

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

check .zshrc and remove other instances of poetry via cat ~/.zshrc | grep poetry

install

curl -sSL https://install.python-poetry.org | python3 -
echo "export PATH=\"/Users/$USER/.local/bin:\$PATH\"" >> "$HOME/.zshrc"
Wafd answered 6/2, 2023 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.