From d1b13cdc0537b6a3477c355c6707cb091a5d618b Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Wed, 16 Oct 2024 11:24:19 -0400 Subject: [PATCH] fix(run-task): install repo requirements to user site dir When using `pip` this is a no-op as `pip` already implicitly detects that the system site dir is not writeable and falls back to the user dir. For the `uv` case, this was never working and should get unblocked by this fix. --- src/taskgraph/run-task/run-task | 5 +++-- test/test_scripts_run_task.py | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/taskgraph/run-task/run-task b/src/taskgraph/run-task/run-task index 62ae5e1e..b64aad14 100755 --- a/src/taskgraph/run-task/run-task +++ b/src/taskgraph/run-task/run-task @@ -1012,9 +1012,10 @@ def install_pip_requirements(repositories): # TODO: Stop using system Python (#381) if shutil.which("uv"): - cmd = ["uv", "pip", "install", "--python", sys.executable, "--break-system-packages"] + user_site_dir = subprocess.run([sys.executable, "-msite", "--user-site"], capture_output=True, text=True).stdout.strip() + cmd = ["uv", "pip", "install", "--python", sys.executable, "--target", user_site_dir] else: - cmd = [sys.executable, "-mpip", "install", "--break-system-packages"] + cmd = [sys.executable, "-mpip", "install", "--user", "--break-system-packages"] if os.environ.get("PIP_DISABLE_REQUIRE_HASHES") != "1": cmd.append("--require-hashes") diff --git a/test/test_scripts_run_task.py b/test/test_scripts_run_task.py index 23259b8a..a78c52df 100644 --- a/test/test_scripts_run_task.py +++ b/test/test_scripts_run_task.py @@ -1,5 +1,6 @@ import io import os +import site import stat import subprocess import sys @@ -85,6 +86,7 @@ def test_install_pip_requirements( sys.executable, "-mpip", "install", + "--user", "--break-system-packages", "--require-hashes", "-r", @@ -105,6 +107,7 @@ def test_install_pip_requirements( sys.executable, "-mpip", "install", + "--user", "--break-system-packages", "--require-hashes", "-r", @@ -137,7 +140,8 @@ def test_install_pip_requirements_with_uv( "install", "--python", sys.executable, - "--break-system-packages", + "--target", + site.getusersitepackages(), "--require-hashes", "-r", str(req),