From 435dc32d259d3e4427bbdfa0b684a956a1ff85bf Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo 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 # Conflicts: # src/hatch/cli/application.py --- src/hatch/cli/application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index 58cc826fe..dbe1c63f1 100644 --- a/src/hatch/cli/application.py +++ b/src/hatch/cli/application.py @@ -160,7 +160,7 @@ 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']) From fc37df40f07c95437a48fdd608840ac0e269298f Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo 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 | 1 + 2 files changed, 5 insertions(+) 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 a5557639e..dbd78127d 100644 --- a/tests/helpers/helpers.py +++ b/tests/helpers/helpers.py @@ -52,6 +52,7 @@ def assert_plugin_installation(subprocess_run, dependencies: list[str], *, verbo sys.executable, '-u', '-m', + 'uv', 'pip', 'install', '--disable-pip-version-check', From f32f360f80ed67446ea4cd293af2969b77b71f5e Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo 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 | 12 +++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index dbe1c63f1..21f780e55 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', '--disable-pip-version-check']) 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 dbd78127d..1891d5bc6 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,15 +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', - '--disable-pip-version-check', - ] + uv_bin = find_uv_bin() + command = [uv_bin, 'pip', 'install', '--disable-pip-version-check'] add_verbosity_flag(command, verbosity, adjustment=-1) command.extend(dependencies) From 376784d31c2b75d77f84dabff29bd8bc9e992332 Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo 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 | 10 +++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hatch/cli/application.py b/src/hatch/cli/application.py index 21f780e55..614744dd6 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', '--disable-pip-version-check']) + pip_command.extend(['install', '--directory', str(pathlib.Path(sys.executable).parent.parent), '--disable-pip-version-check']) # 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 1891d5bc6..4939e3bc5 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,14 @@ 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', '--disable-pip-version-check'] + command = [ + uv_bin, + 'pip', + 'install', + '--disable-pip-version-check', + '--directory', + str(pathlib.Path(sys.executable).parent.parent), + ] add_verbosity_flag(command, verbosity, adjustment=-1) command.extend(dependencies) From c1f2e75b8ff519c5bf6de0f8f024df7a5a0136a9 Mon Sep 17 00:00:00 2001 From: Vladimir Petrigo 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 614744dd6..2c83783d6 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), '--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/helpers/helpers.py b/tests/helpers/helpers.py index 4939e3bc5..1b2f5f75f 100644 --- a/tests/helpers/helpers.py +++ b/tests/helpers/helpers.py @@ -56,8 +56,8 @@ def assert_plugin_installation(subprocess_run, dependencies: list[str], *, verbo 'pip', 'install', '--disable-pip-version-check', - '--directory', - str(pathlib.Path(sys.executable).parent.parent), + '--python', + sys.executable, ] add_verbosity_flag(command, verbosity, adjustment=-1) command.extend(dependencies)