Add function to modify path-like environment variable in a context #4681
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The proposed function
wrap_path_env
would have the utility to allow running commands or functions with modified values forPATH
/LD_LIBRARY_PATH
/...The function allows to both append and prepend to a path-like environment variables, using by default the default system separator.
A custom separator can be specified for each variable by passing a dictionary of strings with the same keys as
prepend and append.
If a key is not present in the sep dictionary, os.pathsep will be used unless strict is True, then an error
will be raised.
Comparison to
env=
parameter inrun_shell_cmd
for 5.0.x:env
parameter on it's own can be cumbersome to use as it requires redefining the entire environment, which would entail copying the environment and modifying the environment variables to have the same effect as the proposed function.env
parameter would not work for other python function calls (eg testing a module that independently calls commands)Comparison with currently available
framework.environment
functions:reset_changes
to reset all variables modified bysetvar
but it is possible that the user has already set some variables and only want to temporarily modify only some of them or different ones, without resetting the originally set variables.Possible enhancements/discussions:
set
/override
parameter to override the value instead of just appending/prependingset
/override
paramenter) i am not sure if this should be implemented in a separate function.