Skip to content

Commit c355973

Browse files
chimaeraseneersighted
authored andcommitted
Clarify removal for non-installed extras & optional groups (#6229)
(cherry picked from commit 8546dd6)
1 parent b5b7843 commit c355973

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

docs/cli.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ This ensures that everyone using the library will get the same versions of the d
144144

145145
If there is no `poetry.lock` file, Poetry will create one after dependency resolution.
146146

147-
If you want to exclude one or more dependency group for the installation, you can use
147+
If you want to exclude one or more dependency groups for the installation, you can use
148148
the `--without` option.
149149

150150
```bash
@@ -201,6 +201,12 @@ poetry install -E mysql -E pgsql
201201
poetry install --all-extras
202202
```
203203

204+
Extras are not sensitive to `--sync`. Any extras not specified will always be removed.
205+
206+
```bash
207+
poetry install --extras "A B" # C is removed
208+
```
209+
204210
By default `poetry` will install your project's package every time you run `install`:
205211

206212
```bash

docs/managing-dependencies.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,9 @@ to remove packages from a specific group:
184184
poetry remove mkdocs --group docs
185185
```
186186

187-
188187
## Synchronizing dependencies
189188

190-
Poetry supports what's called dependency synchronization. What this does is ensuring
189+
Poetry supports what's called dependency synchronization. Dependency synchronization ensures
191190
that the locked dependencies in the `poetry.lock` file are the only ones present
192191
in the environment, removing anything that's not necessary.
193192

@@ -198,7 +197,8 @@ poetry install --sync
198197
```
199198

200199
The `--sync` option can be combined with any [dependency groups]({{< relref "#dependency-groups" >}}) related options
201-
to synchronize the environment with specific groups.
200+
to synchronize the environment with specific groups. Note that extras are separate. Any
201+
extras not selected for install are always removed, regardless of `--sync`.
202202

203203
```bash
204204
poetry install --without dev --sync
@@ -209,3 +209,9 @@ poetry install --only dev
209209
{{% note %}}
210210
The `--sync` option replaces the `--remove-untracked` option which is now deprecated.
211211
{{% /note %}}
212+
213+
## Layering optional groups
214+
215+
When you omit the `--sync` option, you can install any subset of optional groups without removing
216+
those that are already installed. This is very useful, for example, in multi-stage
217+
Docker builds, where you run `poetry install` multiple times in different build stages.

docs/pyproject.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,11 @@ poetry install --extras "mysql pgsql"
385385
poetry install -E mysql -E pgsql
386386
```
387387

388-
Or, you can install all extras with the `--all-extras` option:
388+
Any extras you don't specify will be removed. Note this behavior is different from
389+
[optional dependency groups]({{< relref "managing-dependencies#optional-groups" >}}) not
390+
selected for install, e.g. those not specified via `install --with`.
391+
392+
You can install all extras with the `--all-extras` option:
389393

390394
```bash
391395
poetry install --all-extras

0 commit comments

Comments
 (0)