@@ -52,7 +52,7 @@ buildscript {
52
52
jcenter()
53
53
}
54
54
dependencies {
55
- classpath 'ru.vyarus:gradle-use-python-plugin:2.0 .0'
55
+ classpath 'ru.vyarus:gradle-use-python-plugin:2.1 .0'
56
56
}
57
57
}
58
58
apply plugin: 'ru.vyarus.use-python'
62
62
63
63
``` groovy
64
64
plugins {
65
- id 'ru.vyarus.use-python' version '2.0 .0'
65
+ id 'ru.vyarus.use-python' version '2.1 .0'
66
66
}
67
67
```
68
68
@@ -72,7 +72,7 @@ Plugin compiled for java 8, compatible with java 11
72
72
73
73
Gradle | Version
74
74
--------|-------
75
- 5-6 | 2.0 .0
75
+ 5-6 | 2.1 .0
76
76
4.x | [ 1.2.0] ( https://github.com/xvik/gradle-use-python-plugin/tree/1.2.0 )
77
77
78
78
#### Snapshots
@@ -544,6 +544,26 @@ When command passed as string it is manually parsed to arguments array (split by
544
544
To view parsed arguments run gradle with ` -i ` flag (enable info logs). In case when command can't be parsed properly
545
545
(bug in parser or unsupported case) use array of arguments instead of string.
546
546
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
+
547
567
#### Configuration
548
568
549
569
##### Python location
@@ -682,11 +702,15 @@ PythonTask configuration:
682
702
| pythonArgs | Extra python arguments applied just after python binary. Useful for declaring common python options (-I, -S, etc.) |
683
703
| extraArgs | Extra arguments applied at the end of declared command (usually module arguments). Useful for derived tasks to declare default options |
684
704
| 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
+
685
707
686
708
Also, task provide extra methods:
687
709
688
710
* ` pythonArgs(String... args) ` to declare extra python arguments (shortcut to append values to pythonArgs property).
689
711
* ` 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)
690
714
691
715
#### PipInstallTask
692
716
0 commit comments