environment : filter the current environment
Previously only the environment obtained after sourcing the file was filtered. This caused the appeareance of spurious unset commands in the list.
This commit is contained in:
parent
a17d1efe7c
commit
9e0c20c794
@ -297,16 +297,18 @@ def from_sourcing_files(*args, **kwargs):
|
|||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise RuntimeError('sourcing files returned a non-zero exit code')
|
raise RuntimeError('sourcing files returned a non-zero exit code')
|
||||||
output = ''.join([line for line in proc.stdout])
|
output = ''.join([line for line in proc.stdout])
|
||||||
# Construct a dictionary with all the variables in the environment
|
# Construct a dictionary with all the variables in the new environment
|
||||||
after_source_env = dict(json.loads(output))
|
after_source_env = dict(json.loads(output))
|
||||||
|
this_environment = dict(os.environ)
|
||||||
|
|
||||||
# Filter variables that are due to how we source
|
# Filter variables that are not related to sourcing a file
|
||||||
after_source_env.pop('SHLVL')
|
to_be_filtered = 'SHLVL', '_', 'PWD', 'OLDPWD'
|
||||||
after_source_env.pop('_')
|
for d in after_source_env, this_environment:
|
||||||
after_source_env.pop('PWD')
|
for name in to_be_filtered:
|
||||||
|
d.pop(name, None)
|
||||||
|
|
||||||
# Fill the EnvironmentModifications instance
|
# Fill the EnvironmentModifications instance
|
||||||
this_environment = dict(os.environ)
|
|
||||||
# New variables
|
# New variables
|
||||||
new_variables = set(after_source_env) - set(this_environment)
|
new_variables = set(after_source_env) - set(this_environment)
|
||||||
for x in new_variables:
|
for x in new_variables:
|
||||||
|
Loading…
Reference in New Issue
Block a user