| // 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" | |
| } | |
| /** | |
| * 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.16" | |
| String python36version = "3.6.8" | |
| String python37version = "3.7.6" | |
| String python38version = "3.8.1" | |
| 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 = 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) | |
| } | |
| 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 linkName = "python${version.split(/\./)[0..1].join(".")}" | |
| Closure createLinkClosure = { java.nio.file.Path link, java.nio.file.Path existing -> | |
| if (!link.toFile().exists()) Files.createLink(link, existing) | |
| } | |
| if (Os.isFamily(Os.FAMILY_UNIX) && !shouldUseCondaInterpreters) { | |
| createLinkClosure(Paths.get(pythonDirectory.toString(), linkName), | |
| Paths.get(pythonDirectory.toString(), "bin/$linkName")) | |
| } else if (Os.isFamily(Os.FAMILY_WINDOWS)) { | |
| 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"] + ( Os.isFamily(Os.FAMILY_WINDOWS) ? ['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, | |
| ["ipython==7.8", "django==2.2", "behave", "jinja2", "tox>=2.0", "nose", "pytest", "django-nose", "behave-django", | |
| "pytest-xdist", "untangle", "pandas"], | |
| "python3.8\npython3\nipython\nipython780\nskeletons\ndjango\nbehave\nbehave-django\ntox\njinja2\npython34\npackaging" + | |
| "\npytest\nnose\ndjango-nose\nbehave-django\ndjango2\nxdist\nuntangle\npandas", | |
| 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 (Os.isFamily(Os.FAMILY_UNIX)) { | |
| 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 { Os.isFamily(Os.FAMILY_WINDOWS) } | |
| 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") } | |
| } |