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 9d9d57c commit d1b13cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 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", "--break-system-packages"]

if os.environ.get("PIP_DISABLE_REQUIRE_HASHES") != "1":
cmd.append("--require-hashes")
Expand Down
6 changes: 5 additions & 1 deletion 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,6 +86,7 @@ def test_install_pip_requirements(
sys.executable,
"-mpip",
"install",
"--user",
"--break-system-packages",
"--require-hashes",
"-r",
Expand All @@ -105,6 +107,7 @@ def test_install_pip_requirements(
sys.executable,
"-mpip",
"install",
"--user",
"--break-system-packages",
"--require-hashes",
"-r",
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d1b13cd

Please sign in to comment.