Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python conditional marker causing resolution issue where it shouldn't #5134

Closed
mkniewallner opened this issue Jul 16, 2024 · 3 comments
Closed
Labels
great writeup A wonderful example of a quality contribution 💜 resolver Related to the package resolver

Comments

@mkniewallner
Copy link
Contributor

Stumbled upon what I think is a bug in the dependency resolution algorithm.

If a project:

  • requires a minimum Python version (say >= 3.8)
  • depends on a package that requires a higher minimum Python version than the project (say >= 3.9)
  • conditionally requires the dependency above to match the minimum Python version of the dependency (say >= 3.9)

then dependency resolution fails:

$ uv sync --preview
  × No solution found when resolving dependencies:
  ╰─▶ Because the requested Python version (>=3.8) does not satisfy Python>=3.9 and foo==0.0.1 depends on pre-commit{python_version >= '3.9'}==3.7.1, we can conclude that foo==0.0.1 cannot be used.
      And because only foo==0.0.1 is available and you require foo, we can conclude that the requirements are unsatisfiable.

I would understand why it fails if not setting a condition for the dependency, since it's unsolvable, but because of the condition on the Python version, I would expect the resolution to work, as the dependency would simply not be installed on Python 3.8.

Minimal reproducer

[project]
name = "foo"
version = "0.0.1"
requires-python = ">=3.8"
dependencies = ["pre-commit==3.7.1; python_version >= '3.9'"]
$ uv sync --preview --verbose
DEBUG uv 0.2.25
DEBUG Found project root: `/home/mathieu/Workspaces/throwaways/foo`
DEBUG No workspace root found, using project root
DEBUG Searching for Python >=3.8 in managed installations or system path
DEBUG Searching for managed installations at `/home/mathieu/.local/share/uv/python`
DEBUG Found managed Python `cpython-3.12.1-linux-x86_64-gnu`
DEBUG Found cpython 3.12.1 at `/home/mathieu/.local/share/uv/python/cpython-3.12.1-linux-x86_64-gnu/bin/python3` (managed installations)
Using Python 3.12.1 interpreter at: /home/mathieu/.local/share/uv/python/cpython-3.12.1-linux-x86_64-gnu/bin/python3
Creating virtualenv at: .venv
DEBUG Using request timeout of 30s
DEBUG Starting clean resolution.
DEBUG Acquired lock for `/home/mathieu/.cache/uv/built-wheels-v3/editable/74f2787c29c91621`
DEBUG Preparing metadata for: foo @ file:///home/mathieu/Workspaces/throwaways/foo
DEBUG No static `PKG-INFO` available for: foo @ file:///home/mathieu/Workspaces/throwaways/foo (MissingPkgInfo)
DEBUG Found static `pyproject.toml` for: foo @ file:///home/mathieu/Workspaces/throwaways/foo
DEBUG No workspace root found, using project root
DEBUG Solving with installed Python version: 3.12.1
DEBUG Solving with target Python version: >=3.8
DEBUG Adding direct dependency: foo*
DEBUG Searching for a compatible version of foo @ file:///home/mathieu/Workspaces/throwaways/foo (*)
DEBUG Adding transitive dependency for foo==0.0.1: pre-commit{python_version >= '3.9'}==3.7.1
DEBUG Found fresh response for: https://pypi.org/simple/pre-commit/
DEBUG Searching for a compatible version of pre-commit{python_version >= '3.9'} (==3.7.1)
DEBUG No compatible version found for: Python
DEBUG Searching for a compatible version of foo @ file:///home/mathieu/Workspaces/throwaways/foo (<0.0.1 | >0.0.1)
DEBUG No compatible version found for: foo
  × No solution found when resolving dependencies:
  ╰─▶ Because the requested Python version (>=3.8) does not satisfy Python>=3.9 and foo==0.0.1 depends on pre-commit{python_version >= '3.9'}==3.7.1, we can conclude that foo==0.0.1 cannot be used.
      And because only foo==0.0.1 is available and you require foo, we can conclude that the requirements are unsatisfiable.

You can see the minimum required Python version of the version of pre-commit used in the reproducer here.

@zanieb
Copy link
Member

zanieb commented Jul 16, 2024

Thanks for the clear report! We have a lot of work in-flight in this area, someone should be able to weigh in with some details soon. cc @konstin / @BurntSushi

@zanieb zanieb added great writeup A wonderful example of a quality contribution 💜 resolver Related to the package resolver labels Jul 16, 2024
@charliermarsh
Copy link
Member

I believe this is the same as #4669. Gonna merge into that issue.

@charliermarsh
Copy link
Member

Or, more specifically, it's the same as #4668 (which is slightly different).

@charliermarsh charliermarsh closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
great writeup A wonderful example of a quality contribution 💜 resolver Related to the package resolver
Projects
None yet
Development

No branches or pull requests

3 participants