Skip to content

Commit bcf0d02

Browse files
committed
Oops, we were defaulting to preserving the entire environment!
1 parent a465d11 commit bcf0d02

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

cwltool/job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ def run(self,
442442

443443
env = self.environment
444444
vars_to_preserve = runtimeContext.preserve_environment
445-
if runtimeContext.preserve_entire_environment is not None:
445+
if runtimeContext.preserve_entire_environment is not False:
446446
vars_to_preserve = os.environ
447-
if vars_to_preserve is not None:
447+
if vars_to_preserve:
448448
for key, value in os.environ.items():
449449
if key in vars_to_preserve and key not in env:
450450
# On Windows, subprocess env can't handle unicode.

tests/env.cwl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cwlVersion: v1.0
2+
class: CommandLineTool
3+
inputs: []
4+
requirements:
5+
ShellCommandRequirement: {}
6+
baseCommand: echo
7+
arguments:
8+
- valueFrom: >
9+
{\\"env_count\\": \$(env | wc -l)}
10+
shellQuote: False
11+
stdout: cwl.output.json
12+
outputs:
13+
env_count: int

tests/test_examples.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,3 +931,12 @@ def test_optional_numeric_output_0():
931931
assert "completed success" in stderr
932932
assert error_code == 0
933933
assert json.loads(stdout)['out'] == 0
934+
935+
def test_env_filtering():
936+
test_file = "tests/env.cwl"
937+
error_code, stdout, stderr = get_main_output(
938+
[get_data(test_file)])
939+
940+
assert "completed success" in stderr
941+
assert error_code == 0
942+
assert json.loads(stdout)['env_count'] == 4

0 commit comments

Comments
 (0)