-
To make this example easier, I have two packages: package-a: [tool.poetry]
name = "package-a"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api" package-b: [tool.poetry]
name = "package-b"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api" I then add a new dependency into [tool.poetry]
name = "package-b"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
torch = [
{source = 'torchcpu', version = '2.3.1+cpu'},
]
[[tool.poetry.source]]
name = 'torchcpu'
priority = 'explicit'
url = 'https://download.pytorch.org/whl/cpu'
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
If I build a wheel for /tmp/package-a$ poetry add ../package-b/dist/package_b-0.1.0-py3-none-any.whl
Updating dependencies
Resolving dependencies... (0.1s)
Because package-b (0.1.0) @ file:///tmp/package-b/dist/package_b-0.1.0-py3-none-any.whl depends on torch (2.3.1+cpu) which doesn't match any versions, package-b is forbidden.
So, because package-a depends on package-b (0.1.0) @ file:///tmp/package-b/dist/package_b-0.1.0-py3-none-any.whl, version solving failed. Is there any way for Do I need to add |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No, there is no way to do this because explicit package sources is a Poetry feature so this information cannot be added to metadata when building a wheel.
Yes, but you can add it without a specific version constraint in an optional dependency group so that it is only installed if it is required by a direct dependency. For example:
Alternatively, you can just add the package source as supplemental if you do not care that torch is first searched on PyPI and only on torchcpu if the version is not found on PyPI:
|
Beta Was this translation helpful? Give feedback.
No, there is no way to do this because explicit package sources is a Poetry feature so this information cannot be added to metadata when building a wheel.
Yes, but you can add it without a specific version constraint in an optional dependency group so that it is only installed if it is required by a direct dependency. For example: