Delay import of module-prototypes to avoid init-clash. Resolves #2232.

This commit is contained in:
Griatch 2020-11-12 22:28:14 +01:00
parent e4b1e1c9aa
commit 3bee981cff
2 changed files with 40 additions and 30 deletions

View file

@ -392,8 +392,12 @@ def _init():
BASE_GUEST_TYPECLASS = class_from_module(settings.BASE_GUEST_TYPECLASS) BASE_GUEST_TYPECLASS = class_from_module(settings.BASE_GUEST_TYPECLASS)
del class_from_module del class_from_module
# delayed starts # delayed starts - important so as to not back-access evennia before it has
# finished initializing
GLOBAL_SCRIPTS.start() GLOBAL_SCRIPTS.start()
from .prototypes import prototypes
prototypes.load_module_prototypes()
del prototypes
def set_trace(term_size=(140, 80), debugger="auto"): def set_trace(term_size=(140, 80), debugger="auto"):

View file

@ -144,35 +144,41 @@ def homogenize_prototype(prototype, custom_keys=None):
# module-based prototypes # module-based prototypes
for mod in settings.PROTOTYPE_MODULES: def load_module_prototypes():
# to remove a default prototype, override it with an empty dict. """
# internally we store as (key, desc, locks, tags, prototype_dict) This is called by `evennia.__init__` as Evennia initializes. It's important
prots = [] to do this late so as to not interfere with evennia initialization.
for variable_name, prot in all_from_module(mod).items():
if isinstance(prot, dict): """
if "prototype_key" not in prot: for mod in settings.PROTOTYPE_MODULES:
prot["prototype_key"] = variable_name.lower() # to remove a default prototype, override it with an empty dict.
prots.append((prot["prototype_key"], homogenize_prototype(prot))) # internally we store as (key, desc, locks, tags, prototype_dict)
# assign module path to each prototype_key for easy reference prots = []
_MODULE_PROTOTYPE_MODULES.update({prototype_key.lower(): mod for prototype_key, _ in prots}) for variable_name, prot in all_from_module(mod).items():
# make sure the prototype contains all meta info if isinstance(prot, dict):
for prototype_key, prot in prots: if "prototype_key" not in prot:
actual_prot_key = prot.get("prototype_key", prototype_key).lower() prot["prototype_key"] = variable_name.lower()
prot.update( prots.append((prot["prototype_key"], homogenize_prototype(prot)))
{ # assign module path to each prototype_key for easy reference
"prototype_key": actual_prot_key, _MODULE_PROTOTYPE_MODULES.update({prototype_key.lower(): mod for prototype_key, _ in prots})
"prototype_desc": prot["prototype_desc"] if "prototype_desc" in prot else mod, # make sure the prototype contains all meta info
"prototype_locks": ( for prototype_key, prot in prots:
prot["prototype_locks"] actual_prot_key = prot.get("prototype_key", prototype_key).lower()
if "prototype_locks" in prot prot.update(
else "use:all();edit:false()" {
), "prototype_key": actual_prot_key,
"prototype_tags": list( "prototype_desc": prot["prototype_desc"] if "prototype_desc" in prot else mod,
set(list(make_iter(prot.get("prototype_tags", []))) + ["module"]) "prototype_locks": (
), prot["prototype_locks"]
} if "prototype_locks" in prot
) else "use:all();edit:false()"
_MODULE_PROTOTYPES[actual_prot_key] = prot ),
"prototype_tags": list(
set(list(make_iter(prot.get("prototype_tags", []))) + ["module"])
),
}
)
_MODULE_PROTOTYPES[actual_prot_key] = prot
# Db-based prototypes # Db-based prototypes