Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/dependency-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,39 @@ pathlib2 = { version = "^2.2", markers = "python_version <= '3.4' or sys_platfor
{{< /tab >}}
{{< /tabs >}}

### `python` and `platform` shorthands

In the `[tool.poetry.dependencies]` form, Poetry accepts two convenience keys that are
shorthands for the most common environment markers:

- `python` is a [version constraint](#version-constraints) on `python_version`.
For example, `python = "^3.9"` is equivalent to the marker
`python_version >= "3.9" and python_version < "4.0"`.
- `platform` is an exact match on `sys_platform`. For example, `platform = "darwin"` is
equivalent to the marker `sys_platform == "darwin"`.

```toml
[tool.poetry.dependencies]
# Only installed on Python 3.9+ running on macOS
numpy = { version = "^1.26", python = "^3.9", platform = "darwin" }
```

These keys are not deprecated; they are simply a shorter way of writing the corresponding
markers. When you combine them with an explicit `markers` value, all of the conditions are
joined together with `and`:

```toml
[tool.poetry.dependencies]
numpy = { version = "^1.26", python = "^3.9", markers = "platform_machine == 'arm64'" }
# resolves to:
# python_version >= "3.9" and python_version < "4.0" and platform_machine == "arm64"
```

The `python` and `platform` shorthands are only available in the legacy
`[tool.poetry.dependencies]` table. In the PEP 621 `[project]` table, write the same
conditions inline as PEP 508 markers instead, e.g.
`"numpy (>=1.26) ; python_version >= '3.9' and sys_platform == 'darwin'"`.

### `extra` environment marker

Poetry populates the `extra` marker with each of the selected extras of the root package.
Expand Down