From 1acd25a1ae79beb0293753ebb23880b019783f7a Mon Sep 17 00:00:00 2001 From: abhishekmadan30 Date: Thu, 31 Jul 2025 11:49:39 -0400 Subject: [PATCH 1/4] 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 = [ From d25995981cfed022be6e53453506d2628a90a92c Mon Sep 17 00:00:00 2001 From: abhishekmadan30 Date: Fri, 1 Aug 2025 15:00:00 -0400 Subject: [PATCH 2/4] fix: used the uv to check python version --- src/taskgraph/run-task/run-task | 29 +++++++++++++---------------- test/test_scripts_run_task.py | 21 ++++++--------------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/taskgraph/run-task/run-task b/src/taskgraph/run-task/run-task index b80e4777e..394628eee 100755 --- a/src/taskgraph/run-task/run-task +++ b/src/taskgraph/run-task/run-task @@ -1028,27 +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") -def _display_subprocess_python_version(): - - python_versions = ["python","python3"] + try: + subprocess.run(["uv", "python", "list", "--only-installed"], check=True) - for python_executable in python_versions: - try: - version = subprocess.check_output( - [python_executable, "-c", "import platform; print(platform.python_version())"], - ).strip() + except FileNotFoundError: - print_line( - b"setup", b"Subprocess %s version: %s\n" % (python_executable.encode(), version) - ) + python_versions = ["python","python3"] - except FileNotFoundError: - pass + 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): @@ -1061,8 +1059,7 @@ def main(args): b"setup", b"Invoked by command: %s\n" % " ".join(args).encode("utf-8"), ) - _display_python_version() - _display_subprocess_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 9afff0cf1..b3867d17d 100644 --- a/test/test_scripts_run_task.py +++ b/test/test_scripts_run_task.py @@ -426,28 +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 - - -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 - ) + assert "Subprocess" in output and "version:" in output @pytest.fixture From b4ff930893be93be61f23cc3a48d3f49500f3a6d Mon Sep 17 00:00:00 2001 From: abhishekmadan30 Date: Fri, 1 Aug 2025 15:00:00 -0400 Subject: [PATCH 3/4] fix: used the uv to check python version --- src/taskgraph/run-task/run-task | 29 +++++++++++++---------------- test/test_scripts_run_task.py | 21 ++++++--------------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/taskgraph/run-task/run-task b/src/taskgraph/run-task/run-task index b80e4777e..226d6932b 100755 --- a/src/taskgraph/run-task/run-task +++ b/src/taskgraph/run-task/run-task @@ -1028,27 +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") -def _display_subprocess_python_version(): - - python_versions = ["python","python3"] + try: + subprocess.run(["uv", "python", "list", "--only-installed"], check=True) - for python_executable in python_versions: - try: - version = subprocess.check_output( - [python_executable, "-c", "import platform; print(platform.python_version())"], - ).strip() + except FileNotFoundError or subprocess.CalledProcessError: - print_line( - b"setup", b"Subprocess %s version: %s\n" % (python_executable.encode(), version) - ) + python_versions = ["python","python3"] - except FileNotFoundError: - pass + 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): @@ -1061,8 +1059,7 @@ def main(args): b"setup", b"Invoked by command: %s\n" % " ".join(args).encode("utf-8"), ) - _display_python_version() - _display_subprocess_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 9afff0cf1..b3867d17d 100644 --- a/test/test_scripts_run_task.py +++ b/test/test_scripts_run_task.py @@ -426,28 +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 - - -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 - ) + assert "Subprocess" in output and "version:" in output @pytest.fixture From 68203ef6c25f41afd42365e7d6008637ab0988e5 Mon Sep 17 00:00:00 2001 From: abhishekmadan30 Date: Fri, 8 Aug 2025 14:29:21 -0400 Subject: [PATCH 4/4] fix: removed caching --- src/taskgraph/run-task/run-task | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/taskgraph/run-task/run-task b/src/taskgraph/run-task/run-task index 7f6301061..42fd4d020 100755 --- a/src/taskgraph/run-task/run-task +++ b/src/taskgraph/run-task/run-task @@ -1036,7 +1036,7 @@ def _display_python_versions(): print_line(b"setup", b"Subprocess python version: " + b"\n") try: - subprocess.run(["uv", "python", "list", "--only-installed"], check=True) + subprocess.run(["uv", "python", "list","--no-cache","--only-installed"], check=True) except (FileNotFoundError, subprocess.CalledProcessError):