Make evennia doc-build not require gamedir

This commit is contained in:
Griatch 2021-02-25 08:52:52 +01:00
parent 76d087ffb0
commit 2227f16e17
4 changed files with 46 additions and 28 deletions

View file

@ -176,28 +176,18 @@ ansi_clean = None
if not _no_autodoc:
# we must set up Evennia and its paths for autodocs to work
EV_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # os.environ.get("EVDIR")
GAME_DIR = os.environ.get("EVGAMEDIR")
EV_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if not (EV_ROOT and GAME_DIR):
err = (
"The EVDIR and EVGAMEDIR environment variables must be set to "
"the absolute paths to the evennia/ repo and an initialized "
"evennia gamedir respectively."
)
raise RuntimeError(err)
print("Evennia root: {}, Game dir: {}, branch:".format(EV_ROOT, GAME_DIR)),
print(f"Evennia root: {EV_ROOT}, branch:")
import subprocess
subprocess.call(["git", "rev-parse", "--abbrev-ref", "HEAD"])
subprocess.call("pwd")
sys.path.insert(1, EV_ROOT)
sys.path.insert(1, GAME_DIR)
with cd(GAME_DIR):
with cd(EV_ROOT):
# set up Evennia so its sources can be parsed
os.environ["DJANGO_SETTINGS_MODULE"] = "server.conf.settings"
os.environ["DJANGO_SETTINGS_MODULE"] = "evennia.settings_default"
import django # noqa

View file

@ -27,6 +27,7 @@ import importlib
evennia._init()
from django.db import connection
from django.db.utils import OperationalError
from django.conf import settings
from evennia.accounts.models import AccountDB
@ -174,7 +175,7 @@ def _server_maintenance():
# ------------------------------------------------------------
class Evennia(object):
class Evennia:
"""
The main Evennia server handler. This object sets up the database and
@ -205,7 +206,10 @@ class Evennia(object):
self.start_time = time.time()
# initialize channelhandler
channelhandler.CHANNELHANDLER.update()
try:
channelhandler.CHANNELHANDLER.update()
except OperationalError:
print("channelhandler couldn't update - db not set up")
# wrap the SIGINT handler to make sure we empty the threadpool
# even when we reload and we have long-running requests in queue.
@ -616,7 +620,11 @@ class Evennia(object):
# Tell the system the server is starting up; some things are not available yet
ServerConfig.objects.conf("server_starting_mode", True)
try:
ServerConfig.objects.conf("server_starting_mode", True)
except OperationalError:
print("Server server_starting_mode couldn't be set - database not set up.")
# twistd requires us to define the variable 'application' so it knows
# what to execute from.
@ -728,4 +736,7 @@ for plugin_module in SERVER_SERVICES_PLUGIN_MODULES:
print(f"Could not load plugin module {plugin_module}")
# clear server startup mode
ServerConfig.objects.conf("server_starting_mode", delete=True)
try:
ServerConfig.objects.conf("server_starting_mode", delete=True)
except OperationalError:
print("Server server_starting_mode couldn't unset - db not set up.")

View file

@ -10,6 +10,7 @@ import time
from calendar import monthrange
from datetime import datetime, timedelta
from django.db.utils import OperationalError
from django.conf import settings
from evennia import DefaultScript
from evennia.server.models import ServerConfig
@ -23,7 +24,12 @@ IGNORE_DOWNTIMES = settings.TIME_IGNORE_DOWNTIMES
# Only set if gametime_reset was called at some point.
GAME_TIME_OFFSET = ServerConfig.objects.conf("gametime_offset", default=0)
try:
GAME_TIME_OFFSET = ServerConfig.objects.conf("gametime_offset", default=0)
except OperationalError:
# the db is not initialized
print("Gametime offset could not load - db not set up.")
GAME_TIME_OFFSET = 0
# Common real-life time measure, in seconds.
# You should not change this.

View file

@ -26,6 +26,7 @@ Example: To reach the search method 'get_object_with_account'
# Import the manager methods to be wrapped
from django.db.utils import OperationalError
from django.contrib.contenttypes.models import ContentType
# limit symbol import from API
@ -44,13 +45,23 @@ __all__ = (
# import objects this way to avoid circular import problems
ObjectDB = ContentType.objects.get(app_label="objects", model="objectdb").model_class()
AccountDB = ContentType.objects.get(app_label="accounts", model="accountdb").model_class()
ScriptDB = ContentType.objects.get(app_label="scripts", model="scriptdb").model_class()
Msg = ContentType.objects.get(app_label="comms", model="msg").model_class()
Channel = ContentType.objects.get(app_label="comms", model="channeldb").model_class()
HelpEntry = ContentType.objects.get(app_label="help", model="helpentry").model_class()
Tag = ContentType.objects.get(app_label="typeclasses", model="tag").model_class()
try:
ObjectDB = ContentType.objects.get(app_label="objects", model="objectdb").model_class()
AccountDB = ContentType.objects.get(app_label="accounts", model="accountdb").model_class()
ScriptDB = ContentType.objects.get(app_label="scripts", model="scriptdb").model_class()
Msg = ContentType.objects.get(app_label="comms", model="msg").model_class()
ChannelDB = ContentType.objects.get(app_label="comms", model="channeldb").model_class()
HelpEntry = ContentType.objects.get(app_label="help", model="helpentry").model_class()
Tag = ContentType.objects.get(app_label="typeclasses", model="tag").model_class()
except OperationalError:
# this is a fallback used during tests/doc building
print("Couldn't initialize search managers - db not set up.")
from evennia.objects.models import ObjectDB
from evennia.accounts.models import AccountDB
from evennia.scripts.models import ScriptDB
from evennia.comms.models import Msg, ChannelDB
from evennia.help.models import HelpEntry
from evennia.typeclasses.tags import Tag
# -------------------------------------------------------------------
@ -171,7 +182,7 @@ messages = search_messages
# exact - requires an exact ostring match (not case sensitive)
#
search_channel = Channel.objects.channel_search
search_channel = ChannelDB.objects.channel_search
search_channels = search_channel
channel_search = search_channel
channels = search_channels
@ -347,7 +358,7 @@ def search_channel_tag(key=None, category=None, tagtype=None, **kwargs):
matches were found.
"""
return Channel.objects.get_by_tag(key=key, category=category, tagtype=tagtype, **kwargs)
return ChannelDB.objects.get_by_tag(key=key, category=category, tagtype=tagtype, **kwargs)
# search for tag objects (not the objects they are attached to