-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for --extended-dry-run/-x (REVIEW) #1388
Changes from all commits
035b1c7
f93d7dd
d82c0b7
8038ac3
7f68850
0362ebb
7dec3ad
9b41c6b
b21c3ea
f363dd8
71f5f57
ffc690e
76013ae
59d6c1c
0ca792a
cfa3ba7
e88df4c
43ea50a
fd74353
20aeb74
b12aa84
5fe60b8
3ecb86a
67ccd6d
28f09c4
96d4a5e
62790db
3fb641b
6d53850
794b541
d6a3127
c8c4503
ebc65c6
246bbb0
2ed7ced
812c4fa
51bbf3f
b780041
aa72846
82e24d1
2917125
9066692
8c37cd7
65d0b0d
ef90cc3
b5d62e0
240f1b5
6719900
56c9cb5
a40a65d
7c88836
eb33717
7c57cf7
0f547ad
aec59ba
0664185
553ea66
ea713c0
cfc1574
6f1372c
cec8082
2256baa
07f1d71
4586c08
4c079b2
ee95ee1
6578d04
1bd4f64
efed3d7
6b798c8
5c7bd24
87da9c6
aac7b2e
59444af
81199ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,8 @@ | |
from vsc.utils import fancylogger | ||
from vsc.utils.missing import shell_quote | ||
|
||
from easybuild.tools.build_log import EasyBuildError | ||
from easybuild.tools.build_log import EasyBuildError, dry_run_msg | ||
from easybuild.tools.config import build_option | ||
|
||
|
||
# take copy of original environemt, so we can restore (parts of) it later | ||
|
@@ -79,10 +80,12 @@ def get_changes(): | |
return _changes | ||
|
||
|
||
def setvar(key, value): | ||
def setvar(key, value, verbose=True): | ||
""" | ||
put key in the environment with value | ||
tracks added keys until write_changes has been called | ||
|
||
@param verbose: include message in dry run output for defining this environment variable | ||
""" | ||
if key in os.environ: | ||
oldval_info = "previous value: '%s'" % os.environ[key] | ||
|
@@ -93,6 +96,12 @@ def setvar(key, value): | |
_changes[key] = value | ||
_log.info("Environment variable %s set to %s (%s)", key, value, oldval_info) | ||
|
||
if verbose and build_option('extended_dry_run'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the in some places, defining the environment variables is considered 'internal', i.e. it serves a purposes but is mostly irrelevant so shouldn't 'pollute' the dry run output example: all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll clarify this by updating the |
||
quoted_value = shell_quote(value) | ||
if quoted_value[0] not in ['"', "'"]: | ||
quoted_value = '"%s"' % quoted_value | ||
dry_run_msg(" export %s=%s" % (key, quoted_value), silent=build_option('silent')) | ||
|
||
|
||
def unset_env_vars(keys): | ||
""" | ||
|
@@ -139,7 +148,7 @@ def read_environment(env_vars, strict=False): | |
return result | ||
|
||
|
||
def modify_env(old, new): | ||
def modify_env(old, new, verbose=True): | ||
""" | ||
Compares 2 os.environ dumps. Adapts final environment. | ||
""" | ||
|
@@ -151,10 +160,10 @@ def modify_env(old, new): | |
## hmm, smart checking with debug logging | ||
if not new[key] == old[key]: | ||
_log.debug("Key in new environment found that is different from old one: %s (%s)" % (key, new[key])) | ||
setvar(key, new[key]) | ||
setvar(key, new[key], verbose=verbose) | ||
else: | ||
_log.debug("Key in new environment found that is not in old one: %s (%s)" % (key, new[key])) | ||
setvar(key, new[key]) | ||
setvar(key, new[key], verbose=verbose) | ||
|
||
for key in oldKeys: | ||
if not key in newKeys: | ||
|
@@ -167,4 +176,4 @@ def restore_env(env): | |
""" | ||
Restore active environment based on specified dictionary. | ||
""" | ||
modify_env(os.environ, env) | ||
modify_env(os.environ, env, verbose=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly style, returning somewhere 'deep' in the function results in code that's harder to read or understand at a glance (it's not immediately clear if there are other
return
s for example)