Skip to content

Commit 2f7ed86

Browse files
committed
update docs
1 parent db793f3 commit 2f7ed86

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
### 2.1.0 (2020-03-17)
12
* Add environment variables support (#8):
23
- Python object: `Python.environment` (single and map)
34
- Python task: `PythonTask.environment` (single and map)

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
5858
apply plugin: 'ru.vyarus.use-python'
@@ -62,7 +62,7 @@ OR
6262

6363
```groovy
6464
plugins {
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

7373
Gradle | Version
7474
--------|-------
75-
5-6 | 2.0.0
75+
5-6 | 2.1.0
7676
4.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
544544
To 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

686708
Also, 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

Comments
 (0)