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.

How can I specify differing sets of dependency extras for each of my project's extras?

See original GitHub issue
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Question

How can I specify differing sets of dependency extras for each of my project’s extras? This is something that is relatively trivial to do with setup.py. To clarify, I would like to be able to specify the following dependency graph:

myproject[feature-a] depends on [dependency-one, dependency-two[feature-a]] myproject[feature-b] depends on [dependency-one, dependency-two[feature-b]]

I’ll propose a couple ways that pyproject.toml might model these graphs, but the core value of these examples is to highlight an apparent deficiency with the current model.

  1. By allowing dependency aliases that specify distinct sets of extras. For example:
[tool.poetry.dependencies]
…
dependency-two-a = { git = "git+ssh://git@company.githost.io/projects/dependency-two.git",optional = true,extras = ["feature-a"], provides="dependency-two" }
dependency-two-b = { git = "git+ssh://git@company.githost.io/projects/dependency-two.git",optional = true,extras = ["feature-b"], provides="dependency-two" }
…

[tool.poetry.extras]
feature-a = ["dependency-one", "dependency-two-a"]
feature-b = ["dependency-one", "dependency-two-b"]
  1. By treating the set of extras in the dependencies section as a superset that can be further filtered down when the dependency is referenced in the extras section. For example:
[tool.poetry.dependencies]
…
dependency-two = { git = "git+ssh://git@company.githost.io/projects/dependency-two.git",optional = true,extras = ["feature-a", "feature-b"]}
…

[tool.poetry.extras]
feature-a = ["dependency-one", "dependency-two[feature-a]"]
feature-b = ["dependency-one", "dependency-two[feature-b]"]

Thanks for your time!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:11
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
micudacommented, Feb 10, 2021

Thanks for creating this issue, @kurtiss. We have the same problem. I would prefer option (2) proposed by @kurtiss, because it feels more intuitive - this was the first thing I tried.

What do you think, @sdispater?

@wshayes you are describing a different use-case here.

0reactions
blaise17commented, Jul 14, 2022

I have a subtly different use case, which I’m not sure works with the currently proposed solutions without some modification. Specifically, I need the dependency without extras to not be optional, but the dependency with extras to be optional. I also need one or more of the extras for the dependency to not be optional, while one or more still are optional. Would it be possible to specify the optional flag per extra?

For example:

[tool.poetry.dependencies]
…
dependency-one = {version = "^1.2.0", extras = [{extra="feature-a", optional = true}, "feature-b"] }
dependency-two = {version = "^1.2.0", extras = [{extra="feature-a", optional = true}] }
…

[tool.poetry.extras]
feature-a = ["dependency-one[feature-a]", "dependency-two[feature-a]"]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to specify platforms-specific extras or version in Pipfile?
The Python Developer's Guide states that the "extras" parameter is used to installed extra dependencies, which are in addition to the regular ...
Read more >
Help packaging optional application features, using extras?
Just use my code as it is in the repo, installing dependencies using the requirements file. The repo provides the code, and the...
Read more >
Dependency specification | master | Documentation - Poetry
Dependency specification Dependencies for a project can be specified in various forms, which depend on the type of the dependency and on the...
Read more >
Link tasks in a project - Microsoft Support
You can link any two tasks in a project to show their relationship (also called a task dependency). Dependencies drive the project schedule...
Read more >
Recursive Optional Dependencies in Python - Hynek Schlawack
You can specify more than one extra at once: pip install httpx[http2 ... useful with public projects, because the effort to set up...
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