diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index bdc77b8c2..207ba04b7 100644 --- a/src/hatch/cli/application.py +++ b/src/hatch/cli/application.py @@ -1,10 +1,13 @@ from __future__ import annotations import os +import pathlib import sys from functools import cached_property from typing import TYPE_CHECKING, cast +from uv import find_uv_bin + from hatch.cli.terminal import Terminal from hatch.config.user import ConfigFile, RootConfig from hatch.project.core import Project @@ -160,9 +163,10 @@ def ensure_plugin_dependencies(self, dependencies: list[Requirement], *, wait_me if 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', '--no-python-version-warning']) + pip_command.extend(['install', '--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 a2fbb9fdf..b217b70d9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,7 @@ from click.testing import CliRunner as __CliRunner from filelock import FileLock from platformdirs import user_cache_dir, user_data_dir +from uv import find_uv_bin from hatch.config.constants import AppEnvVars, ConfigEnvVars, PublishEnvVars from hatch.config.user import ConfigFile @@ -440,6 +441,11 @@ def _mock(command, **kwargs): 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 01d1bade5..cc43b3bf9 100644 --- a/tests/helpers/helpers.py +++ b/tests/helpers/helpers.py @@ -3,6 +3,7 @@ import importlib import json import os +import pathlib import re import sys from datetime import datetime, timezone @@ -12,6 +13,7 @@ from unittest.mock import call import tomli_w +from uv import find_uv_bin from hatch.config.user import RootConfig from hatch.env.utils import add_verbosity_flag @@ -48,14 +50,13 @@ def get_current_timestamp(): def assert_plugin_installation(subprocess_run, dependencies: list[str], *, verbosity=0, count=1): + uv_bin = find_uv_bin() command = [ - sys.executable, - '-u', - '-m', + uv_bin, 'pip', 'install', - '--disable-pip-version-check', - '--no-python-version-warning', + '--python', + sys.executable, ] add_verbosity_flag(command, verbosity, adjustment=-1) command.extend(dependencies)