Files
openide/python/setup-test-environment/build.gradle

113 lines
4.3 KiB
Groovy

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.21"
}
envs {
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))
if (System.getenv().containsKey("PYCHARM_ZIP_REPOSITORY")) {
zipRepository = new URL(System.getenv().get("PYCHARM_ZIP_REPOSITORY"))
shouldUseZipsFromRepository = Os.isFamily(Os.FAMILY_WINDOWS)
}
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)
}
project.tasks.create("Misc for $pythonName") {
shouldRunAfter 'build_envs'
doLast {
if (tags) new File(pythonDirectory, "tags.txt").write(tags)
if (createLink) {
String linkName = "python${version.split(/\./)[0..1].join(".")}"
if (Os.isFamily(Os.FAMILY_UNIX) && !shouldUseCondaInterpreters) {
Files.createLink(Paths.get(pythonDirectory.toString(), linkName),
Paths.get(pythonDirectory.toString(), "bin/$linkName"))
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
Files.createLink(Paths.get(pythonDirectory.toString(), "${linkName}.exe"),
Paths.get(pythonDirectory.toString(), "python.exe"))
}
}
}
}
}
createPython("django19",
"2.7.13",
["django==1.9", "tox", "nose", "pytest", "Twisted", "behave", "lettuce>=0.2.22", "unittest2", "teamcity-messages"],
"python2.7\ndjango\nnose\npytest\nbehave\nlettuce\npackaging\ntox\nunittest2\ntwisted",
true)
createPython("django110", "3.4.4", ["django==1.10", "django-nose"], "python3.4\ndjango\nskeletons\ndjango-nose")
createPython("django111", "3.4.4", ["django==1.11"], "python3.4\ndjango")
createPython("python34",
"3.4.4",
["ipython==2.1", "django==1.8", "behave", "jinja2", "tox>=2.0"],
"python3.4\npython3\nipython\nipython200\nskeletons\ndjango\nbehave\ntox\njinja2\npython34\npackaging",
true)
createPython("python36",
"3.6.1",
["django==1.9", "jinja2", "pandas"],
"python3.6\npython3\ndjango\njinja2\npython34\npython36\npandas",
true)
if (Os.isFamily(Os.FAMILY_UNIX)) {
createPython("pyqt_env", "2.7.13", [condaPackage("pyqt=5.6.0")], "pyqt5", false, true)
}
createPython("django_latest", "3.5.3", ["django"], "python3.5\ndjango", true)
}
task prepare (type: Delete) {
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") }
}