From b02dddda354ab6a9a2a7a91bf1c23bae62aacfc3 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Thu, 5 Dec 2024 12:07:44 -0500 Subject: [PATCH] GP-0: Changing python search order to prefer newer versions over system defaults since those tend to be incomplete. Printing python executable path in build. --- build.gradle | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 93f27ed16b..26d2333986 100644 --- a/build.gradle +++ b/build.gradle @@ -168,8 +168,23 @@ def checkPythonVersion(List pyCmd) { standardOutput = stdout errorOutput = OutputStream.nullOutputStream() } - def version = "$stdout".strip() - return version + return "$stdout".strip() + } + catch (Exception e) { + return "ABSENT" + } +} + +def getPythonExecutable(List pyCmd) { + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine pyCmd + args "-c", "import sys; print(sys.executable)" + standardOutput = stdout + errorOutput = OutputStream.nullOutputStream() + } + return "$stdout".strip() } catch (Exception e) { return "ABSENT" @@ -204,13 +219,14 @@ def checkPip(List pyCmd, boolean shouldPrint) { } def findPython3(boolean shouldPrint) { - def pyCmds = [['py'], ['python3'], ['python']] - pyCmds += SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] } + def pyCmds = SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] } + pyCmds += [['py'], ['python3'], ['python']] for (pyCmd in pyCmds) { def pyVer = checkPythonVersion(pyCmd) + def pyExe = getPythonExecutable(pyCmd) if (pyVer in SUPPORTED_PY_VERSIONS) { if (shouldPrint) { - println("Python3 command: ${pyCmd} (version ${pyVer})") + println("Python3 command: ${pyCmd} (${pyVer}, ${pyExe})") } checkPip(pyCmd, shouldPrint) return pyCmd