From 8d4b6ca9712964ed602a3147dbce3a0449fe5f86 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 15 Sep 2024 17:55:37 -0400 Subject: [PATCH] Add documentation on platform-specific dependencies (#7411) ## Summary Closes https://github.com/astral-sh/uv/issues/6758. --- docs/concepts/projects.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/concepts/projects.md b/docs/concepts/projects.md index 6f7108314145..51664838c270 100644 --- a/docs/concepts/projects.md +++ b/docs/concepts/projects.md @@ -237,7 +237,7 @@ def hello() -> None: And the `pyproject.toml` includes a script entrypoint: -```python title="pyproject.toml" hl_lines="9 10" +```toml title="pyproject.toml" hl_lines="9 10" [project] name = "example-packaged-app" version = "0.1.0" @@ -486,6 +486,38 @@ To add a dependency source, e.g., to use `httpx` from GitHub during development: $ uv add git+https://github.com/encode/httpx ``` +### Platform-specific dependencies + +To ensure that a dependency is only installed on a specific platform or on specific Python versions, +use Python's standardized +[environment markers](https://peps.python.org/pep-0508/#environment-markers) syntax. + +For example, to install `jax` on Linux, but not on Windows or macOS: + +```console +$ uv add 'jax; sys_platform == "linux"' +``` + +The resulting `pyproject.toml` will then include the environment marker in the dependency +definition: + +```toml title="pyproject.toml" hl_lines="6" +[project] +name = "project" +version = "0.1.0" +requires-python = ">=3.11" +dependencies = ["jax; sys_platform == 'linux'"] +``` + +Similarly, to include `numpy` on Python 3.11 and later: + +```console +$ uv add 'numpy; python_version >= "3.11"' +``` + +See Python's [environment marker](https://peps.python.org/pep-0508/#environment-markers) +documentation for a complete enumeration of the available markers and operators. + ## Running commands When working on a project, it is installed into virtual environment at `.venv`. This environment is