astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
20.02k stars 594 forks source link

Document support for platform-specific dependencies in pyproject.toml #6758

Open BeeGass opened 2 weeks ago

BeeGass commented 2 weeks ago

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

  1. Simplified dependency management for cross-platform projects
  2. Reduced need for separate requirements files or complex setup scripts
  3. 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.

charliermarsh commented 2 weeks ago
[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?

BeeGass commented 2 weeks ago
[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

charliermarsh commented 2 weeks ago

No worries! Thanks for following up.

zanieb commented 2 weeks ago

Mind if I keep this open? We should add some documentation around this, I've seen it a couple times.