Update path cache when replacing plugins. Fixes #156
This commit is contained in:
parent
7532f4523a
commit
106905fd00
2 changed files with 9 additions and 8 deletions
|
@ -93,10 +93,6 @@ class PluginLoader(BasePluginLoader, ABC):
|
||||||
async def reload(self) -> type[PluginClass]:
|
async def reload(self) -> type[PluginClass]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def unload(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def delete(self) -> None:
|
async def delete(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -233,12 +233,17 @@ class ZippedPluginLoader(PluginLoader):
|
||||||
return plugin
|
return plugin
|
||||||
|
|
||||||
async def reload(self, new_path: str | None = None) -> type[PluginClass]:
|
async def reload(self, new_path: str | None = None) -> type[PluginClass]:
|
||||||
await self.unload()
|
self._unload()
|
||||||
if new_path is not None:
|
if new_path is not None and new_path != self.path:
|
||||||
|
try:
|
||||||
|
del self.path_cache[self.path]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
self.path = new_path
|
self.path = new_path
|
||||||
|
self.path_cache[self.path] = self
|
||||||
return await self.load(reset_cache=True)
|
return await self.load(reset_cache=True)
|
||||||
|
|
||||||
async def unload(self) -> None:
|
def _unload(self) -> None:
|
||||||
for name, mod in list(sys.modules.items()):
|
for name, mod in list(sys.modules.items()):
|
||||||
if (getattr(mod, "__file__", "") or "").startswith(self.path):
|
if (getattr(mod, "__file__", "") or "").startswith(self.path):
|
||||||
del sys.modules[name]
|
del sys.modules[name]
|
||||||
|
@ -246,7 +251,7 @@ class ZippedPluginLoader(PluginLoader):
|
||||||
self.log.debug(f"Unloaded plugin {self.meta.id} at {self.path}")
|
self.log.debug(f"Unloaded plugin {self.meta.id} at {self.path}")
|
||||||
|
|
||||||
async def delete(self) -> None:
|
async def delete(self) -> None:
|
||||||
await self.unload()
|
self._unload()
|
||||||
try:
|
try:
|
||||||
del self.path_cache[self.path]
|
del self.path_cache[self.path]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
Loading…
Reference in a new issue