Skip to content

Commit

Permalink
fix(run-task): install repo requirements to user site dir
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ahal committed Oct 16, 2024
1 parent c215560 commit 46dfa72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/taskgraph/run-task/run-task
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

if os.environ.get("PIP_DISABLE_REQUIRE_HASHES") != "1":
cmd.append("--require-hashes")
Expand Down
8 changes: 5 additions & 3 deletions test/test_scripts_run_task.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import os
import site
import stat
import subprocess
import sys
Expand Down Expand Up @@ -85,7 +86,7 @@ def test_install_pip_requirements(
sys.executable,
"-mpip",
"install",
"--break-system-packages",
"--user",
"--require-hashes",
"-r",
str(req),
Expand All @@ -105,7 +106,7 @@ def test_install_pip_requirements(
sys.executable,
"-mpip",
"install",
"--break-system-packages",
"--user",
"--require-hashes",
"-r",
str(req),
Expand Down Expand Up @@ -137,7 +138,8 @@ def test_install_pip_requirements_with_uv(
"install",
"--python",
sys.executable,
"--break-system-packages",
"--target",
site.getusersitepackages(),
"--require-hashes",
"-r",
str(req),
Expand Down

0 comments on commit 46dfa72

Please sign in to comment.