Document support for platform-specific dependencies in pyproject.toml
Feature Description
Currently, uv doesn't support specifying platform-specific dependencies directly in the pyproject.toml file. It would be incredibly useful to have the ability to define different dependencies for various platforms (e.g., Linux, macOS, Windows) within the same pyproject.toml file.
Use Case
As a developer working on a project that needs to run on multiple platforms (specifically Linux and macOS with M1 chip), I need to specify different dependencies for each platform. For example, I need to install the CUDA-enabled version of JAX on Linux, but the standard version on macOS.
Proposed Solution
Add support for platform-specific dependency sections in pyproject.toml. This could be implemented similar to how pip handles it with sys_platform markers, or as a new section under [tool.uv]. For example:
[tool.uv.platform-dependencies]
linux = [
"jax[cuda12_pip]>=0.4.18,<0.5.0"
]
darwin = [
"jax>=0.4.18,<0.5.0"
]
Or alternatively:
[project]
dependencies = [
"common-dep1",
"common-dep2",
"jax>=0.4.18,<0.5.0; sys_platform == 'darwin'",
"jax[cuda12_pip]>=0.4.18,<0.5.0; sys_platform == 'linux'"
]
Benefits
- Simplified dependency management for cross-platform projects
- Reduced need for separate requirements files or complex setup scripts
- Improved developer experience when working across different environments
Additional Context
This feature would align uv more closely with other packaging tools and standards in the Python ecosystem, making it easier for developers to transition to using uv in their projects.
[project]
dependencies = [
"common-dep1",
"common-dep2",
"jax>=0.4.18,<0.5.0; sys_platform == 'darwin'",
"jax[cuda12_pip]>=0.4.18,<0.5.0; sys_platform == 'linux'"
]
Does this not work as-is?
[project] dependencies = [ "common-dep1", "common-dep2", "jax>=0.4.18,<0.5.0; sys_platform == 'darwin'", "jax[cuda12_pip]>=0.4.18,<0.5.0; sys_platform == 'linux'" ]Does this not work as-is?
@charliermarsh This works and works really well. Cant believe I wrote this out and never actually tried this on my own. I swore I did, but anyways. Sorry for the needless feature request. Thanks so much.
Great feature by the way
No worries! Thanks for following up.
Mind if I keep this open? We should add some documentation around this, I've seen it a couple times.
How can I replicate this for pytorch? When installing on darwin, I need to use the regular pypi index, however, when installing on another linux machine, I'd like to explicitly use the https://download.pytorch.org/whl/cu118/ as per the pytorch docs
Edit: never mind - found it: https://docs.astral.sh/uv/concepts/dependencies/#platform-specific-sources