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.
This commit is contained in:
Ryan Kurtz
2024-12-05 12:07:44 -05:00
parent c5b753e881
commit b02dddda35

View File

@@ -168,8 +168,23 @@ def checkPythonVersion(List<String> pyCmd) {
standardOutput = stdout standardOutput = stdout
errorOutput = OutputStream.nullOutputStream() errorOutput = OutputStream.nullOutputStream()
} }
def version = "$stdout".strip() return "$stdout".strip()
return version }
catch (Exception e) {
return "ABSENT"
}
}
def getPythonExecutable(List<String> 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) { catch (Exception e) {
return "ABSENT" return "ABSENT"
@@ -204,13 +219,14 @@ def checkPip(List<String> pyCmd, boolean shouldPrint) {
} }
def findPython3(boolean shouldPrint) { def findPython3(boolean shouldPrint) {
def pyCmds = [['py'], ['python3'], ['python']] def pyCmds = SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] }
pyCmds += SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] } pyCmds += [['py'], ['python3'], ['python']]
for (pyCmd in pyCmds) { for (pyCmd in pyCmds) {
def pyVer = checkPythonVersion(pyCmd) def pyVer = checkPythonVersion(pyCmd)
def pyExe = getPythonExecutable(pyCmd)
if (pyVer in SUPPORTED_PY_VERSIONS) { if (pyVer in SUPPORTED_PY_VERSIONS) {
if (shouldPrint) { if (shouldPrint) {
println("Python3 command: ${pyCmd} (version ${pyVer})") println("Python3 command: ${pyCmd} (${pyVer}, ${pyExe})")
} }
checkPip(pyCmd, shouldPrint) checkPip(pyCmd, shouldPrint)
return pyCmd return pyCmd