python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.02k stars 2.25k forks source link

Setting extras as non-optional #9574

Open ClementPinard opened 1 month ago

ClementPinard commented 1 month ago

Issue Kind

Improving documentation

Existing Link

https://python-poetry.org/docs/pyproject/#extras

Description

In the documentation for extra, we can read this :

https://python-poetry.org/docs/pyproject/#extras

[tool.poetry]
name = "awesome"

[tool.poetry.dependencies]
# These packages are mandatory and form the core of this package’s distribution.
mandatory = "^1.0"

# A list of all of the optional dependencies, some of which are included in the
# below `extras`. They can be opted into by apps.
psycopg2 = { version = "^2.9", optional = true }
mysqlclient = { version = "^1.3", optional = true }

[tool.poetry.extras]
mysql = ["mysqlclient"]
pgsql = ["psycopg2"]
databases = ["mysqlclient", "psycopg2"]

My question is, what if we don't want to set these dependencies as optional within the repo ?

[tool.poetry]
name = "awesome"

[tool.poetry.dependencies]
# These packages are mandatory and form the core of this package’s distribution.
mandatory = "^1.0"

psycopg2 = "^2.9"
mysqlclient = "^1.3"

[tool.poetry.extras]
mysql = ["mysqlclient"]
pgsql = ["psycopg2"]
databases = ["mysqlclient", "psycopg2"]

Basically, a poetry install inside the repo would install everything, and poetry add awesome would not install pyscopg2 nor mysqlclient unless a -E option is selected.

This makes sense from a developer point of view to treat extra as dev package to perform e.g. tests or docker build

From my experience, this works the way I thought, and extra without mentioning optional still makes packages optional when installing them from outside.

My question, is this behaviour in some way official ? Can I consider this undocumented feature to be stable ? And if so, would it be interesting to mention is in the docs ?

For me, extras and optional are two different things. I know it will be confusing when there is already some confusion between extras and groups, but I feel like this usage of non-optional extras is legitimate and could be officialized in some way.

dimbleby commented 1 month ago

I expect this will eventually break in confusing ways.