diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index 1fef37d16..134e865d9 100644 --- a/src/hatch/cli/application.py +++ b/src/hatch/cli/application.py @@ -159,6 +159,8 @@ def ensure_plugin_dependencies(self, dependencies: list[Dependency], *, wait_mes if not dependencies: return + from uv import find_uv_bin + from hatch.dep.sync import InstalledDistributions from hatch.env.utils import add_verbosity_flag @@ -178,9 +180,10 @@ def ensure_plugin_dependencies(self, dependencies: list[Dependency], *, wait_mes if distributions.dependencies_in_sync(dependencies): return - pip_command = [sys.executable, "-u", "-m", "pip"] + uv_bin = find_uv_bin() + pip_command = [uv_bin, "pip"] - pip_command.extend(["install", "--disable-pip-version-check"]) + pip_command.extend(["install", "--disable-pip-version-check", "--python", sys.executable]) # Default to -1 verbosity add_verbosity_flag(pip_command, self.verbosity, adjustment=-1) diff --git a/tests/conftest.py b/tests/conftest.py index 7b38a299e..df74d00ad 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -481,15 +481,25 @@ def mock_process(command, **kwargs): @pytest.fixture def mock_plugin_installation(mocker): + from uv import find_uv_bin + subprocess_run = subprocess.run mocked_subprocess_run = mocker.MagicMock(returncode=0) def _mock(command, **kwargs): if isinstance(command, list): + if any(arg.startswith("hatchling") for arg in command): + return subprocess_run(command, **kwargs) + if command[:5] == [sys.executable, "-u", "-m", "pip", "install"]: mocked_subprocess_run(command, **kwargs) return mocked_subprocess_run + uv_bin = find_uv_bin() + if command[:3] == [uv_bin, "pip", "install"]: + mocked_subprocess_run(command, **kwargs) + return mocked_subprocess_run + if command[:3] == [sys.executable, "self", "python-path"]: return mocker.MagicMock(returncode=0, stdout=sys.executable.encode()) diff --git a/tests/helpers/helpers.py b/tests/helpers/helpers.py index 52b9fdffd..570fc1c53 100644 --- a/tests/helpers/helpers.py +++ b/tests/helpers/helpers.py @@ -48,13 +48,16 @@ def get_current_timestamp(): def assert_plugin_installation(subprocess_run, dependencies: list[str], *, verbosity=0, count=1): + from uv import find_uv_bin + + uv_bin = find_uv_bin() command = [ - sys.executable, - "-u", - "-m", + uv_bin, "pip", "install", "--disable-pip-version-check", + "--python", + sys.executable, ] add_verbosity_flag(command, verbosity, adjustment=-1) command.extend(dependencies)