Skip to content

Commit 8863b8d

Browse files
fix: used the uv to check python version
1 parent d580c77 commit 8863b8d

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/taskgraph/run-task/run-task

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,21 +1034,31 @@ def _display_python_version():
10341034
)
10351035

10361036
def _display_subprocess_python_version():
1037+
try:
1038+
output = subprocess.check_output(
1039+
["uv", "python", "list", "--only-installed"],
1040+
).strip()
10371041

1038-
python_versions = ["python","python3"]
1042+
if output:
1043+
for line in output.splitlines():
1044+
print_line(b"setup", b"Subprocess python version: " + line + b"\n")
10391045

1040-
for python_executable in python_versions:
1041-
try:
1042-
version = subprocess.check_output(
1043-
[python_executable, "-c", "import platform; print(platform.python_version())"],
1044-
).strip()
1046+
except FileNotFoundError:
10451047

1046-
print_line(
1047-
b"setup", b"Subprocess %s version: %s\n" % (python_executable.encode(), version)
1048-
)
1048+
python_versions = ["python","python3"]
10491049

1050-
except FileNotFoundError:
1051-
pass
1050+
for python_executable in python_versions:
1051+
try:
1052+
version = subprocess.check_output(
1053+
[python_executable, "-c", "import platform; print(platform.python_version())"],
1054+
).strip()
1055+
1056+
print_line(
1057+
b"setup", b"Subprocess %s version: %s\n" % (python_executable.encode(), version)
1058+
)
1059+
1060+
except FileNotFoundError:
1061+
pass
10521062

10531063

10541064
def main(args):

test/test_scripts_run_task.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,8 @@ def test_display_subprocess_python_version_should_output_python_versions_title(
443443
):
444444
run_task_mod._display_subprocess_python_version()
445445

446-
assert (
447-
("Subprocess python3 version:" in capsys.readouterr().out)
448-
or ("Subprocess python2 version:" in capsys.readouterr().out)
449-
or ("Subprocess python version:" in capsys.readouterr().out) is True
450-
)
446+
output = capsys.readouterr().out
447+
assert "Subprocess" in output and "version:" in output
451448

452449

453450
@pytest.fixture

0 commit comments

Comments
 (0)