Build poetry package with extra or optional dependencies
See original GitHub issue- [ x] I have searched the issues of this repo and believe that this is not a duplicate.
- [x ] I have searched the documentation and believe that my question is not covered.
Feature Request
Looking through the documentation I was able to find adding optional/extra dependencies to a project as well as installing, but I could not find information about their inclusion in the build process. I see two scenarios:
- Poetry already supports this and the documentation should be edited accordingly to accommodate.
- Poetry does not support this and should provide some sort of API to do so similarly to the current process for installing extra req.s, but for building:
poetry build --extras "mysql pgsql"
poetry build -E mysql -E pgsql
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Python poetry - how to install optional dependencies?
You need to add a tool.poetry.extras group to your pyproject.toml if you want to use the -E flag during install, as described in...
Read more >The pyproject.toml file | Documentation | Poetry
Poetry supports extras to allow expression of: optional dependencies, which enhance a package, but are not required; and; clusters of optional dependencies.
Read more >Managing Python Dependencies with Poetry
Dependency management and packaging tools for your Python project using poetry. How to install, configure and use it.
Read more >Dependency Management With Python Poetry
After an update, a package might not work as it did before the update. A dependency manager like Python Poetry helps you specify,...
Read more >Python packaging and dependency management using poetry
Poetry helps you declare, manage and install dependencies of Python projects, ensuring you have the right stack everywhere. Install dependencies and create ......
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
Considering all of the above, it is unlikely that such a feature, as you have described, will be implemented. Especially since the wheels need to adhere PEP 427. Typically, this is usually handled by specifying extras (as mentioned above).
There is a broader feature that might benefit a use case like this described in #2270. But that is still under discussion. As for a way forward for your package, I would recommend something like the following.
While this would mean that the user needs to decide if they want to install the cpu version or the gpu version ahead of time, this will ensure that the user only installs the required dependencies for their environment.
Even if you had two separate wheels built as you described, you will end up with exactly the same content in both wheels except for one requirement specification in the wheel metadata having a suffix
-gpu
.If you absolutely must have a separate package you could, split the project into three. A common package that contains your logic and a
-cpu
and-gpu
version that each depend on your common package and also their corresponding onxruntime. Less than ideal, I know. Note that since you do not have any cpu/gpu specific files in your own project, this is not something I would recommend.I’m confused. Even if we build and publish the package with poetry, what happens when the user wants to install the package with one of the 2 extras?
I published the package and tried to install it in a different environment from PyPI but something like:
pip install awesome[cpu]
didn’t work in that case.