This Gradle Plugin uses Miniconda
to run executables (python
, pip
, conda
etc.) from virtual env.
- Java JDK or JRE version 8 or higher
Running python scripts or projects by executing single tasks which will download and install Python virtual environment.
- Apply a plugin to a project as described on gradle portal.
- Configure a plugin by specifying desired python version in build script:
Possible properties in plugin extension are:
pythonPlugin { pythonVersion.set("3.8.2") }
pythonVersion
-> Python environment version, default3.8.5
minicondaVersion
-> Miniconda3 version, defaultlatest
- Define a task to run desired python script, for example to run
quicksort.py
script inmain
dir add the following task configuration to build script:tasks { register<VenvTask>("runQuickSort") { workingDir = projectDir.resolve("main") args = listOf("quicksort.py") } }
- Run python script from gradle:
# Linux ./gradlew runQuickSort # Windows gradlew.bat runQuickSort
Additional examples alongside with sample PipTasks configurations can be found in examples
module in this project.
- To have autocomplete and modules properly recognized in Intellij Idea simply point python executable as described in: https://www.jetbrains.com/help/idea/configuring-python-sdk.html
- To have properly recognized imported source modules in tests, right click on sources directory (for example
main
) ->Mark Direcotry as
->as Sources root
.
- Python common build problems: https://github.com/pyenv/pyenv/wiki/Common-build-problems
- in case of uninstalling venv from Windows, it can be necessary to run uninstall exec (downloaded in
build
directory) to fully uninstall python, deleting python venv dir could not be sufficient - in case of any problems with installation on Windows try reinstalling (uninstall by msi installer in
build
dir and then execute once againbuild_envs
task) - installing python on Linux can require installation of additional packages,
for example openssl, so before virtual envs installation run:
sudo apt-get install openssl