Optional dependencies are generated as required in wheel
- [x] I am on the latest Poetry version.
- [x] I have searched the issues of this repo and believe that this is not a duplicate.
- [ ] If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption).
- OS version and name: Linux 5.5.8-arch1-1
- Poetry version: 1.0.5
- Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/cutwater/65c1120890dc654e9968f8cdcf4cfde1
- Related Issue: python-poetry/poetry#24
Issue
Optional dependencies are generated as required dependencies in wheel package produced by executing poetry build. Dependency list in sdist package does not include optional dependencies as expected. Please refer to the gist above for more details.
Steps to reproduce the issue:
$ poetry new example
$ cd example
$ poetry add --optional psycopg2
$ poetry build
I have exactly the same issue.
My project has aiohttp installed as optional dependency
poetry add aiohttp --optional -E async
My pyproject.toml:
python = "^3.7"
aiohttp = {version = "^3.6.2", optional = true, extras = ["async"]}
After build,PKG-INFO file has this line:
Requires-Dist: aiohttp[async] (>=3.6.2,<4.0.0)
Hello,
the problem here is, that the used syntax isn't correct. Any optional dependency must be assigned to an extra, e.g.:
[tool.poetry.dependencies]
python = "^3.10"
psycopg2 = {version = "^2.9.2", optional = true}
[tool.poetry.dev-dependencies]
[tool.poetry.extras]
pgsql = ["psycopg2"]
poetry build (and maybe other poetry commands) should fail if they detect an optional dependency that is not assigned to an extra.
That optional dependencies must be assigned to an extra is not at all obvious from the current documentation. For example, the example source code on that page says:
# A list of all of the optional dependencies, some of which are included in the
# below `extras`. They can be opted into by apps.
The "some" is very confusing here. "all of which must be included in the below extras" would be clearer, but something should also be said at the top of the section.
If it is actually impossible and invalid to supply optional constraints without being included in an extra, then I would expect poetry to fail with an error stating as much. The behaviour that was observed in #7787 where poetry install and pip install included different dependencies was misleading and counter intuitive.
this is an open bug, no-one is claiming that it is fine.
As I mentioned in #8248 IMO if a dependency is marked as optional=True, is incorrect marked as a required dep in PKG-INFO. I agree that poetry should raise an exception if we can not defined an optional deps without declaring it (again) in the extras section.
if this is important to you then please submit a merge request
(this bug is three years old, at this point I reckon it's a safe bet that waiting for someone else to fix it is not going to work!)
Also ref: #8564
Could these lines about “unsolicited extras” be relevant?
https://github.com/python-poetry/poetry/blob/cdfd955144204c25b277309007c332aaee8be28c/src/poetry/puzzle/transaction.py#L83-L103
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.