astral-sh / uv

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

`uv sync` handling third party dependencies in `setup.py` #7722

Open jamesbraza opened 3 weeks ago

jamesbraza commented 3 weeks ago

I am using uv==0.4.16, and there are two packages that make my life annoying because their setup.py depends on torch:

How can uv sync work with this scenario? Currently, it successfully makes a uv.lock, but then fails on uv sync:

[[package]]
name = "xformers"
version = "0.0.28"
source = { registry = "https://pypi.org/simple" }
dependencies = [
    { name = "numpy" },
    { name = "torch" },
]
sdist = { url = "https://files.pythonhosted.org/packages/be/8e/1b9bc5317a7a26d33af2db63f5db112c0cfe373befe7d5653e1d639db231/xformers-0.0.28.tar.gz", hash = "sha256:bc74e7033d2675962d4ddc708fc66328b6f6cbe5aedff7491eab98c338623bf2", size = 7757812 }
wheels = [
    { url = "https://files.pythonhosted.org/packages/d1/a0/bb5a668186f5f77a73043a8ff8b86176c7d3cbed10cbdafcca67237ee432/xformers-0.0.28-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:c7c6b1887d6bb71fe26464492b84d6cdbfbfdada5669a4a606c186a384e226f5", size = 16653563 },
    { url = "https://files.pythonhosted.org/packages/9b/e4/efead2c5c89cd5766c7c4f5320448c80a51f3a497bbe560b8000e2ebc930/xformers-0.0.28-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:9b3a5e6f2e02d6b2bb84a38351dcb181cfdb037451ab8cd57f39c161af33d83b", size = 16653138 },
]
error: Failed to prepare distributions
  Caused by: Failed to fetch wheel: xformers==0.0.28
  Caused by: Build backend failed to determine extra requires with `build_wheel()` with exit status: 1
--- stdout:

--- stderr:
Traceback (most recent call last):
  File "<string>", line 14, in <module>
  File "/Users/user/Library/Caches/uv/builds-v0/.tmpCHWnFA/lib/python3.12/site-packages/setuptools/build_meta.py", line 332, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=[])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Library/Caches/uv/builds-v0/.tmpCHWnFA/lib/python3.12/site-packages/setuptools/build_meta.py", line 302, in _get_build_requires
    self.run_setup()
  File "/Users/user/Library/Caches/uv/builds-v0/.tmpCHWnFA/lib/python3.12/site-packages/setuptools/build_meta.py", line 503, in run_setup
    super().run_setup(setup_script=setup_script)
  File "/Users/user/Library/Caches/uv/builds-v0/.tmpCHWnFA/lib/python3.12/site-packages/setuptools/build_meta.py", line 318, in run_setup
    exec(code, locals())
  File "<string>", line 24, in <module>
ModuleNotFoundError: No module named 'torch'
---
charliermarsh commented 3 weeks ago

There are some tips on that here: https://docs.astral.sh/uv/concepts/projects/#build-isolation. It's still a bit of a pain though.

jamesbraza commented 3 weeks ago

Ah I see, thank you! Yeah so currently installation is a two-step process:

  1. pip install torch
  2. pip install xformers

I was sort of hoping uv could somehow convert that to be a one-step process, but it doesn't seem to be the case:

  1. uv sync --extra build
    • Note: the extra build= ["torch"]
  2. uv sync --extra xformers
    • Note: relies on no-build-isolation-package = ["xformers"] being in tool.uv

Do you think it's a reasonable request to uv to somehow support this use case as a one-step process? In other words, make it less of a special case from an installer's perspective

charliermarsh commented 3 weeks ago

I would like it to be one-step, yeah. It's a reasonable request. It likely won't happen immediately though.