From a2edc33ead4f3c447678e958c9cb5f1f2e5bb638 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 13 Jul 2024 17:12:26 -0400 Subject: [PATCH] Add a custom error message for `--no-build-isolation` `torch` dependencies (#5041) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Closes https://github.com/astral-sh/uv/issues/5040. ## Test Plan ``` ❯ cargo run pip install torch torch-scatter --no-cache ⠼ torch-scatter==2.1.2 error: Failed to download and build `torch-scatter==2.1.2` Caused by: Failed to build: `torch-scatter==2.1.2` Caused by: Build backend failed to determine extra requires with `build_wheel()` with exit status: 1 --- stdout: --- stderr: Traceback (most recent call last): File "", line 14, in File "/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpuxrhWj/builds-v0/.tmp1OBLbw/lib/python3.12/site-packages/setuptools/build_meta.py", line 327, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=[]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpuxrhWj/builds-v0/.tmp1OBLbw/lib/python3.12/site-packages/setuptools/build_meta.py", line 297, in _get_build_requires self.run_setup() File "/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpuxrhWj/builds-v0/.tmp1OBLbw/lib/python3.12/site-packages/setuptools/build_meta.py", line 497, in run_setup super().run_setup(setup_script=setup_script) File "/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpuxrhWj/builds-v0/.tmp1OBLbw/lib/python3.12/site-packages/setuptools/build_meta.py", line 313, in run_setup exec(code, locals()) File "", line 8, in ModuleNotFoundError: No module named 'torch' --- Caused by: This error likely indicates that torch-scatter==2.1.2 depends on torch, but doesn't declare it as a build dependency. If torch-scatter==2.1.2 is a first-party package, consider adding torch to its `build-system.requires`. Otherwise, `uv pip install torch` into the environment and re-run with `--no-build-isolation ``` --- crates/uv-build/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/uv-build/src/lib.rs b/crates/uv-build/src/lib.rs index 6e1434d7e..a774da42a 100644 --- a/crates/uv-build/src/lib.rs +++ b/crates/uv-build/src/lib.rs @@ -63,6 +63,10 @@ static LD_NOT_FOUND_RE: Lazy = Lazy::new(|| { static WHEEL_NOT_FOUND_RE: Lazy = Lazy::new(|| Regex::new(r"error: invalid command 'bdist_wheel'").unwrap()); +/// e.g. `ModuleNotFoundError: No module named 'torch'` +static TORCH_NOT_FOUND_RE: Lazy = + Lazy::new(|| Regex::new(r"ModuleNotFoundError: No module named 'torch'").unwrap()); + /// The default backend to use when PEP 517 is used without a `build-system` section. static DEFAULT_BACKEND: Lazy = Lazy::new(|| Pep517Backend { backend: "setuptools.build_meta:__legacy__".to_string(), @@ -185,6 +189,8 @@ impl Error { Some(MissingLibrary::Linker(library.to_string())) } else if WHEEL_NOT_FOUND_RE.is_match(line.trim()) { Some(MissingLibrary::PythonPackage("wheel".to_string())) + } else if TORCH_NOT_FOUND_RE.is_match(line.trim()) { + Some(MissingLibrary::PythonPackage("torch".to_string())) } else { None }