Skip to content

Commit c50bc6a

Browse files
feat(run-task): use uv command to check python version (#733)
1 parent 9b6b0c4 commit c50bc6a

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/taskgraph/run-task/run-task

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,10 +1028,25 @@ def install_pip_requirements(repositories):
10281028
run_required_command(b"pip-install", cmd)
10291029

10301030

1031-
def _display_python_version():
1031+
def _display_python_versions():
10321032
print_line(
10331033
b"setup", b"Python version: %s\n" % platform.python_version().encode("utf-8")
10341034
)
1035+
1036+
print_line(b"setup", b"Subprocess python version: " + b"\n")
1037+
1038+
try:
1039+
subprocess.run(["uv", "python", "list","--no-cache","--only-installed"], check=True)
1040+
1041+
except (FileNotFoundError, subprocess.CalledProcessError):
1042+
1043+
python_versions = ["python","python3"]
1044+
1045+
for python_executable in python_versions:
1046+
try:
1047+
subprocess.run([python_executable, "-c", "import platform; print(platform.python_version())"], check=True)
1048+
except FileNotFoundError:
1049+
pass
10351050

10361051

10371052
def main(args):
@@ -1044,7 +1059,7 @@ def main(args):
10441059
b"setup",
10451060
b"Invoked by command: %s\n" % " ".join(args).encode("utf-8"),
10461061
)
1047-
_display_python_version()
1062+
_display_python_versions()
10481063
running_as_root = IS_POSIX and os.getuid() == 0
10491064

10501065
# Arguments up to '--' are ours. After are for the main task

test/test_scripts_run_task.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,16 +426,19 @@ def test_git_checkout_with_commit(
426426
def test_display_python_version_should_output_python_versions_title(
427427
run_task_mod, capsys
428428
):
429-
run_task_mod._display_python_version()
429+
run_task_mod._display_python_versions()
430430

431-
assert ("Python version:" in capsys.readouterr().out) is True
431+
output = capsys.readouterr().out
432+
assert ("Python version:" in output) is True
433+
assert "Subprocess" in output and "version:" in output
432434

433435

434436
def test_display_python_version_should_output_python_versions(run_task_mod, capsys):
435-
run_task_mod._display_python_version()
437+
run_task_mod._display_python_versions()
436438

437439
output = capsys.readouterr().out
438440
assert ("Python version: 3." in output) or ("Python version: 2." in output) is True
441+
assert "Subprocess" in output and "version:" in output
439442

440443

441444
@pytest.fixture

0 commit comments

Comments
 (0)