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.
- 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"]
- 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:
- Created 5 years ago
- Reactions:11
- Comments:9 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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