load each addon only once but for real

This commit is contained in:
əlemi 2022-04-19 03:36:30 +02:00
parent 6d64973c54
commit 4da1a9f834
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -8,7 +8,7 @@ import inspect
from pathlib import Path from pathlib import Path
from importlib import import_module from importlib import import_module
from typing import List, Type, get_type_hints from typing import List, Type, Set, get_type_hints
from dataclasses import dataclass, MISSING, fields from dataclasses import dataclass, MISSING, fields
from setproctitle import setproctitle from setproctitle import setproctitle
@ -21,7 +21,7 @@ def main():
# TODO would be cool if it was possible to configure addons path, but we need to load addons before doing argparse so we can do helptext # TODO would be cool if it was possible to configure addons path, but we need to load addons before doing argparse so we can do helptext
# addon_path = Path(args.path) if args.addon_path else ( root/'addons' ) # addon_path = Path(args.path) if args.addon_path else ( root/'addons' )
addon_path = Path('addons') addon_path = Path('addons')
addons : List[Type[Addon]] = [] addons : Set[Type[Addon]] = set()
for path in sorted(addon_path.rglob('*.py')): for path in sorted(addon_path.rglob('*.py')):
py_path = str(path).replace('/', '.').replace('.py', '') py_path = str(path).replace('/', '.').replace('.py', '')
@ -29,8 +29,7 @@ def main():
for obj_name in vars(m).keys(): for obj_name in vars(m).keys():
obj = getattr(m, obj_name) obj = getattr(m, obj_name)
if obj != Addon and inspect.isclass(obj) and issubclass(obj, Addon): if obj != Addon and inspect.isclass(obj) and issubclass(obj, Addon):
addons.append(obj) addons.add(obj)
break
help_text = '\n\naddons:' help_text = '\n\naddons:'