Files
openide/python/setup-test-environment/build.gradle
Andrey Lisin 32d4cdd9f9 Fix NumPy version in test environments
(cherry picked from commit 02f044c58f387be077b5d300bf85e6ddb6bab3f8)

IDEA-CR-68767

GitOrigin-RevId: 473c9df2a4a35accf317a0194d5b671ee8de97f1
2020-11-16 10:28:46 +00:00

208 lines
8.1 KiB
Groovy

// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
import org.apache.tools.ant.taskdefs.condition.Os
import java.nio.file.Files
import java.nio.file.Paths
plugins {
id "com.jetbrains.python.envs" version "0.0.30"
}
boolean isWindows = Os.isFamily(Os.FAMILY_WINDOWS)
boolean isUnix = Os.isFamily(Os.FAMILY_UNIX)
/**
* Installs python interpreters for env. tests using conda or CPython.
* Utilizes following env variables:
*
* PYCHARM_PYTHONS -- path to install cPythons
* PYCHARM_PYTHON_VIRTUAL_ENVS -- path to install condas
*
* PYCHARM_USE_CONDA -- use conda (cPython will be used if not set)
*
* PYCHARM_ZIP_REPOSITORY -- to download unpacked pythons for Windows (default cpython does not support unattended installation)
* Recommended value: https://repo.labs.intellij.net/pycharm/python-archives-windows/
*
* Pitfall: TMP var on windows points to very long path inside of user local dir and may lead to errors.
* It is recommended to create "c:\temp\" with full write access and set TMP="c:\temp\" on Windows.
*
* When -DdjangoTrunkOnly passed, only install django_latest for Django Trunk tests
*
* ``PyEnvTestSettings`` class uses these vars also.
*
*
*/
envs {
String python27version = "2.7.18"
String python36version = "3.6.8"
String python37version = "3.7.8"
String python38version = "3.8.5"
String python39version = isWindows ? "3.9.0b4" : "3.9-dev"
bootstrapDirectory = new File(System.getenv().getOrDefault("PYCHARM_PYTHONS", new File(buildDir, 'pythons').path))
envsDirectory = new File(System.getenv().getOrDefault("PYCHARM_PYTHON_VIRTUAL_ENVS", new File(buildDir, 'envs').path))
def djangoTrunkOnly = System.getProperty("djangoTrunkOnly") ?: false
if (System.getenv().containsKey("PYCHARM_ZIP_REPOSITORY")) {
zipRepository = new URL(System.getenv().get("PYCHARM_ZIP_REPOSITORY"))
shouldUseZipsFromRepository = isWindows
}
Boolean shouldUseCondaInterpreters = System.getenv().getOrDefault("PYCHARM_USE_CONDA", false)
Closure createPython = { String pythonName,
String version,
List<String> packages = null,
String tags = null,
Boolean createLink = false,
Boolean forceConda = false ->
File pythonDirectory
if (shouldUseCondaInterpreters || forceConda) {
condaenv pythonName, version, packages
pythonDirectory = new File(envsDirectory, pythonName)
} else {
python pythonName, version, packages
pythonDirectory = new File(bootstrapDirectory, pythonName)
}
print("Python dir: $pythonDirectory\n")
project.tasks.create("Misc for $pythonName") {
shouldRunAfter 'build_envs'
doLast {
if (tags) new File(pythonDirectory, "tags.txt").write(tags)
if (createLink) {
String versionMajor = version.split(/\./)[0]
String versionMinor = version.split(/\./)[1]
versionMinor = versionMinor.endsWith("-dev") ? versionMinor.substring(0, versionMinor.indexOf("-dev"))
: versionMinor
String linkName = "python$versionMajor.$versionMinor"
Closure createLinkClosure = { java.nio.file.Path link, java.nio.file.Path existing ->
if (!link.toFile().exists()) Files.createLink(link, existing)
}
if (isUnix && !shouldUseCondaInterpreters) {
createLinkClosure(Paths.get(pythonDirectory.toString(), linkName),
Paths.get(pythonDirectory.toString(), "bin/$linkName"))
} else if (isWindows) {
createLinkClosure(Paths.get(pythonDirectory.toString(), "${linkName}.exe"),
Paths.get(pythonDirectory.toString(), "python.exe"))
}
}
}
}
}
createPython("django_latest", python36version, ["django", "behave-django", "behave", "pytest", "untangle"],
"python3.6\ndjango\ndjango20\nbehave\nbehave-django\ndjango2\npytest\nuntangle", true)
if (djangoTrunkOnly) {
return
}
createPython("py27_django11_full",
python27version,
["django==1.11", "tox>=3.8.3", "nose", "pytest", "Twisted", "behave", "teamcity-messages", "django-nose",
"untangle"] + ( isWindows ? ['pypiwin32'] : [] ), //win32api is required for pypiwin32
"python2.7\ndjango\nnose\npytest\nbehave\nnpackaging\ntox\ntwisted\ndjango-nose\nuntangle\nmessages",
true)
createPython("py38_django22_full",
python38version,
// The version of Jinja2 is fixed due to a bug in recent versions which breaks the debugging.
// See: https://github.com/pallets/jinja/pull/1178.
// The version of NumPy is fixed due to https://tinyurl.com/y3dm3h86.
["ipython==7.8", "django==2.2", "behave", "jinja2==2.10.2", "tox>=2.0", "nose", "pytest", "django-nose", "behave-django",
"pytest-xdist", "untangle", "numpy==1.19.3", "pandas"],
"python3.8\npython3\nipython\nipython780\nskeletons\ndjango\nbehave\nbehave-django\ntox\njinja2\npackaging" +
"\npytest\nnose\ndjango-nose\nbehave-django\ndjango2\nxdist\nuntangle\npandas",
true)
createPython("python3.9",
python39version,
["pytest", "pytest-xdist"],
"python3.9\npython3\npytest\nxdist",
true)
// For tox
createPython("py36",
python36version,
[],
"python3.6",
true)
createPython("py37",
python37version,
[],
"python3.7",
true)
// For TensorFlow
createPython("py37_tensorflow1_oldpaths",
python37version,
["tensorflow < 1.15.0rc0"],
"tensorflow1\ntensorflow_oldpaths",
true)
createPython("py37_tensorflow1_newpaths",
python37version,
["tensorflow >= 1.15.0rc0, < 2.0.0a0"],
"tensorflow1\ntensorflow_newpaths",
true)
createPython("py37_tensorflow2_oldpaths",
python37version,
["tensorflow >= 2.0.0a0, < 2.0.0rc0"],
"tensorflow2\ntensorflow_oldpaths",
true)
createPython("py37_tensorflow2_newpaths",
python37version,
["tensorflow >= 2.0.0rc0"],
"tensorflow2\ntensorflow_newpaths",
true)
if (isUnix) {
createPython("qt_env", python37version, ["pyqt5==5.12", "PySide2==5.12.1"], "qt", true)
}
}
/**
* Kills any process named "python" using windows powershell.
* Works on Win7+.
*/
task killPythonWindows(type: Exec) {
onlyIf { isWindows }
commandLine 'powershell', '"Get-Process | where {$_.Name -ieq \\"python\\"} | Stop-Process"'
}
task prepare(type: Delete) {
// Python leaked from previous test may prevent this script from
// deleting folder because you can't delete file opened by process on Windows
dependsOn killPythonWindows
doFirst {
new File(envs.bootstrapDirectory, "django_latest").with { djangoLatestFolder ->
// if (djangoLatestFolder.exists() && djangoLatestFolder.lastModified() < System.currentTimeMillis() - 24 * 60 * 60 * 1000) {
// older then a day
println "Cleaning django_latest at" + djangoLatestFolder
delete djangoLatestFolder
// }
}
// if (!envs.bootstrapDirectory.exists() || (System.getenv("NO_CLEAN") == null && envs.envsDirectory.exists() &&
// envs.envsDirectory.lastModified() < project.buildscript.sourceFile.lastModified())) {
// clean the cache if the build script was modified later
println "Cleaning cached environments at " + envs.envsDirectory
delete envs.envsDirectory
println "Cleaning cached pythons at " + envs.bootstrapDirectory
delete envs.bootstrapDirectory
//}
}
}
task build {
mustRunAfter prepare
dependsOn prepare, 'build_envs', tasks.findAll { it.name.startsWith("Misc") }
}