Skip to content

Commit 10d76e7

Browse files
authored
[BE] Fix lintrunner init for uv based environments (#6928)
Fixes lintrunner init when uv is installed locally and used to generated the venv, porting over `uv` related fixes from https://github.com/pytorch/pytorch/blob/main/tools/linter/adapters/pip_init.py
1 parent 601e6f4 commit 10d76e7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tools/linter/adapters/pip_init.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
Initializer script that installs stuff to pip.
33
"""
44

5+
from __future__ import annotations
6+
57
import argparse
68
import logging
79
import os
10+
import shutil
811
import subprocess
912
import sys
1013
import time
11-
from typing import List
1214

1315

14-
def run_command(args: List[str]) -> "subprocess.CompletedProcess[bytes]":
16+
def run_command(args: list[str]) -> subprocess.CompletedProcess[bytes]:
1517
logging.debug("$ %s", " ".join(args))
1618
start_time = time.monotonic()
1719
try:
@@ -50,7 +52,17 @@ def run_command(args: List[str]) -> "subprocess.CompletedProcess[bytes]":
5052
stream=sys.stderr,
5153
)
5254

53-
pip_args = ["pip3", "install"]
55+
uv_available = (
56+
any(prefix in sys.base_prefix for prefix in ["uv/python", "uv\\python"])
57+
and shutil.which("uv") is not None
58+
)
59+
60+
if uv_available:
61+
pip_args = ["uv", "pip", "install"]
62+
elif sys.executable:
63+
pip_args = [sys.executable, "-mpip", "install"]
64+
else:
65+
pip_args = ["pip3", "install"]
5466

5567
# If we are in a global install, use `--user` to install so that you do not
5668
# need root access in order to initialize linters.

0 commit comments

Comments
 (0)