From f24bce90462a1a86b624a31e22f9a2f3b5c3f9b7 Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo <vladimir.petrigo@gmail.com> Date: Thu, 9 Jan 2025 19:30:21 +0100 Subject: [PATCH 1/5] hatch: cli: application: Switch to uv Address: juftin/hatch-pip-compile#85 --- src/hatch/cli/application.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index bdc77b8c2..9a10990a1 100644 --- a/src/hatch/cli/application.py +++ b/src/hatch/cli/application.py @@ -160,9 +160,9 @@ def ensure_plugin_dependencies(self, dependencies: list[Requirement], *, wait_me if dependencies_in_sync(dependencies): return - pip_command = [sys.executable, '-u', '-m', 'pip'] + pip_command = [sys.executable, '-u', '-m', 'uv', 'pip'] - pip_command.extend(['install', '--disable-pip-version-check', '--no-python-version-warning']) + pip_command.extend(['install']) # Default to -1 verbosity add_verbosity_flag(pip_command, self.verbosity, adjustment=-1) From b1838f882fc96ae829af35936d26584be114a63a Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo <vladimir.petrigo@gmail.com> Date: Thu, 9 Jan 2025 19:31:15 +0100 Subject: [PATCH 2/5] tests: Update asserts after switching to uv --- tests/conftest.py | 4 ++++ tests/helpers/helpers.py | 10 +--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index a2fbb9fdf..f3e8f0688 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -440,6 +440,10 @@ def _mock(command, **kwargs): mocked_subprocess_run(command, **kwargs) return mocked_subprocess_run + if command[:6] == [sys.executable, '-u', '-m', 'uv', '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..692487256 100644 --- a/tests/helpers/helpers.py +++ b/tests/helpers/helpers.py @@ -48,15 +48,7 @@ def get_current_timestamp(): def assert_plugin_installation(subprocess_run, dependencies: list[str], *, verbosity=0, count=1): - command = [ - sys.executable, - '-u', - '-m', - 'pip', - 'install', - '--disable-pip-version-check', - '--no-python-version-warning', - ] + command = [sys.executable, '-u', '-m', 'uv', 'pip', 'install'] add_verbosity_flag(command, verbosity, adjustment=-1) command.extend(dependencies) From 306dd828c77b3cce7d8310da6779610c11663aa1 Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo <vladimir.petrigo@gmail.com> Date: Sat, 11 Jan 2025 23:11:31 +0100 Subject: [PATCH 3/5] hatch: tests: Update uv command search --- src/hatch/cli/application.py | 5 ++++- tests/conftest.py | 4 +++- tests/helpers/helpers.py | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index 9a10990a1..d3c9b1c0b 100644 --- a/src/hatch/cli/application.py +++ b/src/hatch/cli/application.py @@ -12,6 +12,8 @@ from hatch.utils.platform import Platform from hatch.utils.runner import ExecutionContext +from uv import find_uv_bin + if TYPE_CHECKING: from collections.abc import Generator @@ -160,7 +162,8 @@ def ensure_plugin_dependencies(self, dependencies: list[Requirement], *, wait_me if dependencies_in_sync(dependencies): return - pip_command = [sys.executable, '-u', '-m', 'uv', 'pip'] + uv_bin = find_uv_bin() + pip_command = [uv_bin, 'pip'] pip_command.extend(['install']) diff --git a/tests/conftest.py b/tests/conftest.py index f3e8f0688..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,7 +441,8 @@ def _mock(command, **kwargs): mocked_subprocess_run(command, **kwargs) return mocked_subprocess_run - if command[:6] == [sys.executable, '-u', '-m', 'uv', 'pip', 'install']: + uv_bin = find_uv_bin() + if command[:3] == [uv_bin, 'pip', 'install']: mocked_subprocess_run(command, **kwargs) return mocked_subprocess_run diff --git a/tests/helpers/helpers.py b/tests/helpers/helpers.py index 692487256..60ffd2ab0 100644 --- a/tests/helpers/helpers.py +++ b/tests/helpers/helpers.py @@ -12,6 +12,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,7 +49,8 @@ def get_current_timestamp(): def assert_plugin_installation(subprocess_run, dependencies: list[str], *, verbosity=0, count=1): - command = [sys.executable, '-u', '-m', 'uv', 'pip', 'install'] + uv_bin = find_uv_bin() + command = [uv_bin, 'pip', 'install'] add_verbosity_flag(command, verbosity, adjustment=-1) command.extend(dependencies) From a565a5fe9e236d2dfb602baa054c141623e5181a Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo <vladimir.petrigo@gmail.com> Date: Sat, 11 Jan 2025 23:13:06 +0100 Subject: [PATCH 4/5] hatch: Update to use find_uv_bin() --- src/hatch/cli/application.py | 7 ++++--- tests/helpers/helpers.py | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index d3c9b1c0b..70b4bb2b4 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 @@ -12,8 +15,6 @@ from hatch.utils.platform import Platform from hatch.utils.runner import ExecutionContext -from uv import find_uv_bin - if TYPE_CHECKING: from collections.abc import Generator @@ -165,7 +166,7 @@ def ensure_plugin_dependencies(self, dependencies: list[Requirement], *, wait_me uv_bin = find_uv_bin() pip_command = [uv_bin, 'pip'] - pip_command.extend(['install']) + pip_command.extend(['install', '--directory', str(pathlib.Path(sys.executable).parent.parent)]) # Default to -1 verbosity add_verbosity_flag(pip_command, self.verbosity, adjustment=-1) diff --git a/tests/helpers/helpers.py b/tests/helpers/helpers.py index 60ffd2ab0..7fb074b31 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 @@ -50,7 +51,13 @@ def get_current_timestamp(): def assert_plugin_installation(subprocess_run, dependencies: list[str], *, verbosity=0, count=1): uv_bin = find_uv_bin() - command = [uv_bin, 'pip', 'install'] + command = [ + uv_bin, + 'pip', + 'install', + '--directory', + str(pathlib.Path(sys.executable).parent.parent), + ] add_verbosity_flag(command, verbosity, adjustment=-1) command.extend(dependencies) From 8dca06cec3a1f609217e466d6bf9c80b3fe626eb Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo <vladimir.petrigo@gmail.com> Date: Tue, 14 Jan 2025 09:47:34 +0100 Subject: [PATCH 5/5] hatch: Update the implementation to use --python switch Switch from --directory to --python switch to simplify `uv pip install` command. --- src/hatch/cli/application.py | 2 +- tests/helpers/helpers.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index 70b4bb2b4..207ba04b7 100644 --- a/src/hatch/cli/application.py +++ b/src/hatch/cli/application.py @@ -166,7 +166,7 @@ def ensure_plugin_dependencies(self, dependencies: list[Requirement], *, wait_me uv_bin = find_uv_bin() pip_command = [uv_bin, 'pip'] - pip_command.extend(['install', '--directory', str(pathlib.Path(sys.executable).parent.parent)]) + pip_command.extend(['install', '--python', sys.executable]) # Default to -1 verbosity add_verbosity_flag(pip_command, self.verbosity, adjustment=-1) diff --git a/tests/helpers/helpers.py b/tests/helpers/helpers.py index 7fb074b31..cc43b3bf9 100644 --- a/tests/helpers/helpers.py +++ b/tests/helpers/helpers.py @@ -55,8 +55,8 @@ def assert_plugin_installation(subprocess_run, dependencies: list[str], *, verbo uv_bin, 'pip', 'install', - '--directory', - str(pathlib.Path(sys.executable).parent.parent), + '--python', + sys.executable, ] add_verbosity_flag(command, verbosity, adjustment=-1) command.extend(dependencies)