uv icon indicating copy to clipboard operation
uv copied to clipboard

Document support for platform-specific dependencies in pyproject.toml

Open BeeGass opened this issue 1 year ago • 4 comments

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.

BeeGass avatar Aug 28 '24 15:08 BeeGass

[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 avatar Aug 28 '24 15:08 charliermarsh

[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

BeeGass avatar Aug 29 '24 12:08 BeeGass

No worries! Thanks for following up.

charliermarsh avatar Aug 29 '24 12:08 charliermarsh

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

zanieb avatar Aug 29 '24 13:08 zanieb

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

NellyWhads avatar Nov 13 '24 02:11 NellyWhads