diff --git a/pyproject.toml b/pyproject.toml index a6d2dbc6..14452687 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ docs = [ "sphinx-issues >= 3.0.0", ] test = [ - "build[virtualenv]", + "build[uv, virtualenv]", "filelock >= 3", "pytest >= 6.2.4", "pytest-cov >= 2.12", @@ -62,15 +62,18 @@ test = [ 'setuptools >= 56.0.0; python_version == "3.10"', 'setuptools >= 56.0.0; python_version == "3.11"', 'setuptools >= 67.8.0; python_version >= "3.12"', - "uv >= 0.1.15", ] typing = [ + "build[uv]", "importlib-metadata >= 5.1", "mypy ~= 1.5.0", "tomli", "typing-extensions >= 3.7.4.3", "uv >= 0.1.15", ] +uv = [ + "uv >= 0.1.15", +] virtualenv = [ "virtualenv >= 20.0.35", ] diff --git a/src/build/env.py b/src/build/env.py index 6871e586..419ffb04 100644 --- a/src/build/env.py +++ b/src/build/env.py @@ -282,10 +282,19 @@ def create(self, path: str) -> None: self._env_path = path - uv_bin = shutil.which('uv') + # ``uv.find_uv_bin`` will look for uv in the user prefix if it can't + # find it under ``sys.prefix``, essentially potentially rearranging + # the user's $PATH. We'll only look for uv under the prefix of + # the running interpreter for unactivated venvs then defer to $PATH. + uv_bin = shutil.which('uv', path=sysconfig.get_path('scripts')) + + if not uv_bin: + uv_bin = shutil.which('uv') + if not uv_bin: msg = 'uv executable missing' raise RuntimeError(msg) + self._uv_bin = uv_bin if sys.implementation.name == 'pypy': diff --git a/tests/test_env.py b/tests/test_env.py index 90859a8d..283add9f 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -6,6 +6,7 @@ import subprocess import sys import sysconfig +import typing from pathlib import Path from types import SimpleNamespace @@ -64,6 +65,7 @@ def test_venv_executable_missing_post_creation( assert venv_create.call_count == 1 +@typing.no_type_check def test_isolated_env_abstract(): with pytest.raises(TypeError): build.env.IsolatedEnv()