Skip to content

Commit

Permalink
fix(bash): exclude PWD environment variable from backup/restore (#142)
Browse files Browse the repository at this point in the history
Close #142
  • Loading branch information
Toilal committed Dec 30, 2020
1 parent 0348407 commit e8ee977
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddb/feature/shell/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def execute(self):
config_environ.update(config.env_additions)

to_encode_environ = dict(initial_environ)
self.shell.before_environ_backup(to_encode_environ)
os.environ.update(config_environ)
os.environ[_env_environ_backup] = encode_environ_backup(to_encode_environ)
os.environ[config.env_prefix + '_PROJECT_HOME'] = config.paths.project_home
Expand Down
11 changes: 11 additions & 0 deletions ddb/feature/shell/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def evaluate_script(self, script_filepath) -> Iterable[str]:
Get the command to evaluate the script inside the current shell context.
"""

def before_environ_backup(self, environ: Dict[str, str]):
"""
Alter environment variables before backup. This should be used to remove for saved environ variables that
should not be restored on deactivation.
"""

def header(self) -> Iterable[str]: # pylint:disable=no-self-use
"""
Returns header of script
Expand Down Expand Up @@ -100,6 +106,11 @@ def set_environment_variable(self, key, value):
def remove_environment_variable(self, key):
yield "unset " + self._sanitize_key(key)

def before_environ_backup(self, environ):
for key in ('PWD',):
if key in environ:
del environ['PWD']

def remove_all_binary_shims(self, shims_path: str):
shims = []

Expand Down

0 comments on commit e8ee977

Please sign in to comment.