Skip to content

Commit

Permalink
update examples and add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Nov 29, 2024
1 parent a6980a3 commit 8b36cbd
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions docs/dependency-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,17 @@ paths = [

#### Exclusive extras

{{% warning %}}
The first example will only work completely if you configure Poetry to not re-resolve for installation:

```bash
poetry config installer.re-resolve false
```

This is a new feature of Poetry 2.0 that may become the default in a future version of Poetry.

{{% /warning %}}

Keep in mind that all combinations of possible extras available in your project need to be compatible with each other.
This means that in order to use differing or incompatible versions across different combinations, you need to make your
extra markers *exclusive*. For example, the following installs PyTorch from one source repository with CPU versions
Expand All @@ -595,6 +606,8 @@ for GPUs when the `cuda` extra *is* specified:

```toml
[project]
name = "torch-example"
requires-python = ">=3.10"
dependencies = [
"torch (==2.3.1+cpu) ; extra != 'cuda'",
]
Expand All @@ -604,10 +617,13 @@ cuda = [
"torch (==2.3.1+cu118)",
]

[tool.poetry]
package-mode = false

[tool.poetry.dependencies]
torch = [
{ markers = "extra != 'cuda'", source = "pytorch-cpu"},
{ markers = "extra == 'cuda'", source = "pytorch-cu118"},
{ markers = "extra == 'cuda'", source = "pytorch-cuda"},
]

[[tool.poetry.source]]
Expand All @@ -616,7 +632,7 @@ url = "https://download.pytorch.org/whl/cpu"
priority = "explicit"

[[tool.poetry.source]]
name = "pytorch-cu118"
name = "pytorch-cuda"
url = "https://download.pytorch.org/whl/cu118"
priority = "explicit"
```
Expand All @@ -627,18 +643,25 @@ GPU (`cuda`) version.
This same logic applies when you want either-or extras:

```toml
[project]
name = "torch-example"
requires-python = ">=3.10"

[project.optional-dependencies]
cuda = [
"torch (==2.3.1+cu118) ; extra != 'cpu'",
]
cpu = [
"torch (==2.3.1+cpu) ; extra != 'cuda'",
"torch (==2.3.1+cpu)",
]
cuda = [
"torch (==2.3.1+cu118)",
]

[tool.poetry]
package-mode = false

[tool.poetry.dependencies]
torch = [
{ markers = "extra == 'cpu' and extra != 'cuda'", source = "pytorch-cpu"},
{ markers = "extra == 'cuda' and extra != 'cpu'", source = "pytorch-cu118"},
{ markers = "extra == 'cuda' and extra != 'cpu'", source = "pytorch-cuda"},
]

[[tool.poetry.source]]
Expand All @@ -647,7 +670,7 @@ url = "https://download.pytorch.org/whl/cpu"
priority = "explicit"

[[tool.poetry.source]]
name = "pytorch-cu118"
name = "pytorch-cuda"
url = "https://download.pytorch.org/whl/cu118"
priority = "explicit"
```
Expand Down

0 comments on commit 8b36cbd

Please sign in to comment.