Skip to content

Commit

Permalink
fix: only reload modules that weren't already imported
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Dec 25, 2021
1 parent 03f78b1 commit 7ba93af
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion beet/toolchain/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def inject(self, cls: Any) -> Any:
@contextmanager
def activate(self):
"""Push the context directory to sys.path and handle cleanup to allow module reloading."""
already_loaded = set(sys.modules)

not_in_path = self._path_entry not in sys.path
if not_in_path:
sys.path.append(self._path_entry)
Expand All @@ -233,7 +235,8 @@ def activate(self):
imported_modules = [
name
for name, module in sys.modules.items()
if (filename := getattr(module, "__file__", None))
if name not in already_loaded
and (filename := getattr(module, "__file__", None))
and "site-packages" not in filename
and filename.startswith(self._path_entry)
]
Expand Down

0 comments on commit 7ba93af

Please sign in to comment.