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:
alalazo 2016-06-18 13:39:08 +02:00
parent a17d1efe7c
commit 9e0c20c794

View File

@ -297,16 +297,18 @@ def from_sourcing_files(*args, **kwargs):
if proc.returncode != 0:
raise RuntimeError('sourcing files returned a non-zero exit code')
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))
this_environment = dict(os.environ)
# Filter variables that are due to how we source
after_source_env.pop('SHLVL')
after_source_env.pop('_')
after_source_env.pop('PWD')
# Filter variables that are not related to sourcing a file
to_be_filtered = 'SHLVL', '_', 'PWD', 'OLDPWD'
for d in after_source_env, this_environment:
for name in to_be_filtered:
d.pop(name, None)
# Fill the EnvironmentModifications instance
this_environment = dict(os.environ)
# New variables
new_variables = set(after_source_env) - set(this_environment)
for x in new_variables: