Use shutil.which for the build backend (#10028)

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 <cthoyt@gmail.com>
This commit is contained in:
konsti 2024-12-20 10:15:24 +01:00 committed by GitHub
parent c4d0caaee5
commit ff860296c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)