mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Update path cache when replacing plugins. Fixes #156
This commit is contained in:
parent
7532f4523a
commit
106905fd00
@ -93,10 +93,6 @@ class PluginLoader(BasePluginLoader, ABC):
|
||||
async def reload(self) -> type[PluginClass]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def unload(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def delete(self) -> None:
|
||||
pass
|
||||
|
@ -233,12 +233,17 @@ class ZippedPluginLoader(PluginLoader):
|
||||
return plugin
|
||||
|
||||
async def reload(self, new_path: str | None = None) -> type[PluginClass]:
|
||||
await self.unload()
|
||||
if new_path is not None:
|
||||
self._unload()
|
||||
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_cache[self.path] = self
|
||||
return await self.load(reset_cache=True)
|
||||
|
||||
async def unload(self) -> None:
|
||||
def _unload(self) -> None:
|
||||
for name, mod in list(sys.modules.items()):
|
||||
if (getattr(mod, "__file__", "") or "").startswith(self.path):
|
||||
del sys.modules[name]
|
||||
@ -246,7 +251,7 @@ class ZippedPluginLoader(PluginLoader):
|
||||
self.log.debug(f"Unloaded plugin {self.meta.id} at {self.path}")
|
||||
|
||||
async def delete(self) -> None:
|
||||
await self.unload()
|
||||
self._unload()
|
||||
try:
|
||||
del self.path_cache[self.path]
|
||||
except KeyError:
|
||||
|
Loading…
Reference in New Issue
Block a user