Skip to content

Commit

Permalink
Merge pull request m2ci-msp#12 from kristyj/gradle-check-python
Browse files Browse the repository at this point in the history
Version checking with boundaries for python, numpy, pip
  • Loading branch information
kristyj committed Mar 4, 2016
2 parents 79c2532 + d9bd1a3 commit 58310c5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
5 changes: 5 additions & 0 deletions buildconfig/versionNumbers.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ numpy{
warnBelow = "1.9"
failBelow = "1.0"
}

pip{
warnBelow = "8.0.1"
failBelow = "8.0.0"
}
71 changes: 70 additions & 1 deletion gradlescripts/setup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ else{ //OS is Unix/Mac

def blenderpath = findbinary{ binary "blender" }.path

def blenderVersion = (parseVersion("$blenderpath -v")).toDouble()
def blenderVersionString = parseCL("$blenderpath -v")
def blenderVersion =blenderVersionString.tokenize()[1]
def builder = new groovy.json.JsonBuilder()

def json = builder.blender{
Expand Down Expand Up @@ -173,6 +174,7 @@ else{ //OS is Unix/Mac
task installMathUtils(type: Exec){

dependsOn cloneMathUtils
dependsOn checkPip
outputs.dir file("$rootProject.buildDir/mathutils/build")

// use "--prefix=" as workaround for bug on os x
Expand All @@ -184,6 +186,73 @@ else{ //OS is Unix/Mac

} // end OS check

/*--------------------------------------------------------------------------*/

ext.parseCL = {param -> // get the output from the CL call
def clOutput = new ByteArrayOutputStream()
exec{
workingDir = rootProject.buildDir
commandLine = param.tokenize()
standardOutput = clOutput
}
def outputAsString = clOutput.toString()
println "Result of call was: ${outputAsString}"
return outputAsString
}

ext.parseVerString = { verstring, boundstring -> // return true if verstring > boundstring
println("Comparing versions $verstring and $boundstring")
def verlist = verstring.tokenize('.').take(2)
def boundlist = boundstring.tokenize('.').take(2)
return verlist[0] > boundlist[0] || (verlist[0] == boundlist[0] & verlist[1] >= boundlist[1])
}


ext.pythonNumber = null

task checkPython() {
println("Checking python installation")
// try to search for python3 1 TODO
def pyStr = null
try{
pyStr = parseCL("python3 --version")
pythonNumber = "python3"
} catch(e){
println(e)
println("Command python3 failed")
pyStr = parseCL("python --version")
pythonNumber = "python"
}
def pyVer = pyStr.tokenize()[1]
println("Python version is $pyVer")
assert parseVerString(pyVer, versionNumbers.python.failBelow)
if (! parseVerString(pyVer, versionNumbers.python.warnBelow)){
println("WARNING - OLD PYTHON VERSION")
}
}

task checkPip() {
dependsOn checkPython
println("Checking Pip installation")
def pipStr = parseCL("pip -V")
def pipVer = pipStr.tokenize()[1]
println("Pip version is $pipVer")
assert parseVerString(pipVer, versionNumbers.pip.failBelow)
if (! parseVerString(pipVer, versionNumbers.pip.warnBelow)){
println("WARNING - OLD PIP VERSION")
}
}

task checkNumpy() {
dependsOn checkPython
println("Checking Numpy installation with python command $pythonNumber")
def numpyVer = parseCL("$pythonNumber -c \"import numpy;print(numpy.__version__)\"")
assert parseVerString(numpyVer, versionNumbers.numpy.failBelow)
if (! parseVerString(numpyVer, versionNumbers.numpy.warnBelow)){
println("WARNING - OLD NUMPY VERSION")
}
}

task setup() {
dependsOn findBlender
dependsOn installMathUtils
Expand Down

0 comments on commit 58310c5

Please sign in to comment.