Skip to content

Commit 7d41446

Browse files
committed
Original get_changes would not report unset variables
1 parent 346cefc commit 7d41446

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

easybuild/tools/environment.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def write_changes(filename):
7777
"""
7878
try:
7979
with open(filename, 'w') as script:
80-
for key, changed_value in get_context().items():
80+
for key, changed_value in get_changes().items():
8181
script.write('export %s=%s\n' % (key, shell_quote(changed_value)))
8282
except IOError as err:
8383
raise EasyBuildError("Failed to write to %s: %s", filename, err)
@@ -91,11 +91,14 @@ def reset_changes():
9191
get_context().clear()
9292

9393

94-
def get_changes():
94+
def get_changes(show_unset=False):
9595
"""
9696
Return tracked changes made in environment.
9797
"""
98-
return get_context()
98+
changes = get_context()
99+
if not show_unset:
100+
return {k: v for k, v in changes.items() if v is not None}
101+
return changes.copy()
99102

100103

101104
def apply_context(context=None):
@@ -127,14 +130,13 @@ def getvar(key, default='', strict=False):
127130
if val is None:
128131
if strict:
129132
raise KeyError(f"Key '{key}' is explicitly unset in the current context")
130-
else:
131-
return default
133+
return default
132134
return val
133135
else:
134136
if strict:
135-
return os._real_os.environ[key]
137+
return ORIG_OS_ENVIRON[key]
136138
else:
137-
return os._real_os.environ.get(key, default)
139+
return ORIG_OS_ENVIRON.get(key, default)
138140

139141

140142
@contextmanager

0 commit comments

Comments
 (0)