Skip to content

Commit 88bf78d

Browse files
fix: dump subprocesses python versions
Closes #7
1 parent d2dee6a commit 88bf78d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/taskgraph/run-task/run-task

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,24 @@ def _display_python_version():
10331033
b"setup", b"Python version: %s\n" % platform.python_version().encode("utf-8")
10341034
)
10351035

1036+
def _display_subprocess_python_version():
1037+
1038+
python_versions = ["python","python2","python3"]
1039+
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+
text=True
1045+
).strip()
1046+
1047+
print_line(
1048+
b"setup", b"Subprocess %s version: %s\n" % (python_executable.encode(), version.encode("utf-8"))
1049+
)
1050+
1051+
except FileNotFoundError:
1052+
pass
1053+
10361054

10371055
def main(args):
10381056
task_workdir = os.environ["TASK_WORKDIR"] = os.getcwd()
@@ -1045,6 +1063,7 @@ def main(args):
10451063
b"Invoked by command: %s\n" % " ".join(args).encode("utf-8"),
10461064
)
10471065
_display_python_version()
1066+
_display_subprocess_python_version()
10481067
running_as_root = IS_POSIX and os.getuid() == 0
10491068

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

test/test_scripts_run_task.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,18 @@ def test_display_python_version_should_output_python_versions(run_task_mod, caps
438438
assert ("Python version: 3." in output) or ("Python version: 2." in output) is True
439439

440440

441+
def test_display_subprocess_python_version_should_output_python_versions_title(
442+
run_task_mod, capsys
443+
):
444+
run_task_mod._display_subprocess_python_version()
445+
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+
)
451+
452+
441453
@pytest.fixture
442454
def run_main(tmp_path, mocker, mock_stdin, run_task_mod):
443455
base_args = [

0 commit comments

Comments
 (0)