Fix pre-emptive import bug introduced in container

This commit is contained in:
Griatch 2022-10-07 00:07:21 +02:00
parent a5f19e8b92
commit f9ba117680
2 changed files with 17 additions and 6 deletions

View file

@ -2,6 +2,13 @@
Contrib by Griatch 2022 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 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 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 that you follow the tutorial step by step and write your own code. But if

View file

@ -12,13 +12,14 @@ evennia.OPTION_CLASSES
from pickle import dumps 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 SCRIPTDB = None
_BASE_SCRIPT_TYPECLASS = None
class Container: class Container:
@ -106,7 +107,6 @@ class GlobalScriptContainer(Container):
callables from settings but a custom dict of tuples. callables from settings but a custom dict of tuples.
""" """
__BASE_SCRIPT_TYPECLASS = class_from_module(settings.BASE_SCRIPT_TYPECLASS)
def __init__(self): def __init__(self):
""" """
@ -201,13 +201,17 @@ class GlobalScriptContainer(Container):
initialized. 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: if self.typeclass_storage is None:
self.typeclass_storage = {} self.typeclass_storage = {}
for key, data in list(self.loaded_data.items()): for key, data in list(self.loaded_data.items()):
try: try:
typeclass = data.get("typeclass", settings.BASE_SCRIPT_TYPECLASS) typeclass = data.get("typeclass", settings.BASE_SCRIPT_TYPECLASS)
script_typeclass = class_from_module(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 self.typeclass_storage[key] = script_typeclass
except Exception: except Exception:
logger.log_trace( logger.log_trace(