From f9ba11768097bcfa751aa8fb705a647cb01c9532 Mon Sep 17 00:00:00 2001 From: Griatch Date: Fri, 7 Oct 2022 00:07:21 +0200 Subject: [PATCH] Fix pre-emptive import bug introduced in container --- evennia/contrib/tutorials/evadventure/README.md | 7 +++++++ evennia/utils/containers.py | 16 ++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/evennia/contrib/tutorials/evadventure/README.md b/evennia/contrib/tutorials/evadventure/README.md index 6e308c37d6..d500ea836d 100644 --- a/evennia/contrib/tutorials/evadventure/README.md +++ b/evennia/contrib/tutorials/evadventure/README.md @@ -2,6 +2,13 @@ Contrib by Griatch 2022 + +```{warning} +NOTE - this tutorial is WIP and NOT complete! It was put on hold to focus on +releasing Evennia 1.0. You will still learn things from it, but don't expect +perfection. +``` + A complete example MUD using Evennia. This is the final result of what is implemented if you follow the Getting-Started tutorial. It's recommended that you follow the tutorial step by step and write your own code. But if diff --git a/evennia/utils/containers.py b/evennia/utils/containers.py index a94a92454b..fbce2a3299 100644 --- a/evennia/utils/containers.py +++ b/evennia/utils/containers.py @@ -12,13 +12,14 @@ evennia.OPTION_CLASSES from pickle import dumps -from django.db.utils import OperationalError, ProgrammingError -from django.conf import settings -from evennia.utils.utils import class_from_module, callables_from_module -from evennia.utils import logger +from django.conf import settings +from django.db.utils import OperationalError, ProgrammingError +from evennia.utils import logger +from evennia.utils.utils import callables_from_module, class_from_module SCRIPTDB = None +_BASE_SCRIPT_TYPECLASS = None class Container: @@ -106,7 +107,6 @@ class GlobalScriptContainer(Container): callables from settings but a custom dict of tuples. """ - __BASE_SCRIPT_TYPECLASS = class_from_module(settings.BASE_SCRIPT_TYPECLASS) def __init__(self): """ @@ -201,13 +201,17 @@ class GlobalScriptContainer(Container): initialized. """ + global _BASE_SCRIPT_TYPECLASS + if not _BASE_SCRIPT_TYPECLASS: + _BASE_SCRIPT_TYPECLASS = class_from_module(settings.BASE_SCRIPT_TYPECLASS) + if self.typeclass_storage is None: self.typeclass_storage = {} for key, data in list(self.loaded_data.items()): try: typeclass = data.get("typeclass", settings.BASE_SCRIPT_TYPECLASS) script_typeclass = class_from_module(typeclass) - assert issubclass(script_typeclass, self.__BASE_SCRIPT_TYPECLASS) + assert issubclass(script_typeclass, _BASE_SCRIPT_TYPECLASS) self.typeclass_storage[key] = script_typeclass except Exception: logger.log_trace(