How should project.optional-dependencies be managed from the CLI?
#11056
Replies: 2 comments
|
The short answer is that currently, modifying or removing dependencies from Here is the breakdown of why this asymmetry exists, how 1. Why is there no
|
|
Adding to an existing extra already works in 2.4.3: repeat poetry add --optional cli richStarting with your The remaining operations differ:
One version correction to the earlier reply: I verified these cases in a clean temporary project with Poetry 2.4.3/Python 3.13.9, including keeping References: add options, lock, update. |
Uh oh!
There was an error while loading. Please reload this page.
The documentation says that the old
[tool.poetry.extras]mechanism is deprecated and recommends using[project.optional-dependencies]instead:I'm trying to understand what the intended CLI workflow is for managing these optional dependencies after they have been defined.
Environment:
I created a fresh project:
Creating an optional dependency
I used the documented
--optionaloption:And this create an
optional-dependenciesThis seems correct.
I can also activate the project extra during installation:
and
cleois installed.So far, everything is clear.
What is the CLI workflow after creation?
The problem starts when I want to modify the existing optional dependency group.
For example, I would expect something analogous to:
but:
I also tried:
The same applies to
update:So
--optionalappears to be available when creating an optional dependency, but there doesn't seem to be a corresponding mechanism for modifying or removing dependencies from an existing[project.optional-dependencies]entry.What does
-Emean inpoetry add?There is another confusing behavior.
Given:
I tried to add
richto the same project extra:I initially interpreted
-E clias "addrichto the project'sclioptional dependency".However, Poetry generated:
So it appears that
-E clihere means thecliextra of therichpackage, effectively:rather than the project's:
This distinction does make sense given the documentation.
The documentation also says that when a project depends on a package with extras, those extras should be expressed on the dependency itself, for example:
So I understand that there are two different concepts here:
[project.optional-dependencies];rich[cli].My confusion is specifically about the first one.
Comparison with dependency groups
I realize that dependency groups and project optional dependencies have different semantics, and I'm not suggesting that they should behave identically.
However, dependency groups have explicit CLI operations for selecting them, such as:
while project extras have:
The documentation explains how project extras are activated during installation, but I couldn't find an equivalent CLI workflow for modifying the contents of an existing project extra.
For example, if I have:
what is the intended Poetry CLI operation to:
cli;cli;cli?Is manually editing
[project.optional-dependencies]the intended workflow?Questions
poetry add --optional cli cleointentionally the onlyaddoperation for[project.optional-dependencies]?-Einpoetry addintentionally about dependency/package extras (rich[cli]) rather than project extras defined by[project.optional-dependencies]?[project.optional-dependencies]entry, is manually editingpyproject.tomlthe intended workflow?I'm mainly trying to understand the intended CLI interface now that
[tool.poetry.extras]is deprecated in favor of[project.optional-dependencies].All reactions