question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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).

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.

Possibly related issues: #5506, #5447, #4695

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
thueringacommented, May 8, 2022

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.

1reaction
thueringacommented, May 8, 2022

Sorry, yes, I got all the versions a bit mixed up in my head it seems… To clarify:

  • flake8 depends on importlib-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-metadata

So 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

There are incompatible versions in the resolved dependencies
Poetry will resolve your dependencies to the latest versions that match the constraints and don't conflict with each other.
Read more >
Should You Use Upper Bound Version Constraints?
Bound version constraints (upper caps) are starting to show up in the Python ecosystem. This is causing real world problems with libraries ...
Read more >
FAQ | Documentation | Poetry - Python dependency ...
Why are unbound version constraints a bad idea? #. A version constraint without an upper bound such as * or >=3.4 will allow...
Read more >
Dependency Management With Python Poetry
Install dependencies with poetry.lock; Execute basic Poetry CLI commands. Using Poetry will help you start new projects, maintain existing ones, ...
Read more >
Release and Version History — pipenv 2022.12.20.dev0 ...
Now if you create a new project with a fully named python version it will record ... Fix for pipenv lock fails for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found