Skip to content

Commit

Permalink
remove modules after sys.path has been changed
Browse files Browse the repository at this point in the history
to make sure we do not keep them during the update, see cruft#253
  • Loading branch information
Chilipp committed May 31, 2023
1 parent c9f678a commit 1f74151
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cruft/_commands/utils/iohelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ def __enter__(self):

def cleanup(self, cnt=0):
if self._extended_path:
name = str(Path(self.tmpdir.name) / self._directory)
if name in sys.path:
sys.path.remove(name)
dir_path = Path(self.tmpdir.name) / self._directory
dir_name = str(dir_path)
if dir_name in sys.path:
sys.path.remove(dir_name)
for name, mod in list(sys.modules.items()):
if getattr(mod, "__file__", None):
mod_path = Path(mod.__file__)
if dir_path < mod_path:
del sys.modules[name]
if cnt >= 5: # pragma: no cover
raise RuntimeError("Could not delete TemporaryDirectory!")
try:
Expand Down

0 comments on commit 1f74151

Please sign in to comment.