Skip to content

Latest commit

 

History

History
162 lines (123 loc) · 5.68 KB

README.md

File metadata and controls

162 lines (123 loc) · 5.68 KB

Gradle use-python plugin

License CI Appveyor build status codecov

DOCUMENTATION: https://xvik.github.io/gradle-use-python-plugin/

About

Plugin does not install python and pip itself and use globally installed python (by default). It's easier to prepare python manually because python have good compatibility (from user perspective) and does not need to be updated often.

Also, plugin could run python inside docker container to avoid local python installation.

The only plugin intention is to simplify python usage from gradle. By default, plugin creates python virtualenv inside the project and installs all modules there so each project has its own python (copy) and could not be affected by other projects or system changes.

Features:

  • Works with directly installed python or docker container (with python)
  • Creates local (project-specific) virtualenv (project-specific python copy)
  • Installs required pip modules (virtualenv by default, but could be global installation)
  • Support requirements.txt file (limited by default)
  • Could be used as basement for building plugins for specific python modules (like mkdocs plugin)

Who's using (usage examples)

Summary
  • Configuration: python
  • Tasks:
    • checkPython - validate python installation (and create virtualenv if required)
    • cleanPython - clean created python environment
    • pipInstall - install declared pip modules
    • pipUpdates - show the latest available versions for the registered modules
    • pipList - show all installed modules (the same as pipInstall shows after installation)
    • type:PythonTask - call python command/script/module
    • type:PipInstallTask - may be used for custom pip modules installation workflow

Setup

Maven Central Gradle Plugin Portal

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'ru.vyarus:gradle-use-python-plugin:3.0.0'
    }
}
apply plugin: 'ru.vyarus.use-python'

OR

plugins {
    id 'ru.vyarus.use-python' version '3.0.0'
}

Compatibility

Plugin compiled for java 8, compatible with java 11. Supports python 2 and 3 on windows and linux (macos).

Gradle Version
5.3-8 3.0.0
5-5.2 2.3.0
4.x 1.2.0

Snapshots

Snapshots may be used through JitPack
  • Go to JitPack project page
  • Select Commits section and click Get it on commit you want to use or use master-SNAPSHOT to use the most recent snapshot

For gradle before 6.0 use buildscript block with required commit hash as version:

buildscript {
    repositories {
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'ru.vyarus:gradle-use-python-plugin:2450c7e881'
    }
}
apply plugin: 'ru.vyarus.use-python'

For gradle 6.0 and above:

  • Add to settings.gradle (top most!) with required commit hash as version:

    pluginManagement {
        resolutionStrategy {
            eachPlugin {
                if (requested.id.namespace == 'ru.vyarus.use-python') {
                    useModule('ru.vyarus:gradle-use-python-plugin:2450c7e881')
                }
            }
        }
        repositories {
            maven { url 'https://jitpack.io' }
            gradlePluginPortal()          
        }
    }    
  • Use plugin without declaring version:

    plugins {
        id 'ru.vyarus.use-python'
    }

Python & Pip

Make sure python and pip are installed:

python --version  
pip --version

On *nix python usually reference python2. For python3:

python3 --version  
pip3 --version

OR enable docker support to run python inside docker container

Usage

Read documentation

Might also like


gradle plugin generator