Locking dependencies fails when using python version constraints
See original GitHub issue- I am on the latest Poetry version.
- I have searched the issues of this repo and believe that this is not a duplicate.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option).
- OS version and name: Debian bookworm, Python 3.9.12, Python 3.7.13
- Poetry version: 1.2.0b2.dev0
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/thueringa/a9fe9ea20408a5d1e54af4a8bd1eda58
Issue
I have the following dependencies:
[tool.poetry.dependencies]
python = "^3.7"
flake8 = "4.0.1"
sphinx = [
{version = "4.3.1", python = "~3.7.0"},
{version = "^4.5.0", python = "^3.8"},
]
Locking the depencies with poetry lock --no-update
fails with the following error (see Gist for full output of poetry lock -vvv --no-update
):
SolverProblemError
Because flake8 (4.0.1) depends on importlib-metadata (<4.3)
and sphinx (4.5.0) depends on importlib-metadata (>=4.4), flake8 (4.0.1) is incompatible with sphinx (4.5.0).
And because no versions of sphinx match >4.5.0,<5.0.0, flake8 (4.0.1) is incompatible with sphinx (>=4.5.0,<5.0.0).
So, because poetry-test depends on both flake8 (4.0.1) and sphinx (^4.5.0), version solving failed.
at ~/.local/lib/python3.10/site-packages/poetry/puzzle/solver.py:155 in _solve
151│ packages = result.packages
152│ except OverrideNeeded as e:
153│ return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
154│ except SolveFailure as e:
→ 155│ raise SolverProblemError(e)
156│
157│ combined_nodes = depth_first_search(PackageNode(self._package, packages))
158│ results = dict(aggregate_package_nodes(nodes) for nodes in combined_nodes)
159│
I would expect poetry
to find a solution where flake8==4.0.1
is installed for all environments, sphinx==4.3.1
is installed for Python 3.7.* environments, and sphinx==4.5.0
is installed for all Python 3.8 environments and upwards.
A work-around is to define specific versions of flake8
for each Python environment:
[tool.poetry.dependencies]
python = "^3.7"
flake8 = [
{version = "4.0.0", python = "~3.7.0"},
{version = "4.0.1", python = "^3.8"},
]
sphinx = [
{version = "4.3.1", python = "~3.7.0"},
{version = "^4.5.0", python = "^3.8"},
]
This correctly locks the dependencies, but it only works when using different versions of flake8
for each kind of environment, which is impractical.
Additional information
Similar failing command
A similar set of dependencies that fails is this one:
[tool.poetry.dependencies]
python = "^3.7"
importlib-metadata = {version ="<4.3", python= "~3.7.0"}
sphinx = [
{version = "4.3.1", python = "~3.7.0"},
{version = "^4.5.0", python = "^3.8"},
]
I would expect poetry
to find a solution for Python 3.8 environments and upwards that installs sphinx==4.5.0
and a compatible version of importlib-metadata
that is defined in the dependencies of sphinx v4.5.0
. For Python 3.7 environments I would expect poetry
to find a solution that installs sphinx==4.3.1
and a version of importlib-metadata
that adheres to our dependency constraint.
importlib-metadata
dependencies in referenced packages flake8
and sphinx
The relevant lines concerning importlib-metadata
in setup.cfg of flake8 v4.0.1
(unchanged from flake8 v4.0.0
):
install_requires =
[...]
importlib-metadata<4.3;python_version<"3.8"
In setup.py of sphinx v4.5.0
:
install_requires = [
[...]
"importlib-metadata>=4.4; python_version < '3.10'",
]
sphinx v4.3.1
does not seem to have a dependency on importlib-metadata
.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
I should have thought about the set of dependencies diligently, I see now that this was an misunderstanding on my side on the dependencies of Sphinx v4.5.0. It does have a dependency on “importlib-metadata>=4.4; python_version < ‘3.10’”. So the behavior of Poetry in conjunction with Flake8 is correct, and the snippet in my opening post is not expected to be solvable.
Thank you for your help @Qu4tro, I will close this issue now.
Sorry, yes, I got all the versions a bit mixed up in my head it seems… To clarify:
flake8
depends onimportlib-metadata<4.3;python_version<"3.8"
,sphinx v4.5.0
depends on"importlib-metadata>=4.4; python_version < '3.10'"
,sphinx v4.3.*
has no dependency on importlib-metadataSo yes, I believe this is a regression bug of Poetry, as it should find a solution for this set of dependencies with the snippet above, like it did in
v1.0.10
.