python-poetry / python-poetry/poetry

Including companion dependency only for specific versions of another dependency

Open
#8,813 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/feature status/triage
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the FAQ and general documentation and believe that my question is not already covered.

Feature Request

I have an optional dev dependency (a companion package containing stubs), which I only want to include for certain versions of a main dependency.

For example, when using pyspark~=3.0, I want to use the pyspark-stubs~=3.0. However, when using pyspark~=3.3., I don't want to (as that package already includes the stubs).

My attempt:

[tool.poetry.dependencies]
pyspark = [
  {version = "~3.0", optional = true, python = "<=3.8"},
  {version = "~3.3", optional = true, python = ">3.8"}
]

[tool.poetry.group.test.dependencies]
pyspark-stubs = {version = "~3.0", python = "<=3.8", optional=true}

Which fails to resolve, as pyspark-stubs depends on pyspark ~3.0, and the project depends on both pyspark ~3.0 and pyspark ~3.3.

The problem in this case is of course that for pyspark 3.3, there's no compatible pyspark-stubs specified. But in this case, I want the resolution to not use any pyspark-stubs. I tried to enforce this by using the same restriction on python, but that didn't work.

How can I specify such a companion dependency (like stubs) only for specific versions of my main dependency? Or is there a way to group them together in another way?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing Poetry's dependency-resolution and dependency-group documentation in light of the pyspark and pyspark-stubs examples. Define done as documenting or implementing a supported way to include the companion dependency only for selected versions of the main dependency, while resolving successfully for the other versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.