From 1acd25a1ae79beb0293753ebb23880b019783f7a Mon Sep 17 00:00:00 2001 From: abhishekmadan30 Date: Thu, 31 Jul 2025 11:49:39 -0400 Subject: [PATCH] fix: dump subprocesses python versions Closes #7 --- src/taskgraph/run-task/run-task | 18 ++++++++++++++++++ test/test_scripts_run_task.py | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/taskgraph/run-task/run-task b/src/taskgraph/run-task/run-task index f14267d72..b80e4777e 100755 --- a/src/taskgraph/run-task/run-task +++ b/src/taskgraph/run-task/run-task @@ -1033,6 +1033,23 @@ def _display_python_version(): b"setup", b"Python version: %s\n" % platform.python_version().encode("utf-8") ) +def _display_subprocess_python_version(): + + python_versions = ["python","python3"] + + for python_executable in python_versions: + try: + version = subprocess.check_output( + [python_executable, "-c", "import platform; print(platform.python_version())"], + ).strip() + + print_line( + b"setup", b"Subprocess %s version: %s\n" % (python_executable.encode(), version) + ) + + except FileNotFoundError: + pass + def main(args): task_workdir = os.environ["TASK_WORKDIR"] = os.getcwd() @@ -1045,6 +1062,7 @@ def main(args): b"Invoked by command: %s\n" % " ".join(args).encode("utf-8"), ) _display_python_version() + _display_subprocess_python_version() 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..9afff0cf1 100644 --- a/test/test_scripts_run_task.py +++ b/test/test_scripts_run_task.py @@ -438,6 +438,18 @@ def test_display_python_version_should_output_python_versions(run_task_mod, caps assert ("Python version: 3." in output) or ("Python version: 2." in output) is True +def test_display_subprocess_python_version_should_output_python_versions_title( + run_task_mod, capsys +): + run_task_mod._display_subprocess_python_version() + + assert ( + ("Subprocess python3 version:" in capsys.readouterr().out) + or ("Subprocess python2 version:" in capsys.readouterr().out) + or ("Subprocess python version:" in capsys.readouterr().out) is True + ) + + @pytest.fixture def run_main(tmp_path, mocker, mock_stdin, run_task_mod): base_args = [