diff --git a/Ghidra/Features/PyGhidra/build.gradle b/Ghidra/Features/PyGhidra/build.gradle index dead56a036..d2647bbc16 100644 --- a/Ghidra/Features/PyGhidra/build.gradle +++ b/Ghidra/Features/PyGhidra/build.gradle @@ -70,7 +70,7 @@ task installEditablePyGhidra(type: Exec) { commandLine "$PYTHON3_VENV", "-m", "pip", "install", "-e", "src/main/py", "--no-index", "-f", "$dir" } -if (findPython3(false)) { +if (findPython3(false, false)) { rootProject.prepDev.dependsOn installEditablePyGhidra } diff --git a/build.gradle b/build.gradle index 754a98c949..818ea8fecb 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,7 @@ if ("32".equals(System.getProperty("sun.arch.data.model"))) { * Identify supported Python command ***************************************************************************************/ project.ext.SUPPORTED_PY_VERSIONS = ['3.12', '3.11', '3.10', '3.9'] -project.ext.PYTHON3 = findPython3(true) +project.ext.PYTHON3 = findPython3(true, true) project.ext.PYTHON_DEPS = new HashSet() /********************************************************************************* @@ -160,11 +160,12 @@ def checkGradleVersion() { * Although warnings may be produced no exception is thrown since python only required * for specific build tasks and is not required for prepdev *********************************************************************************/ -def checkPythonVersion(String pyCmd) { +def checkPythonVersion(List pyCmd) { try { def stdout = new ByteArrayOutputStream() exec { - commandLine pyCmd, "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))" + commandLine pyCmd + args "-c", "import sys; print('{0}.{1}'.format(*sys.version_info))" standardOutput = stdout errorOutput = OutputStream.nullOutputStream() } @@ -176,49 +177,53 @@ def checkPythonVersion(String pyCmd) { } } -def checkPip(String pyCmd) { +def checkPip(List pyCmd, boolean shouldPrint) { try { def stdout = new ByteArrayOutputStream() exec { - commandLine pyCmd, "-c", "import pip; print(pip.__version__)" + commandLine pyCmd + args "-c", "import pip; print(pip.__version__)" standardOutput = stdout errorOutput = OutputStream.nullOutputStream() } def version = "$stdout".strip(); - if (version.length() == 0) { - println("Warning: Python3 pip not installed (required for build)") - } - else { - println("Python3 pip version: ${version}") + if (shouldPrint) { + if (version.length() == 0) { + println("Warning: Python3 pip not installed (required for build)") + } + else { + println("Python3 pip version: ${version}") + } } return version } catch (Exception e) { - println("Warning: Python3 pip not installed (required for build)") + if (shouldPrint) { + println("Warning: Python3 pip not installed (required for build)") + } } } -def findPython3(boolean useDefault) { - for (pyCmd in ['py', 'python3', 'python']) { +def findPython3(boolean useDefault, boolean shouldPrint) { + def pyCmds = [['py'], ['python3'], ['python']] + pyCmds += SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] } + for (pyCmd in pyCmds) { def pyVer = checkPythonVersion(pyCmd) if (pyVer in SUPPORTED_PY_VERSIONS) { - println("Python3 command: ${pyCmd} (version ${pyVer})") - checkPip(pyCmd) - return pyCmd - } - } - for (pyVer in SUPPORTED_PY_VERSIONS) { - def pyCmd = "python${pyVer}" - if (checkPythonVersion(pyCmd) in SUPPORTED_PY_VERSIONS) { - println("Python3 command: ${pyCmd}") - checkPip(pyCmd) + if (shouldPrint) { + println("Python3 command: ${pyCmd} (version ${pyVer})") + } + checkPip(pyCmd, shouldPrint) return pyCmd } } + // Don't fail until task execution. Just let "python3" fail. // Force use of non-existent python3.9 instead of unsupported python version // which should fail if a python build is performed. - println("Warning: Python3 command not found (required for build)") + if (shouldPrint) { + println("Warning: Supported Python ${SUPPORTED_PY_VERSIONS} not found (required for build)") + } return useDefault ? 'python3.9' : null } diff --git a/gradle/hasPythonPackage.gradle b/gradle/hasPythonPackage.gradle index 7f40010229..3755575dd8 100644 --- a/gradle/hasPythonPackage.gradle +++ b/gradle/hasPythonPackage.gradle @@ -51,10 +51,8 @@ task buildPyPackage { File setuptools = project(":Debugger-rmi-trace").findPyDep(".") exec { workingDir { "build/pypkg" } - commandLine rootProject.PYTHON3, "-m", "pip" - args "wheel", "-w", "dist/", "--no-index", "--no-deps" - args "-f", setuptools - args "." + commandLine rootProject.PYTHON3 + args "-m", "pip", "wheel", "-w", "dist/", "--no-index", "--no-deps", "-f", setuptools, "." } } } diff --git a/gradle/root/venv.gradle b/gradle/root/venv.gradle index 29a292847d..c20bdd54a8 100644 --- a/gradle/root/venv.gradle +++ b/gradle/root/venv.gradle @@ -25,9 +25,10 @@ task createPythonVirtualEnvironment(type: Exec) { project.ext.PYTHON3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/python${suffix}" project.ext.PIP3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/pip${suffix}" - commandLine rootProject.PYTHON3, "-m", "venv", venvDir, "--copies" + commandLine rootProject.PYTHON3 + args "-m", "venv", venvDir, "--copies" } -if (findPython3(false)) { +if (findPython3(false, false)) { rootProject.prepDev.dependsOn createPythonVirtualEnvironment }