GP-0: Improving python build error reporting (Closes #7036)

This commit is contained in:
Ryan Kurtz 2024-10-11 14:13:24 -04:00
parent ddf1efd486
commit 3558fe59a4
5 changed files with 30 additions and 13 deletions

View File

@ -56,7 +56,9 @@ task installJPype(type: Exec) {
File binRepoDir = file("${BIN_REPO}/ExternalPyWheels")
def dir = depsDir.exists() ? depsDir : binRepoDir
doFirst {
commandLine "$PYTHON3_VENV", "-m", "pip", "install", "--no-index", "-f", "$dir", "JPype1"
}
}
// Install PyGhidra in editable mode to the development virtual environment
@ -67,10 +69,12 @@ task installEditablePyGhidra(type: Exec) {
File binRepoDir = file("${BIN_REPO}/ExternalPyWheels")
def dir = depsDir.exists() ? depsDir : binRepoDir
doFirst {
commandLine "$PYTHON3_VENV", "-m", "pip", "install", "-e", "src/main/py", "--no-index", "-f", "$dir"
}
}
if (findPython3(false, false)) {
if (findPython3(false)) {
rootProject.prepDev.dependsOn installEditablePyGhidra
}

View File

@ -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, true)
project.ext.PYTHON3 = findPython3(true)
project.ext.PYTHON_DEPS = new HashSet<String>()
/*********************************************************************************
@ -204,7 +204,7 @@ def checkPip(List<String> pyCmd, boolean shouldPrint) {
}
}
def findPython3(boolean useDefault, boolean shouldPrint) {
def findPython3(boolean shouldPrint) {
def pyCmds = [['py'], ['python3'], ['python']]
pyCmds += SUPPORTED_PY_VERSIONS.collectMany { [["python$it"], ["py", "-$it"]] }
for (pyCmd in pyCmds) {
@ -218,14 +218,12 @@ def findPython3(boolean useDefault, boolean shouldPrint) {
}
}
// 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.
if (shouldPrint) {
println("Warning: Supported Python ${SUPPORTED_PY_VERSIONS} not found (required for build)")
}
return useDefault ? 'python3.9' : null
// Don't fail until task execution. Just retun null, which can be gracefully handled later.
return null
}
/******************************************************************************************

View File

@ -48,6 +48,10 @@ task buildPyPackage {
outputs.dir(dist)
doLast {
if (rootProject.PYTHON3 == null) {
throw new GradleException("A supported version of Python ${SUPPORTED_PY_VERSIONS} was not found!")
}
File setuptools = project(":Debugger-rmi-trace").findPyDep(".")
exec {
workingDir { "build/pypkg" }

View File

@ -271,6 +271,11 @@ task createGhidraStubsWheel {
doLast {
File setuptools = project(":Debugger-rmi-trace").findPyDep(".")
if (rootProject.PYTHON3 == null) {
throw new GradleException("A supported version of Python ${SUPPORTED_PY_VERSIONS} was not found!")
}
exec {
workingDir { cwd.toString() }
commandLine rootProject.PYTHON3

View File

@ -25,10 +25,16 @@ task createPythonVirtualEnvironment(type: Exec) {
project.ext.PYTHON3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/python${suffix}"
project.ext.PIP3_VENV = "${rootProject.projectDir}/${venvDir}/${binDir}/pip${suffix}"
doFirst {
if (rootProject.PYTHON3 == null) {
throw new GradleException("A supported version of Python ${SUPPORTED_PY_VERSIONS} was not found!")
}
commandLine rootProject.PYTHON3
args "-m", "venv", venvDir, "--copies"
}
}
if (findPython3(false, false)) {
if (findPython3(false)) {
rootProject.prepDev.dependsOn createPythonVirtualEnvironment
}