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 build --extras "mysql pgsql"
poetry build -E mysql -E pgsql
@JulianRMedina Is this stack-overflow answer related?
@teichert, thank you for the response but this is a different problem than what I was thinking. That stack-overflow post talks about the install of optional or extra dependencies, I'm specifically talking about the inclusion of optional/extra dependencies in a package wheel.
My exact use-case was the following:
I have a package that uses onnxruntime. You can install onnxruntime or onnxruntime-gpu but not both as they're not compatible with each other. Ideally, I'd like to be able to have the following work-flow:
poetry build --E onnxgpu
poetry build --E onnxcpu
or something similar, so that I can create two different wheels, one with support for a CPU, and another with support for a GPU.
After considering this, it may be some type of anti-pattern, and I curse onnxruntime for separating support for CPU and GPU but it's the scenario I am in.
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.
[tool.poetry]
name = "awesome"
[tool.poetry.dependencies]
onnxruntime = { version = "^1.3.0", optional = true }
onnxruntime-gpu = { version = "^1.3.0", optional = true }
[tool.poetry.extras]
cpu = ["onnxruntime"]
gpu = ["onnxruntime-gpu"]
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.
# this will install onnxruntime and not onnxruntime-gpu
pip install awesome[cpu]
# this will install onnxruntime-gpu and not onnxruntime
pip install awesome[gpu]
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.
@abn I appreciate the feedback and feel settled in the matter, and I thought I may have been chasing some sort of anti-pattern to my problem. I'll resolve this now.
Most helpful comment
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
-cpuand-gpuversion 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.