Run black. Resolve circular import issues in components contrib.
This commit is contained in:
parent
577f66c3ec
commit
e5d07603ca
49 changed files with 202 additions and 122 deletions
|
|
@ -126,6 +126,7 @@ from inspect import getfullargspec
|
|||
from textwrap import dedent
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from evennia import CmdSet, Command
|
||||
from evennia.commands import cmdhandler
|
||||
from evennia.utils.ansi import strip_ansi
|
||||
|
|
|
|||
|
|
@ -7,16 +7,8 @@ This helps writing isolated code and reusing it over multiple objects.
|
|||
|
||||
See the docs for more information.
|
||||
"""
|
||||
from evennia.contrib.base_systems.components import exceptions
|
||||
from evennia.contrib.base_systems.components.listing import COMPONENT_LISTING, get_component_class
|
||||
from evennia.contrib.base_systems.components.component import Component
|
||||
from evennia.contrib.base_systems.components.dbfield import (
|
||||
DBField,
|
||||
NDBField,
|
||||
TagField
|
||||
)
|
||||
|
||||
from evennia.contrib.base_systems.components.holder import (
|
||||
ComponentHolderMixin,
|
||||
ComponentProperty,
|
||||
)
|
||||
from . import exceptions # noqa
|
||||
from .component import Component # noqa
|
||||
from .dbfield import DBField, NDBField, TagField # noqa
|
||||
from .holder import ComponentHolderMixin, ComponentProperty # noqa
|
||||
from .listing import COMPONENT_LISTING, get_component_class # noqa
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ This file contains the base class to inherit for creating new components.
|
|||
"""
|
||||
|
||||
from evennia.commands.cmdset import CmdSet
|
||||
from evennia.contrib.base_systems.components import COMPONENT_LISTING, exceptions
|
||||
|
||||
from . import exceptions
|
||||
from .listing import COMPONENT_LISTING
|
||||
|
||||
|
||||
class BaseComponent(type):
|
||||
|
|
@ -13,6 +15,7 @@ class BaseComponent(type):
|
|||
This is the metaclass for components,
|
||||
responsible for registering components to the listing.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def __new__(cls, *args):
|
||||
"""
|
||||
|
|
@ -45,7 +48,7 @@ class Component(metaclass=BaseComponent):
|
|||
Each Component must supply the name, it is used as a slot name but also part of the attribute key.
|
||||
"""
|
||||
|
||||
__slots__ = ('host',)
|
||||
__slots__ = ("host",)
|
||||
|
||||
name = ""
|
||||
slot = None
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import typing
|
|||
from evennia.typeclasses.attributes import AttributeProperty, NAttributeProperty
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from evennia.contrib.base_systems.components import Component
|
||||
from .components import Component
|
||||
|
||||
|
||||
class DBField(AttributeProperty):
|
||||
|
|
@ -21,7 +21,7 @@ class DBField(AttributeProperty):
|
|||
def __init__(self, default=None, autocreate=False, **kwargs):
|
||||
super().__init__(default=default, autocreate=autocreate, **kwargs)
|
||||
|
||||
def __set_name__(self, owner: 'Component', name):
|
||||
def __set_name__(self, owner: "Component", name):
|
||||
"""
|
||||
Called when descriptor is first assigned to the class.
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ class NDBField(NAttributeProperty):
|
|||
It uses NAttributeProperty under the hood but prefixes the key with the component name.
|
||||
"""
|
||||
|
||||
def __set_name__(self, owner: 'Component', name):
|
||||
def __set_name__(self, owner: "Component", name):
|
||||
"""
|
||||
Called when descriptor is first assigned to the class.
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ class TagField:
|
|||
self._default = default
|
||||
self._enforce_single = enforce_single
|
||||
|
||||
def __set_name__(self, owner: 'Component', name):
|
||||
def __set_name__(self, owner: "Component", name):
|
||||
"""
|
||||
Called when TagField is first assigned to the class.
|
||||
It is called with the component class and the name of the field.
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ Components - ChrisLR 2022
|
|||
This file contains the classes that allow a typeclass to use components.
|
||||
"""
|
||||
|
||||
from evennia.contrib.base_systems import components
|
||||
from evennia.contrib.base_systems.components import signals, exceptions, get_component_class
|
||||
from . import exceptions, signals
|
||||
from .component import Component
|
||||
from .listing import get_component_class
|
||||
|
||||
|
||||
class ComponentProperty:
|
||||
|
|
@ -62,7 +63,7 @@ class ComponentHandler:
|
|||
self.host = host
|
||||
self._loaded_components = {}
|
||||
|
||||
def add(self, component: components.Component):
|
||||
def add(self, component: Component):
|
||||
"""
|
||||
Method to add a Component to a host.
|
||||
It caches the loaded component and appends its name to the host's component name list.
|
||||
|
|
@ -92,11 +93,11 @@ class ComponentHandler:
|
|||
name (str): The name of the component class to add.
|
||||
|
||||
"""
|
||||
component_class = components.get_component_class(name)
|
||||
component_class = get_component_class(name)
|
||||
component_instance = component_class.default_create(self.host)
|
||||
self.add(component_instance)
|
||||
|
||||
def remove(self, component: components.Component):
|
||||
def remove(self, component: Component):
|
||||
"""
|
||||
Method to remove a component instance from a host.
|
||||
It removes the component from the cache and listing.
|
||||
|
|
@ -109,9 +110,7 @@ class ComponentHandler:
|
|||
name = component.name
|
||||
slot_name = component.get_component_slot()
|
||||
if not self.has(slot_name):
|
||||
message = (
|
||||
f"Cannot remove {name} from {self.host.name} as it is not registered."
|
||||
)
|
||||
message = f"Cannot remove {name} from {self.host.name} as it is not registered."
|
||||
raise exceptions.ComponentIsNotRegistered(message)
|
||||
|
||||
for field in component.get_fields():
|
||||
|
|
@ -142,7 +141,7 @@ class ComponentHandler:
|
|||
|
||||
self.remove(instance)
|
||||
|
||||
def get(self, name: str) -> components.Component | None:
|
||||
def get(self, name: str) -> Component | None:
|
||||
return self._loaded_components.get(name)
|
||||
|
||||
def has(self, name: str) -> bool:
|
||||
|
|
@ -167,7 +166,7 @@ class ComponentHandler:
|
|||
return
|
||||
|
||||
for component_name in component_names:
|
||||
component = components.get_component_class(component_name)
|
||||
component = get_component_class(component_name)
|
||||
if component:
|
||||
component_instance = component.load(self.host)
|
||||
self._set_component(component_instance)
|
||||
|
|
@ -213,6 +212,7 @@ class ComponentHolderMixin:
|
|||
All registered components are initialized on the typeclass.
|
||||
They will be of None value if not present in the class components or runtime components.
|
||||
"""
|
||||
|
||||
def at_init(self):
|
||||
"""
|
||||
Method that initializes the ComponentHandler.
|
||||
|
|
@ -241,7 +241,7 @@ class ComponentHolderMixin:
|
|||
setattr(self, "_signal_handler", signals.SignalsHandler(self))
|
||||
class_components = self._get_class_components()
|
||||
for component_name, values in class_components:
|
||||
component_class = components.get_component_class(component_name)
|
||||
component_class = get_component_class(component_name)
|
||||
component = component_class.create(self, **values)
|
||||
self.components.add(component)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from evennia.contrib.base_systems.components import exceptions
|
||||
from . import exceptions
|
||||
|
||||
COMPONENT_LISTING = {}
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ def get_component_class(name):
|
|||
if component_class is None:
|
||||
message = (
|
||||
f"Component with name {name} has not been found. "
|
||||
f"Make sure it has been imported before being used."
|
||||
"Make sure it has been imported before being used."
|
||||
)
|
||||
raise exceptions.ComponentDoesNotExist(message)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,13 @@
|
|||
from evennia.contrib.base_systems.components import (
|
||||
Component,
|
||||
DBField,
|
||||
TagField,
|
||||
signals,
|
||||
)
|
||||
from evennia.contrib.base_systems.components.holder import (
|
||||
ComponentHolderMixin,
|
||||
ComponentProperty,
|
||||
)
|
||||
from evennia.contrib.base_systems.components.signals import as_listener
|
||||
from evennia.objects.objects import DefaultCharacter
|
||||
from evennia.utils import create
|
||||
from evennia.utils.test_resources import BaseEvenniaTest, EvenniaTest
|
||||
|
||||
from . import signals
|
||||
from .component import Component
|
||||
from .dbfield import DBField, TagField
|
||||
from .holder import ComponentHolderMixin, ComponentProperty
|
||||
from .signals import as_listener
|
||||
|
||||
|
||||
class ComponentTestA(Component):
|
||||
name = "test_a"
|
||||
|
|
@ -22,12 +17,12 @@ class ComponentTestA(Component):
|
|||
|
||||
class ShadowedComponentTestA(ComponentTestA):
|
||||
name = "shadowed_test_a"
|
||||
slot = 'ic_a'
|
||||
slot = "ic_a"
|
||||
|
||||
|
||||
class InheritedComponentTestA(ComponentTestA):
|
||||
name = "inherited_test_a"
|
||||
slot = 'ic_a'
|
||||
slot = "ic_a"
|
||||
|
||||
my_other_int = DBField(default=2)
|
||||
|
||||
|
|
@ -68,7 +63,7 @@ class ShadowedCharacterMixin:
|
|||
|
||||
class CharacterMixinWithComponents:
|
||||
ic_a = ComponentProperty("inherited_test_a", my_other_int=33)
|
||||
test_d = ComponentProperty('test_d')
|
||||
test_d = ComponentProperty("test_d")
|
||||
|
||||
|
||||
class CharacterWithComponents(
|
||||
|
|
@ -247,9 +242,13 @@ class TestComponents(EvenniaTest):
|
|||
test_b = self.char1.components.get("test_b")
|
||||
test_b.default_single_tag = "second value"
|
||||
|
||||
self.assertTrue(self.char1.tags.has(key="second value", category="test_b::default_single_tag"))
|
||||
self.assertTrue(
|
||||
self.char1.tags.has(key="second value", category="test_b::default_single_tag")
|
||||
)
|
||||
self.assertTrue(test_b.default_single_tag == "second value")
|
||||
self.assertFalse(self.char1.tags.has(key="first_value", category="test_b::default_single_tag"))
|
||||
self.assertFalse(
|
||||
self.char1.tags.has(key="first_value", category="test_b::default_single_tag")
|
||||
)
|
||||
|
||||
def test_component_tags_support_multiple_values_by_default(self):
|
||||
test_b = self.char1.components.get("test_b")
|
||||
|
|
@ -257,9 +256,12 @@ class TestComponents(EvenniaTest):
|
|||
test_b.multiple_tags = "second value"
|
||||
test_b.multiple_tags = "third value"
|
||||
|
||||
self.assertTrue(all(
|
||||
val in test_b.multiple_tags for val in ("first value", "second value", "third value")
|
||||
))
|
||||
self.assertTrue(
|
||||
all(
|
||||
val in test_b.multiple_tags
|
||||
for val in ("first value", "second value", "third value")
|
||||
)
|
||||
)
|
||||
self.assertTrue(self.char1.tags.has(key="first value", category="test_b::multiple_tags"))
|
||||
self.assertTrue(self.char1.tags.has(key="second value", category="test_b::multiple_tags"))
|
||||
self.assertTrue(self.char1.tags.has(key="third value", category="test_b::multiple_tags"))
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ the module given by settings.CONNECTION_SCREEN_MODULE.
|
|||
"""
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from evennia.accounts.models import AccountDB
|
||||
from evennia.commands.cmdhandler import CMD_LOGINSTART
|
||||
from evennia.commands.cmdset import CmdSet
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ except ImportError:
|
|||
import json
|
||||
|
||||
import mock
|
||||
from django.test import override_settings
|
||||
from mock import MagicMock, Mock
|
||||
from twisted.internet.base import DelayedCall
|
||||
from twisted.test import proto_helpers
|
||||
|
|
@ -22,11 +23,12 @@ import evennia
|
|||
from evennia.server.portal.portalsessionhandler import PortalSessionHandler
|
||||
from evennia.server.portal.service import EvenniaPortalService
|
||||
from evennia.utils.test_resources import BaseEvenniaTest
|
||||
from django.test import override_settings
|
||||
|
||||
|
||||
class TestGodotWebSocketClient(BaseEvenniaTest):
|
||||
@override_settings(GODOT_CLIENT_WEBSOCKET_CLIENT_INTERFACE="127.0.0.1", GODOT_CLIENT_WEBSOCKET_PORT='8988')
|
||||
@override_settings(
|
||||
GODOT_CLIENT_WEBSOCKET_CLIENT_INTERFACE="127.0.0.1", GODOT_CLIENT_WEBSOCKET_PORT="8988"
|
||||
)
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.portal = EvenniaPortalService()
|
||||
|
|
@ -34,7 +36,9 @@ class TestGodotWebSocketClient(BaseEvenniaTest):
|
|||
self.amp_server_factory = AMPServerFactory(self.portal)
|
||||
self.amp_server = self.amp_server_factory.buildProtocol("127.0.0.1")
|
||||
start_plugin_services(self.portal)
|
||||
godot_ws_service = next(srv for srv in self.portal.services if srv.name.startswith('GodotWebSocket'))
|
||||
godot_ws_service = next(
|
||||
srv for srv in self.portal.services if srv.name.startswith("GodotWebSocket")
|
||||
)
|
||||
|
||||
factory = godot_ws_service.args[1]
|
||||
self.proto = factory.protocol()
|
||||
|
|
@ -61,11 +65,15 @@ class TestGodotWebSocketClient(BaseEvenniaTest):
|
|||
self.proto.sessionhandler.data_in.assert_called_with(self.proto, logged_in=[[], {}])
|
||||
msg = json.dumps(["text", ("|rRed Text|n",), {}]).encode()
|
||||
self.proto.onMessage(msg, isBinary=False)
|
||||
self.proto.sessionhandler.data_in.assert_called_with(self.proto, text=[["|rRed Text|n"], {}])
|
||||
self.proto.sessionhandler.data_in.assert_called_with(
|
||||
self.proto, text=[["|rRed Text|n"], {}]
|
||||
)
|
||||
|
||||
@mock.patch("evennia.server.portal.portalsessionhandler.reactor", new=MagicMock())
|
||||
def test_data_out(self):
|
||||
self.proto.onOpen()
|
||||
self.proto.sendLine = MagicMock()
|
||||
self.proto.sessionhandler.data_out(self.proto, text=[["|rRed Text|n"], {}])
|
||||
self.proto.sendLine.assert_called_with(json.dumps(["text", ["[color=#ff0000]Red Text[/color]"], {}]))
|
||||
self.proto.sendLine.assert_called_with(
|
||||
json.dumps(["text", ["[color=#ff0000]Red Text[/color]"], {}])
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,9 +21,14 @@ called automatically when a new user connects.
|
|||
"""
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from evennia import CmdSet, Command, syscmdkeys
|
||||
from evennia.utils.evmenu import EvMenu
|
||||
from evennia.utils.utils import callables_from_module, class_from_module, random_string_from_module
|
||||
from evennia.utils.utils import (
|
||||
callables_from_module,
|
||||
class_from_module,
|
||||
random_string_from_module,
|
||||
)
|
||||
|
||||
_CONNECTION_SCREEN_MODULE = settings.CONNECTION_SCREEN_MODULE
|
||||
_GUEST_ENABLED = settings.GUEST_ENABLED
|
||||
|
|
|
|||
|
|
@ -333,13 +333,13 @@ class WildernessScript(DefaultScript):
|
|||
|
||||
# we will need to do special handling if the old room is a different location
|
||||
# check that here, so we only need to do it once
|
||||
if self == getattr(old_room, 'wilderness', None):
|
||||
if self == getattr(old_room, "wilderness", None):
|
||||
# it is our own room
|
||||
from_outside = False
|
||||
else:
|
||||
# it's from another wilderness, or no wilderness
|
||||
from_outside = True
|
||||
|
||||
|
||||
# check if we have a room at the new coordinates already
|
||||
room = self.db.rooms.get(new_coordinates)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ Use `evennia xyzgrid help` for usage help.
|
|||
|
||||
from os.path import join as pathjoin
|
||||
|
||||
import evennia
|
||||
from django.conf import settings
|
||||
|
||||
import evennia
|
||||
from evennia.contrib.grid.xyzgrid.xyzgrid import get_xyzgrid
|
||||
from evennia.utils import ansi
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ from random import randint
|
|||
from unittest import mock
|
||||
|
||||
from django.test import TestCase
|
||||
from evennia.utils.test_resources import BaseEvenniaCommandTest, BaseEvenniaTest
|
||||
from parameterized import parameterized
|
||||
|
||||
from evennia.utils.test_resources import BaseEvenniaCommandTest, BaseEvenniaTest
|
||||
|
||||
from . import commands, xymap, xymap_legend, xyzgrid, xyzroom
|
||||
|
||||
MAP1 = """
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ used as stand-alone XYZ-coordinate-aware rooms.
|
|||
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
|
||||
from evennia.objects.manager import ObjectManager
|
||||
from evennia.objects.objects import DefaultExit, DefaultRoom
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ Unit tests for the LLM Client and npc.
|
|||
|
||||
from anything import Something
|
||||
from django.test import override_settings
|
||||
from mock import Mock, patch
|
||||
|
||||
from evennia.utils.create import create_object
|
||||
from evennia.utils.test_resources import BaseEvenniaTestCase
|
||||
from mock import Mock, patch
|
||||
|
||||
from .llm_npc import LLMNPC
|
||||
|
||||
|
|
|
|||
|
|
@ -154,12 +154,18 @@ from string import punctuation
|
|||
|
||||
import inflect
|
||||
from django.conf import settings
|
||||
|
||||
from evennia.commands.cmdset import CmdSet
|
||||
from evennia.commands.command import Command
|
||||
from evennia.objects.models import ObjectDB
|
||||
from evennia.objects.objects import DefaultCharacter, DefaultObject
|
||||
from evennia.utils import ansi, logger
|
||||
from evennia.utils.utils import iter_to_str, lazy_property, make_iter, variable_from_module
|
||||
from evennia.utils.utils import (
|
||||
iter_to_str,
|
||||
lazy_property,
|
||||
make_iter,
|
||||
variable_from_module,
|
||||
)
|
||||
|
||||
_INFLECT = inflect.engine()
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ Tests for RP system
|
|||
import time
|
||||
|
||||
from anything import Anything
|
||||
|
||||
from evennia import DefaultObject, create_object, default_cmds
|
||||
from evennia.commands.default.tests import BaseEvenniaCommandTest
|
||||
from evennia.utils.test_resources import BaseEvenniaTest
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ EvAdventure character generation.
|
|||
|
||||
"""
|
||||
from django.conf import settings
|
||||
|
||||
from evennia.objects.models import ObjectDB
|
||||
from evennia.prototypes.spawner import spawn
|
||||
from evennia.utils.create import create_object
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ Test tutorial_world/mob
|
|||
|
||||
"""
|
||||
|
||||
from evennia.commands.default.tests import BaseEvenniaCommandTest
|
||||
from evennia.utils.create import create_object
|
||||
from evennia.utils.test_resources import BaseEvenniaTest, mockdeferLater, mockdelay
|
||||
from mock import patch
|
||||
from twisted.internet.base import DelayedCall
|
||||
from twisted.trial.unittest import TestCase as TwistedTestCase
|
||||
|
||||
from evennia.commands.default.tests import BaseEvenniaCommandTest
|
||||
from evennia.utils.create import create_object
|
||||
from evennia.utils.test_resources import BaseEvenniaTest, mockdeferLater, mockdelay
|
||||
|
||||
from . import mob
|
||||
from . import objects as tutobjects
|
||||
from . import rooms as tutrooms
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue