poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Optional dependencies are generated as required in wheel

Open cutwater opened this issue 5 years ago • 9 comments

  • [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 (-vvv option).
  • 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

cutwater avatar Mar 10 '20 20:03 cutwater

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)

bawongfai avatar Mar 21 '20 06:03 bawongfai

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.

finswimmer avatar Mar 26 '22 13:03 finswimmer

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.

mforbes avatar Jan 03 '23 21:01 mforbes

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.

KotlinIsland avatar Apr 28 '23 08:04 KotlinIsland

this is an open bug, no-one is claiming that it is fine.

dimbleby avatar Apr 28 '23 09:04 dimbleby

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.

eamanu avatar Jul 28 '23 17:07 eamanu

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!)

dimbleby avatar Jul 28 '23 21:07 dimbleby

Also ref: #8564

Secrus avatar Oct 13 '24 23:10 Secrus

Could these lines about “unsolicited extras” be relevant?

https://github.com/python-poetry/poetry/blob/cdfd955144204c25b277309007c332aaee8be28c/src/poetry/puzzle/transaction.py#L83-L103

ron-wolf avatar Dec 21 '24 15:12 ron-wolf

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.

github-actions[bot] avatar Mar 04 '25 00:03 github-actions[bot]