From d4cebe782cb31d8b860c31578a569200f4ca38cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Sun, 25 Aug 2024 15:52:18 -0700 Subject: [PATCH 1/2] hatch: hardcode uv executable path --- pkgs/by-name/ha/hatch/package.nix | 7 ++-- pkgs/by-name/ha/hatch/paths.patch | 58 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 pkgs/by-name/ha/hatch/paths.patch diff --git a/pkgs/by-name/ha/hatch/package.nix b/pkgs/by-name/ha/hatch/package.nix index 940c343b556bb01..d4011175f7d9711 100644 --- a/pkgs/by-name/ha/hatch/package.nix +++ b/pkgs/by-name/ha/hatch/package.nix @@ -2,7 +2,7 @@ lib, python3, fetchFromGitHub, - uv, + replaceVars, git, cargo, stdenv, @@ -24,12 +24,15 @@ python3.pkgs.buildPythonApplication rec { hash = "sha256-HW2vDVsFrdFRRaPNuGDg9DZpJd8OuYDIqA3KQRa3m9o="; }; + patches = [ (replaceVars ./paths.patch { uv = lib.getExe python3.pkgs.uv; }) ]; + build-system = with python3.pkgs; [ hatchling hatch-vcs - uv ]; + pythonRemoveDeps = [ "uv" ]; + dependencies = with python3.pkgs; [ click hatchling diff --git a/pkgs/by-name/ha/hatch/paths.patch b/pkgs/by-name/ha/hatch/paths.patch new file mode 100644 index 000000000000000..60aeec4e49716de --- /dev/null +++ b/pkgs/by-name/ha/hatch/paths.patch @@ -0,0 +1,58 @@ +diff --git a/src/hatch/env/virtual.py b/src/hatch/env/virtual.py +index 285edb32..90bd94e6 100644 +--- a/src/hatch/env/virtual.py ++++ b/src/hatch/env/virtual.py +@@ -106,26 +106,7 @@ class VirtualEnvironment(EnvironmentInterface): + if self.explicit_uv_path: + return self.explicit_uv_path + +- from hatch.env.internal import is_default_environment +- +- env_name = 'hatch-uv' +- if not ( +- # Prevent recursive loop +- self.name == env_name +- # Only if dependencies have been set by the user +- or is_default_environment(env_name, self.app.project.config.internal_envs[env_name]) +- ): +- uv_env = self.app.get_environment(env_name) +- self.app.prepare_environment(uv_env) +- with uv_env: +- return self.platform.modules.shutil.which('uv') +- +- import sysconfig +- +- scripts_dir = sysconfig.get_path('scripts') +- old_path = os.environ.get('PATH', os.defpath) +- new_path = f'{scripts_dir}{os.pathsep}{old_path}' +- return self.platform.modules.shutil.which('uv', path=new_path) ++ return '@uv@' + + @staticmethod + def get_option_types() -> dict: +diff --git a/src/hatch/venv/core.py b/src/hatch/venv/core.py +index d1303f03..e1e60871 100644 +--- a/src/hatch/venv/core.py ++++ b/src/hatch/venv/core.py +@@ -131,7 +131,7 @@ class TempVirtualEnv(VirtualEnv): + + class UVVirtualEnv(VirtualEnv): + def create(self, python, *, allow_system_packages=False): +- command = [os.environ.get('HATCH_UV', 'uv'), 'venv', str(self.directory), '--python', python] ++ command = [os.environ.get('HATCH_UV', '@uv@'), 'venv', str(self.directory), '--python', python] + if allow_system_packages: + command.append('--system-site-packages') + +diff --git a/tests/conftest.py b/tests/conftest.py +index e8fe663a..6066316d 100644 +--- a/tests/conftest.py ++++ b/tests/conftest.py +@@ -203,7 +203,7 @@ def python_on_path(): + + @pytest.fixture(scope='session', autouse=True) + def uv_on_path(): +- return shutil.which('uv') ++ return '@uv@' + + + @pytest.fixture(scope='session') From be709723a58b739d52e4e539c785e01f708f17e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Sun, 25 Aug 2024 18:56:51 -0700 Subject: [PATCH 2/2] hatch: use python3Packages This makes cross compilation work. --- pkgs/by-name/ha/hatch/package.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/by-name/ha/hatch/package.nix b/pkgs/by-name/ha/hatch/package.nix index d4011175f7d9711..141fb9a51ec66d1 100644 --- a/pkgs/by-name/ha/hatch/package.nix +++ b/pkgs/by-name/ha/hatch/package.nix @@ -1,6 +1,6 @@ { lib, - python3, + python3Packages, fetchFromGitHub, replaceVars, git, @@ -12,7 +12,7 @@ hatch, }: -python3.pkgs.buildPythonApplication rec { +python3Packages.buildPythonApplication rec { pname = "hatch"; version = "1.12.0"; pyproject = true; @@ -24,16 +24,16 @@ python3.pkgs.buildPythonApplication rec { hash = "sha256-HW2vDVsFrdFRRaPNuGDg9DZpJd8OuYDIqA3KQRa3m9o="; }; - patches = [ (replaceVars ./paths.patch { uv = lib.getExe python3.pkgs.uv; }) ]; + patches = [ (replaceVars ./paths.patch { uv = lib.getExe python3Packages.uv; }) ]; - build-system = with python3.pkgs; [ + build-system = with python3Packages; [ hatchling hatch-vcs ]; pythonRemoveDeps = [ "uv" ]; - dependencies = with python3.pkgs; [ + dependencies = with python3Packages; [ click hatchling httpx @@ -52,7 +52,7 @@ python3.pkgs.buildPythonApplication rec { ]; nativeCheckInputs = - with python3.pkgs; + with python3Packages; [ binary git