Skip to content

Instantly share code, notes, and snippets.

@SlyDen
Created August 7, 2015 12:41
Show Gist options
  • Save SlyDen/1bcdca4e91dc1a899337 to your computer and use it in GitHub Desktop.
Save SlyDen/1bcdca4e91dc1a899337 to your computer and use it in GitHub Desktop.
task checkPython << {
def python27Executable = ['python2.7', 'python'].find { python ->
try {
def check = "import sys; sys.exit(0 if sys.version_info >= (2,7) and sys.version_info < (3,) else 1)"
return [python, "-c", check].execute().waitFor() == 0
} catch (IOException e) {
return false
}
}
if (python27Executable == null) {
throw new GradleException('Build requires Python 2.7.')
} else {
thriftEntities.python = python27Executable
}
}
generateThriftEntitiesJava.dependsOn checkPython
@SlyDen
Copy link
Author

SlyDen commented Aug 7, 2015

https://github.com/captsens/clichart/blob/master/build.gradle#L58

task pythonTests << {
runPythonTests(false)
}

task pythonCoverage << {
runPythonTests(true)
}

def runPythonTests(def includeCoverage) {
def sourceFiles = fileTree(pythonScriptDir).include('/*.py')
def testFiles = fileTree('src/test/python').include('
/*Test.py')
def pythonCoverageDir = file("$buildDir/reports/pythonCoverage")
def arguments = []
if (includeCoverage) {
arguments = ['--with-coverage', '--cover-erase', '--cover-html', '--cover-html-dir',
pythonCoverageDir]
delete(pythonCoverageDir)
logger.lifecycle "Coverage report can be found in $pythonCoverageDir"
}
exec {
executable = "nosetests"
args = arguments + testFiles.collect{it.getPath()}
environment = ['PYTHONPATH': pythonScriptDir]
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment