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

Conditionally allow dependencies to resolve where specific versions conflict with optional dependency bounds #10154

Open
mjlbach opened this issue Dec 25, 2024 · 0 comments

Comments

@mjlbach
Copy link

mjlbach commented Dec 25, 2024

Description of problem

Some optional dependencies can introduce additional version constraints. E.g., I may introduce a package that requires numpy pinned to version 1.x.x. I would ideally like this not to impact the resolved packages when not using this optional dependency.

Scenario 1: optional dependency upper bound is incompatible with lower bound of dependency

pyproject toml

[project]
name = "uv-test"
version = "0.1.0"
description = "an example showing conflict resolution"
requires-python = ">=3.12.7"
dependencies = [
  "numpy>=2.0.0",
]

[project.optional-dependencies]
mediapipe = [
    "mediapipe>=0.10.20",
]

Sync the dependencies

❯ uv sync
Using CPython 3.12.7
Creating virtual environment at: .venv
  × No solution found when resolving dependencies:
  ╰─▶ Because your project depends on numpy>=2.0.0 and mediapipe==0.10.20 depends on
      numpy<2, we can conclude that mediapipe==0.10.20 and your project are incompatible.
      And because only mediapipe<=0.10.20 is available, we can conclude that
      mediapipe>=0.10.20 and your project are incompatible.
      And because uv-test[mediapipe] depends on mediapipe>=0.10.20 and your project
      requires uv-test[mediapipe], we can conclude that your project's requirements are
      unsatisfiable.

Workaround

[project]
name = "uv-test"
version = "0.1.0"
description = "an example showing conflict resolution"
requires-python = ">=3.12.7"
dependencies = []

[dependency-groups]
numpy = [
  "numpy>=2.0.0",
]

[tool.uv]
default-groups = ["numpy"]
conflicts = [
    [
      { group = "numpy" },
      { extra = "mediapipe" },
    ],
]

[project.optional-dependencies]
mediapipe = [
    "mediapipe>=0.10.20",
]

Ugly workaround

uv sync --extra mediapipe --no-group numpy

Anything I'm missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant