Unverified Commit 8af5a5c4 authored by yihong's avatar yihong Committed by GitHub
Browse files

fix: can not use uv run collect_env close #13888 (#15792)


Signed-off-by: default avataryihong0618 <zouzou0208@gmail.com>
parent 3a5f0afc
...@@ -482,16 +482,28 @@ def get_pip_packages(run_lambda, patterns=None): ...@@ -482,16 +482,28 @@ def get_pip_packages(run_lambda, patterns=None):
if patterns is None: if patterns is None:
patterns = DEFAULT_PIP_PATTERNS patterns = DEFAULT_PIP_PATTERNS
# People generally have `pip` as `pip` or `pip3` def run_with_pip():
# But here it is invoked as `python -mpip` try:
def run_with_pip(pip): import importlib.util
out = run_and_read_all(run_lambda, pip + ["list", "--format=freeze"]) pip_spec = importlib.util.find_spec('pip')
pip_available = pip_spec is not None
except ImportError:
pip_available = False
if pip_available:
cmd = [sys.executable, '-mpip', 'list', '--format=freeze']
elif os.environ.get("UV") is not None:
print("uv is set")
cmd = ["uv", "pip", "list", "--format=freeze"]
else:
raise RuntimeError("Could not collect pip list output (pip or uv module not available)")
out = run_and_read_all(run_lambda, cmd)
return "\n".join(line for line in out.splitlines() return "\n".join(line for line in out.splitlines()
if any(name in line for name in patterns)) if any(name in line for name in patterns))
pip_version = 'pip3' if sys.version[0] == '3' else 'pip' pip_version = 'pip3' if sys.version[0] == '3' else 'pip'
out = run_with_pip([sys.executable, '-mpip']) out = run_with_pip()
return pip_version, out return pip_version, out
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment