Skip to content

Commit

Permalink
PyPlugin bugfix: load_all should only load classes which subclass PyP…
Browse files Browse the repository at this point in the history
…lugin
  • Loading branch information
AndrewFasano committed Nov 16, 2021
1 parent 62ce70f commit 713ebc3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions panda/python/core/pandare/pypluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,14 @@ def load_all(self, plugin_file, args=None, template_dir=None):
all classes that subclass PyPlugin and passing them to self.load()
'''
import inspect, importlib
spec = importlib.util.spec_from_file_location("snake_hook", plugin_file)
spec = importlib.util.spec_from_file_location("plugin_file", plugin_file)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

for name, cls in inspect.getmembers(module, lambda x: inspect.isclass(x) and x.__module__ == "snake_hook"): # matches module set above
for name, cls in inspect.getmembers(module, lambda x: inspect.isclass(x)):
if not issubclass(cls, PyPlugin):
continue
cls.__name__ = name
self.load(cls, args, template_dir)

def unload(self, pluginclass, do_del=True):
Expand All @@ -226,8 +229,8 @@ def unload(self, pluginclass, do_del=True):
del self.plugins[name]

def unload_all(self):
for instance in self.plugins.values():
self.unload(instance, do_del=False)
for name in self.plugins.keys():
self.unload(name, do_del=False)
self.plugins.clear()

def is_loaded(self, pluginclass):
Expand Down

0 comments on commit 713ebc3

Please sign in to comment.