Now, all what is required to run python scripts is Java.
This Gradle Plugin uses Miniforge
to run executables (python
, pip
, conda
etc.) from virtual env.
Python project configuration can be fully automated by Gradle tasks.
miniforge is the community (conda-forge) driven and package installations thus come from conda-forge channel resolving licensing issues and keeping the entire use open in nature.
miniforge also has better arm64 and other architecture support.
miniforge has a dedicated pypy support. Will enhance this plugin to support pypy.
- 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.
Additional Python configuration (pip/conda packages installation etc.) can be done by defining Gradle tasks in build.gradle.kts
file.
-
Apply a plugin to a project as described on gradle portal.
-
Configure a plugin by specifying desired python version in build script:
pythonPlugin { pythonVersion.set("3.8.2") }
Possible properties in plugin extension are:
pythonVersion
-> Python environment version, default3.10.4
miniforgeVersion
-> Miniforge3 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
.
- It may be required to unset
PYTHONPATH
in system before running any tasks (https://stackoverflow.com/a/31841132)
This project is heavily inspired and is built on https://github.com/PrzemyslawSwiderski/python-gradle-plugin