From ff860296c519604ae80dc74f6b853d9714f2a690 Mon Sep 17 00:00:00 2001 From: konsti Date: Fri, 20 Dec 2024 10:15:24 +0100 Subject: [PATCH] Use `shutil.which` for the build backend (#10028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From PEP 517: > All command-line scripts provided by the build-required packages must be present in the build environment’s PATH. For example, if a project declares a build-requirement on flit, then the following must work as a mechanism for running the flit command-line tool: > > ```python > import subprocess > import shutil > subprocess.check_call([shutil.which("flit"), ...]) > ``` Fixes #9991 --------- Co-authored-by: Charles Tapley Hoyt --- python/uv/_build_backend.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/python/uv/_build_backend.py b/python/uv/_build_backend.py index 5ab4cb1ba..88bd54c91 100644 --- a/python/uv/_build_backend.py +++ b/python/uv/_build_backend.py @@ -26,14 +26,17 @@ def warn_config_settings(config_settings: "dict | None" = None): def call(args: "list[str]", config_settings: "dict | None" = None) -> str: """Invoke a uv subprocess and return the filename from stdout.""" + import shutil import subprocess import sys - from ._find_uv import find_uv_bin - warn_config_settings(config_settings) + # Unlike `find_uv_bin`, this mechanism must work according to PEP 517 + uv_bin = shutil.which("uv") + if uv_bin is None: + raise RuntimeError("uv was not properly installed") # Forward stderr, capture stdout for the filename - result = subprocess.run([find_uv_bin()] + args, stdout=subprocess.PIPE) + result = subprocess.run([uv_bin] + args, stdout=subprocess.PIPE) if result.returncode != 0: sys.exit(result.returncode) # If there was extra stdout, forward it (there should not be extra stdout)