diff --git a/src/taskgraph/run-task/run-task b/src/taskgraph/run-task/run-task index f14267d72..42fd4d020 100755 --- a/src/taskgraph/run-task/run-task +++ b/src/taskgraph/run-task/run-task @@ -1028,10 +1028,25 @@ def install_pip_requirements(repositories): run_required_command(b"pip-install", cmd) -def _display_python_version(): +def _display_python_versions(): print_line( b"setup", b"Python version: %s\n" % platform.python_version().encode("utf-8") ) + + print_line(b"setup", b"Subprocess python version: " + b"\n") + + try: + subprocess.run(["uv", "python", "list","--no-cache","--only-installed"], check=True) + + except (FileNotFoundError, subprocess.CalledProcessError): + + python_versions = ["python","python3"] + + for python_executable in python_versions: + try: + subprocess.run([python_executable, "-c", "import platform; print(platform.python_version())"], check=True) + except FileNotFoundError: + pass def main(args): @@ -1044,7 +1059,7 @@ def main(args): b"setup", b"Invoked by command: %s\n" % " ".join(args).encode("utf-8"), ) - _display_python_version() + _display_python_versions() running_as_root = IS_POSIX and os.getuid() == 0 # Arguments up to '--' are ours. After are for the main task diff --git a/test/test_scripts_run_task.py b/test/test_scripts_run_task.py index fc8c905ba..b3867d17d 100644 --- a/test/test_scripts_run_task.py +++ b/test/test_scripts_run_task.py @@ -426,16 +426,19 @@ def test_git_checkout_with_commit( def test_display_python_version_should_output_python_versions_title( run_task_mod, capsys ): - run_task_mod._display_python_version() + run_task_mod._display_python_versions() - assert ("Python version:" in capsys.readouterr().out) is True + output = capsys.readouterr().out + assert ("Python version:" in output) is True + assert "Subprocess" in output and "version:" in output def test_display_python_version_should_output_python_versions(run_task_mod, capsys): - run_task_mod._display_python_version() + run_task_mod._display_python_versions() output = capsys.readouterr().out assert ("Python version: 3." in output) or ("Python version: 2." in output) is True + assert "Subprocess" in output and "version:" in output @pytest.fixture