@@ -52,7 +52,7 @@ buildscript {
5252 jcenter()
5353 }
5454 dependencies {
55- classpath 'ru.vyarus:gradle-use-python-plugin:2.0 .0'
55+ classpath 'ru.vyarus:gradle-use-python-plugin:2.1 .0'
5656 }
5757}
5858apply plugin: 'ru.vyarus.use-python'
6262
6363``` groovy
6464plugins {
65- id 'ru.vyarus.use-python' version '2.0 .0'
65+ id 'ru.vyarus.use-python' version '2.1 .0'
6666}
6767```
6868
@@ -72,7 +72,7 @@ Plugin compiled for java 8, compatible with java 11
7272
7373Gradle | Version
7474--------|-------
75- 5-6 | 2.0 .0
75+ 5-6 | 2.1 .0
76764.x | [ 1.2.0] ( https://github.com/xvik/gradle-use-python-plugin/tree/1.2.0 )
7777
7878#### Snapshots
@@ -544,6 +544,26 @@ When command passed as string it is manually parsed to arguments array (split by
544544To view parsed arguments run gradle with ` -i ` flag (enable info logs). In case when command can't be parsed properly
545545(bug in parser or unsupported case) use array of arguments instead of string.
546546
547+ ##### Environment variables
548+
549+ By default, executed python can access system environment variables (same as ` System.getenv() ` ).
550+
551+ To declare custom (process specific) variables:
552+
553+ ``` groovy
554+ task sample(type: PythonTask) {
555+ command = "-c \"import os;print('variables: '+os.getenv('some', 'null')+' '+os.getenv('foo', 'null'))\""
556+ environment 'some', 1
557+ environment 'other', 2
558+ environment(['foo': 'bar', 'baz': 'bag'])
559+ }
560+ ```
561+
562+ Map based declaration (` environment(['foo': 'bar', 'baz': 'bag']) ` ) does not remove previously declared variables
563+ (just add all vars from map), but direct assignment ` environment = ['foo': 'bar', 'baz': 'bag'] ` will reset variables.
564+
565+ System variables will be available even after declaring custom variables (of course, custom variables could override global value).
566+
547567#### Configuration
548568
549569##### Python location
@@ -682,11 +702,15 @@ PythonTask configuration:
682702| pythonArgs | Extra python arguments applied just after python binary. Useful for declaring common python options (-I, -S, etc.) |
683703| extraArgs | Extra arguments applied at the end of declared command (usually module arguments). Useful for derived tasks to declare default options |
684704| outputPrefix | Prefix, applied for each line of python output. By default is '\t' to identify output for called gradle command |
705+ | environment | Process specific environment variables |
706+
685707
686708Also, task provide extra methods:
687709
688710* ` pythonArgs(String... args) ` to declare extra python arguments (shortcut to append values to pythonArgs property).
689711* ` extraArgs(String... args) ` to declare extra arguments (shortcut to append values to extraArgs property).
712+ * ` environment(String var, Object value) ` to set custom environment variable (shortcut to append values to environment property)
713+ * ` environment(Map<String, Object> vars) ` to set multiple custom environment variables at once (shortcut to append values to environment property)
690714
691715#### PipInstallTask
692716
0 commit comments