Preliminary support for a "all effects" module to help with import times hopefully
This commit is contained in:
@@ -25,6 +25,7 @@ import eos.db
|
||||
from .eqBase import EqBase
|
||||
from eos.saveddata.price import Price as types_Price
|
||||
from collections import OrderedDict
|
||||
import importlib
|
||||
|
||||
|
||||
from logbook import Logger
|
||||
@@ -156,9 +157,19 @@ class Effect(EqBase):
|
||||
Grab the handler, type and runTime from the effect code if it exists,
|
||||
if it doesn't, set dummy values and add a dummy handler
|
||||
"""
|
||||
|
||||
try:
|
||||
self.__effectModule = effectModule = __import__('eos.effects.' + self.handlerName, fromlist=True)
|
||||
import eos.effects.all as all
|
||||
func = getattr(all, self.handlerName)
|
||||
self.__effectModule = effectModule = func()
|
||||
self.__handler = getattr(effectModule, "handler", effectDummy)
|
||||
self.__runTime = getattr(effectModule, "runTime", "normal")
|
||||
self.__activeByDefault = getattr(effectModule, "activeByDefault", True)
|
||||
t = getattr(effectModule, "type", None)
|
||||
|
||||
t = t if isinstance(t, tuple) or t is None else (t,)
|
||||
self.__type = t
|
||||
except ImportError as e:
|
||||
self.__effectModule = effectModule = importlib.import_module('eos.effects.' + self.handlerName)
|
||||
self.__handler = getattr(effectModule, "handler", effectDummy)
|
||||
self.__runTime = getattr(effectModule, "runTime", "normal")
|
||||
self.__activeByDefault = getattr(effectModule, "activeByDefault", True)
|
||||
|
||||
24
scripts/effect_rollup.py
Normal file
24
scripts/effect_rollup.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
import os.path
|
||||
|
||||
new_effect_file_contents = ""
|
||||
|
||||
for filename in os.listdir(os.path.join('eos', 'effects')):
|
||||
if filename.startswith("_") or not filename.endswith(".py") or filename == 'all.py':
|
||||
continue
|
||||
|
||||
new_effect_file_contents += f"def {os.path.splitext(filename)[0]}():\n"
|
||||
|
||||
file = open(os.path.join('eos', 'effects', filename), "r")
|
||||
|
||||
for line in file:
|
||||
if line.strip().startswith("#") or line.strip() == "":
|
||||
continue
|
||||
new_effect_file_contents += f" {line}"
|
||||
|
||||
new_effect_file_contents += "\n return locals()\n\n"
|
||||
|
||||
with open(os.path.join('eos', 'effects', 'all.py'), "w") as f:
|
||||
f.write(new_effect_file_contents)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user