diff --git a/build.gradle b/build.gradle index f93dddda8..6e5465623 100644 --- a/build.gradle +++ b/build.gradle @@ -196,8 +196,31 @@ allprojects { } } +rootProject.ext { + pyver = { exe -> + try { + ext.execInBash( + exe + " -c 'import sys; print(sys.hexversion)'", "/") as Integer + } catch (org.gradle.process.internal.ExecException e) { + return -1; + } + } +} + task runPresubmits(type: Exec) { - executable '/usr/bin/python3' + + // Find a python version greater than 3.7.3 (this is somewhat arbitrary, we + // know we'd like at least 3.6, but 3.7.3 is the latest that ships with + // Debian so it seems like that should be available anywhere). + def MIN_PY_VER = 0x3070300 + if (pyver('python') >= MIN_PY_VER) { + executable 'python' + } else if (pyver('/usr/bin/python3') >= MIN_PY_VER) { + executable '/usr/bin/python3' + } else { + throw new GradleException("No usable Python version found (build " + + "requires at least python 3.7.3)"); + } args('config/presubmits.py') } diff --git a/config/presubmits.py b/config/presubmits.py index b54f5c325..f1f499a8f 100644 --- a/config/presubmits.py +++ b/config/presubmits.py @@ -344,6 +344,7 @@ def get_files(): if __name__ == "__main__": + print('python version is %s' % sys.version) failed = False for file in get_files(): error_messages = []