Open valentincalomme opened 2 months ago
expected, and duplicate #6993, #7000, #7302, etc
I wonder if there is a good reason for this behavior or if it is just legacy behavior nobody had the courage to change? In other words, it might be something we want to change especially if we do a major version bump.
Personally, I think it makes more sense not to remove dependencies that are part of an unrequested extra when running poetry install
, but only when running poetry install --sync
. The only reason for the current behavior that comes to my mind are mutually exclusive extras with the same dependency from different sources, which we do not support anyway if I remember correctly.
there is some sort of expectation in this report that poetry install
(and probably also poetry add
) should be purely additive.
but this has never been so, these commands have always removed packages if they are under poetry control and they are not required by the action being taken
--sync
is about removing things in the environment that poetry otherwise considers to be outside of its management.
for sure that behaviour could be changed but I think it is currently consistent and understandable. (though perhaps it could be better understood eg with improved docs)
but this has never been so, these commands have always removed packages if they are under poetry control and they are not required by the action being taken
I think it is currently consistent and understandable
I think I do not quite understand what exactly you are referring to. Consider the following example:
[tool.poetry]
package-mode = false
[tool.poetry.dependencies]
python = "^3.9"
tomli = "*"
[tool.poetry.group.dev.dependencies]
tomli_w = "*"
Commands:
$poetry install
Installing dependencies from lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing tomli (2.0.1)
- Installing tomli-w (1.0.0)
$poetry install --only main
Installing dependencies from lock file
No dependencies to install or update
$poetry install --only dev
Installing dependencies from lock file
No dependencies to install or update
$poetry install --only main --sync
Installing dependencies from lock file
Package operations: 0 installs, 0 updates, 1 removal
- Removing tomli-w (1.0.0)
I would say, both, tomli
and tomli_w
are managed by Poetry. However, they are not removed when not using --sync
.
removing unspecified groups was declared "counter-intuitive" in https://github.com/python-poetry/poetry/pull/4336. I guess my intuition is the opposite, it does not seem to me to match the meaning of the words for --only
or --without
to keep them around.
one more thought: --sync
is a less precise tool than being able to control extras as currently supported (or groups, as not currently supported)
eg if for whatever reason I have tools in my environment that are not managed by poetry - ruff
or mypy
or tox
or whatever - then --sync
will remove them, which was not necessarily wanted.
ie changing the behaviour would be taking something away, it is certainly debatable how valuable that thing is.
Description
I experienced a strange behavior when using the
poetry install
command with the--only
flag.Let's say that all of my dependencies are installed and up to date. If I run
poetry install --only=mygroup
, I expect that no installations would be required. But, what actually happens is that it removes my optional dependencies, as if I had used the--sync
keyword.My scenario is that for some parts of my (local or remote) CI process, I want to install only a certain subset of my dependencies. So I use the
--only
flag to specify which dependency group to install. My expectations is that, nothing should be uninstalled unless I use the--sync
flag.Workarounds
If I run
poetry install --only=mygroup --all-extras
, the optional dependencies aren't removed. But it feels that it should be the default behaviour.Poetry Installation Method
system package manager (eg: dnf, apt etc.)
Operating System
MacOs (14.4.1 (23E224))
Poetry Version
1.8.2
Poetry Configuration
Python Sysconfig
Example pyproject.toml
Poetry Runtime Logs