Run black on sources

This commit is contained in:
Griatch 2024-06-27 16:01:09 +02:00
parent 9ca41b5d0d
commit 9c3ba936e4
27 changed files with 153 additions and 90 deletions

View file

@ -48,6 +48,10 @@
template properly (InspectorCaracal)
- [Fix][pull3545]: Fix fallback issue in cmdhandler for local-object cmdsets (InspectorCaracal)
- [Fix][pull3554]: Fix/readd custom `ic` command to the `character_creator` contrib (InspectorCaracal)
- [Fix][pull3466]: Make sure the `website/base.html` website base is targeted
explicitly so it doesn't get overridden by same file name elsewhere in app (InspectorCaracal)
- [fix][issue3387]: Update all game template doc strings to be more up-to-date
(Griatch)
- [Docs]: Doc fixes (Griatch, chiizujin, InspectorCaracal, iLPDev)
[pull3470]: https://github.com/evennia/evennia/pull/3470
@ -79,7 +83,9 @@
[pull3549]: https://github.com/evennia/evennia/pull/3549
[pull3554]: https://github.com/evennia/evennia/pull/3554
[pull3523]: https://github.com/evennia/evennia/pull/3523
[pull3566]: https://github.com/evennia/evennia/pull/3566
[issue3522]: https://github.com/evennia/evennia/issue/3522
[issue3387]: https://github.com/evennia/evennia/issue/3387
## Evennia 4.1.1

View file

@ -16,13 +16,14 @@ import time
import typing
from random import getrandbits
import evennia
from django.conf import settings
from django.contrib.auth import authenticate, password_validation
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.utils import timezone
from django.utils.module_loading import import_string
from django.utils.translation import gettext as _
import evennia
from evennia.accounts.manager import AccountManager
from evennia.accounts.models import AccountDB
from evennia.commands.cmdsethandler import CmdSetHandler
@ -30,17 +31,24 @@ from evennia.comms.models import ChannelDB
from evennia.objects.models import ObjectDB
from evennia.scripts.scripthandler import ScriptHandler
from evennia.server.models import ServerConfig
from evennia.server.signals import (SIGNAL_ACCOUNT_POST_CREATE,
SIGNAL_ACCOUNT_POST_LOGIN_FAIL,
SIGNAL_OBJECT_POST_PUPPET,
SIGNAL_OBJECT_POST_UNPUPPET)
from evennia.server.signals import (
SIGNAL_ACCOUNT_POST_CREATE,
SIGNAL_ACCOUNT_POST_LOGIN_FAIL,
SIGNAL_OBJECT_POST_PUPPET,
SIGNAL_OBJECT_POST_UNPUPPET,
)
from evennia.server.throttle import Throttle
from evennia.typeclasses.attributes import ModelAttributeBackend, NickHandler
from evennia.typeclasses.models import TypeclassBase
from evennia.utils import class_from_module, create, logger
from evennia.utils.optionhandler import OptionHandler
from evennia.utils.utils import (is_iter, lazy_property, make_iter, to_str,
variable_from_module)
from evennia.utils.utils import (
is_iter,
lazy_property,
make_iter,
to_str,
variable_from_module,
)
__all__ = ("DefaultAccount", "DefaultGuest")

View file

@ -2,9 +2,10 @@
import django.core.validators
import evennia.accounts.manager
from django.db import migrations, models
import evennia.accounts.manager
class Migration(migrations.Migration):

View file

@ -3,14 +3,18 @@
from random import randint
from unittest import TestCase
import evennia
from django.test import override_settings
from evennia.accounts.accounts import (AccountSessionHandler, DefaultAccount,
DefaultGuest)
from mock import MagicMock, Mock, patch
import evennia
from evennia.accounts.accounts import (
AccountSessionHandler,
DefaultAccount,
DefaultGuest,
)
from evennia.utils import create
from evennia.utils.test_resources import BaseEvenniaTest
from evennia.utils.utils import uses_database
from mock import MagicMock, Mock, patch
class TestAccountSessionHandler(TestCase):

View file

@ -9,6 +9,7 @@ Communication commands:
from django.conf import settings
from django.db.models import Q
from evennia.accounts import bots
from evennia.accounts.models import AccountDB
from evennia.comms.comms import DefaultChannel
@ -1412,9 +1413,7 @@ class CmdPage(COMMAND_DEFAULT_CLASS):
message = f"{caller.key} {message.strip(':').strip()}"
# create the persistent message object
target_perms = " or ".join(
[f"id({target.id})" for target in targets + [caller]]
)
target_perms = " or ".join([f"id({target.id})" for target in targets + [caller]])
create.create_message(
caller,
message,

View file

@ -5,10 +5,11 @@ Base typeclass for in-game Channels.
import re
import evennia
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from django.utils.text import slugify
import evennia
from evennia.comms.managers import ChannelManager
from evennia.comms.models import ChannelDB
from evennia.typeclasses.models import TypeclassBase

View file

@ -22,6 +22,7 @@ necessary to easily be able to delete connections on the fly).
from django.conf import settings
from django.db import models
from django.utils import timezone
from evennia.comms import managers
from evennia.locks.lockhandler import LockHandler
from evennia.typeclasses.models import TypedObject

View file

@ -15,16 +15,17 @@ class BaseComponent(type):
This is the metaclass for components,
responsible for registering components to the listing.
"""
def __new__(cls, name, parents, attrs):
"""
Every class that uses this metaclass will be registered
as a component in the Component Listing using its name.
All of them require a unique name.
"""
attrs_name = attrs.get('name')
attrs_name = attrs.get("name")
if attrs_name and not COMPONENT_LISTING.get(attrs_name):
new_fields = {}
attrs['_fields'] = new_fields
attrs["_fields"] = new_fields
for parent in parents:
_parent_fields = getattr(parent, "_fields")
if _parent_fields:

View file

@ -87,23 +87,23 @@ class TestComponents(EvenniaTest):
def test_character_components_set_fields_properly(self):
test_a_fields = self.char1.test_a._fields
self.assertIn('my_int', test_a_fields)
self.assertIn('my_list', test_a_fields)
self.assertIn("my_int", test_a_fields)
self.assertIn("my_list", test_a_fields)
self.assertEqual(len(test_a_fields), 2)
test_b_fields = self.char1.test_b._fields
self.assertIn('my_int', test_b_fields)
self.assertIn('my_list', test_b_fields)
self.assertIn('default_tag', test_b_fields)
self.assertIn('single_tag', test_b_fields)
self.assertIn('multiple_tags', test_b_fields)
self.assertIn('default_single_tag', test_b_fields)
self.assertIn("my_int", test_b_fields)
self.assertIn("my_list", test_b_fields)
self.assertIn("default_tag", test_b_fields)
self.assertIn("single_tag", test_b_fields)
self.assertIn("multiple_tags", test_b_fields)
self.assertIn("default_single_tag", test_b_fields)
self.assertEqual(len(test_b_fields), 6)
test_ic_a_fields = self.char1.ic_a._fields
self.assertIn('my_int', test_ic_a_fields)
self.assertIn('my_list', test_ic_a_fields)
self.assertIn('my_other_int', test_ic_a_fields)
self.assertIn("my_int", test_ic_a_fields)
self.assertIn("my_list", test_ic_a_fields)
self.assertIn("my_other_int", test_ic_a_fields)
self.assertEqual(len(test_ic_a_fields), 3)
def test_inherited_typeclass_does_not_include_child_class_components(self):

View file

@ -1,8 +1,8 @@
from .achievements import (
get_achievement,
search_achievement,
all_achievements,
track_achievements,
get_achievement_progress,
CmdAchieve,
all_achievements,
get_achievement,
get_achievement_progress,
search_achievement,
track_achievements,
)

View file

@ -50,11 +50,18 @@ Example:
"""
from collections import Counter
from django.conf import settings
from evennia.utils import logger
from evennia.utils.utils import all_from_module, is_iter, make_iter, string_partial_matching
from evennia.utils.evmore import EvMore
from evennia.commands.default.muxcommand import MuxCommand
from evennia.utils import logger
from evennia.utils.evmore import EvMore
from evennia.utils.utils import (
all_from_module,
is_iter,
make_iter,
string_partial_matching,
)
# this is either a string of the attribute name, or a tuple of strings of the attribute name and category
_ACHIEVEMENT_ATTR = make_iter(getattr(settings, "ACHIEVEMENT_CONTRIB_ATTRIBUTE", "achievements"))
@ -322,12 +329,12 @@ class CmdAchieve(MuxCommand):
elif not achievement_data.get("progress"):
status = "|yNot Started|n"
else:
count = achievement_data.get("count",1)
count = achievement_data.get("count", 1)
# is this achievement tracking items separately?
if is_iter(achievement_data["progress"]):
# we'll display progress as how many items have been completed
completed = Counter(val >= count for val in achievement_data["progress"])[True]
pct = (completed * 100) // len(achievement_data['progress'])
pct = (completed * 100) // len(achievement_data["progress"])
else:
# we display progress as the percent of the total count
pct = (achievement_data["progress"] * 100) // count
@ -379,8 +386,7 @@ class CmdAchieve(MuxCommand):
elif "all" in self.switches:
# we merge our progress data into the full dict of achievements
achievement_data = {
key: data | progress_data.get(key, {})
for key, data in achievements.items()
key: data | progress_data.get(key, {}) for key, data in achievements.items()
}
# we show all of the currently available achievements regardless of progress status

View file

@ -1,5 +1,7 @@
from evennia.utils.test_resources import BaseEvenniaTest, BaseEvenniaCommandTest
from mock import patch
from evennia.utils.test_resources import BaseEvenniaCommandTest, BaseEvenniaTest
from . import achievements
_dummy_achievements = {

View file

@ -47,8 +47,17 @@ from collections import deque
from django.conf import settings
from django.db.models import Q
from evennia import (CmdSet, DefaultRoom, EvEditor, FuncParser,
InterruptCommand, default_cmds, gametime, utils)
from evennia import (
CmdSet,
DefaultRoom,
EvEditor,
FuncParser,
InterruptCommand,
default_cmds,
gametime,
utils,
)
from evennia.typeclasses.attributes import AttributeProperty
from evennia.utils.utils import list_to_string, repeat

View file

@ -22,9 +22,9 @@ from random import choices
from django.conf import settings
from evennia import DefaultAccount
from evennia.commands.default.muxcommand import MuxAccountCommand
from evennia.commands.default.account import CmdIC
from evennia.commands.cmdset import CmdSet
from evennia.commands.default.account import CmdIC
from evennia.commands.default.muxcommand import MuxAccountCommand
from evennia.objects.models import ObjectDB
from evennia.utils.evmenu import EvMenu
from evennia.utils.utils import is_iter, string_partial_matching

View file

@ -15,6 +15,7 @@ from django.db import models
from django.urls import reverse
from django.utils import timezone
from django.utils.text import slugify
from evennia.help.manager import HelpEntryManager
from evennia.locks.lockhandler import LockHandler
from evennia.typeclasses.models import AliasHandler, Tag, TagHandler

View file

@ -10,10 +10,11 @@ import time
import typing
from collections import defaultdict
import evennia
import inflect
from django.conf import settings
from django.utils.translation import gettext as _
import evennia
from evennia.commands import cmdset
from evennia.commands.cmdsethandler import CmdSetHandler
from evennia.objects.manager import ObjectManager
@ -23,9 +24,17 @@ from evennia.server.signals import SIGNAL_EXIT_TRAVERSED
from evennia.typeclasses.attributes import ModelAttributeBackend, NickHandler
from evennia.typeclasses.models import TypeclassBase
from evennia.utils import ansi, create, funcparser, logger, search
from evennia.utils.utils import (class_from_module, compress_whitespace, dbref,
is_iter, iter_to_str, lazy_property,
make_iter, to_str, variable_from_module)
from evennia.utils.utils import (
class_from_module,
compress_whitespace,
dbref,
is_iter,
iter_to_str,
lazy_property,
make_iter,
to_str,
variable_from_module,
)
_INFLECT = inflect.engine()
_MULTISESSION_MODE = settings.MULTISESSION_MODE

View file

@ -6,12 +6,13 @@ ability to run timers.
"""
from django.utils.translation import gettext as _
from twisted.internet.defer import Deferred, maybeDeferred
from twisted.internet.task import LoopingCall
from evennia.scripts.manager import ScriptManager
from evennia.scripts.models import ScriptDB
from evennia.typeclasses.models import TypeclassBase
from evennia.utils import create, logger
from twisted.internet.defer import Deferred, maybeDeferred
from twisted.internet.task import LoopingCall
__all__ = ["DefaultScript", "DoNothing", "Store"]

View file

@ -474,7 +474,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, _BASE_SESSION_CLASS):
_RE_N.sub("", prompt) + ("||n" if prompt.endswith("|") else "|n"),
strip_ansi=nocolor,
xterm256=xterm256,
truecolor=truecolor
truecolor=truecolor,
)
if mxp:
prompt = mxp_parse(prompt)
@ -511,7 +511,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, _BASE_SESSION_CLASS):
strip_ansi=nocolor,
xterm256=xterm256,
mxp=mxp,
truecolor=truecolor
truecolor=truecolor,
)
if mxp:
linetosend = mxp_parse(linetosend)

View file

@ -130,10 +130,10 @@ class Ttype:
self.protocol.protocol_flags["NOPROMPTGOAHEAD"] = False
if (
clientname.startswith("XTERM")
or clientname.endswith("-256COLOR")
or clientname
in (
clientname.startswith("XTERM")
or clientname.endswith("-256COLOR")
or clientname
in (
"ATLANTIS", # > 0.9.9.0 (aug 2009)
"CMUD", # > 3.04 (mar 2009)
"KILDCLIENT", # > 2.2.0 (sep 2005)
@ -143,17 +143,13 @@ class Ttype:
"BEIP", # > 2.00.206 (late 2009) (BeipMu)
"POTATO", # > 2.00 (maybe earlier)
"TINYFUGUE", # > 4.x (maybe earlier)
)
)
):
xterm256 = True
# use name to identify support for xterm truecolor
truecolor = False
if (clientname.endswith("-TRUECOLOR") or
clientname in (
"AXMUD",
"TINTIN"
)):
if clientname.endswith("-TRUECOLOR") or clientname in ("AXMUD", "TINTIN"):
truecolor = True
# all clients supporting TTYPE at all seem to support ANSI
@ -169,9 +165,9 @@ class Ttype:
tupper = term.upper()
# identify xterm256 based on flag
xterm256 = (
tupper.endswith("-256COLOR")
or tupper.endswith("XTERM") # Apple Terminal, old Tintin
and not tupper.endswith("-COLOR") # old Tintin, Putty
tupper.endswith("-256COLOR")
or tupper.endswith("XTERM") # Apple Terminal, old Tintin
and not tupper.endswith("-COLOR") # old Tintin, Putty
)
if xterm256:
self.protocol.protocol_flags["ANSI"] = True

View file

@ -26,7 +26,6 @@ these to create custom managers.
"""
import evennia
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
@ -37,21 +36,30 @@ from django.urls import reverse
from django.utils import timezone
from django.utils.encoding import smart_str
from django.utils.text import slugify
import evennia
from evennia.locks.lockhandler import LockHandler
from evennia.server.signals import SIGNAL_TYPED_OBJECT_POST_RENAME
from evennia.typeclasses import managers
from evennia.typeclasses.attributes import (Attribute, AttributeHandler,
AttributeProperty, DbHolder,
InMemoryAttributeBackend,
ModelAttributeBackend)
from evennia.typeclasses.tags import (AliasHandler, PermissionHandler, Tag,
TagCategoryProperty, TagHandler,
TagProperty)
from evennia.utils.idmapper.models import (SharedMemoryModel,
SharedMemoryModelBase)
from evennia.typeclasses.attributes import (
Attribute,
AttributeHandler,
AttributeProperty,
DbHolder,
InMemoryAttributeBackend,
ModelAttributeBackend,
)
from evennia.typeclasses.tags import (
AliasHandler,
PermissionHandler,
Tag,
TagCategoryProperty,
TagHandler,
TagProperty,
)
from evennia.utils.idmapper.models import SharedMemoryModel, SharedMemoryModelBase
from evennia.utils.logger import log_trace
from evennia.utils.utils import (class_from_module, inherits_from, is_iter,
lazy_property)
from evennia.utils.utils import class_from_module, inherits_from, is_iter, lazy_property
__all__ = ("TypedObject",)

View file

@ -69,8 +69,8 @@ from collections import OrderedDict
from django.conf import settings
from evennia.utils import logger, utils
from evennia.utils.utils import to_str
from evennia.utils.hex_colors import HexColors
from evennia.utils.utils import to_str
hex2truecolor = HexColors()
hex_sub = HexColors.hex_sub

View file

@ -722,7 +722,7 @@ class CmdEditorGroup(CmdEditorBase):
}
align_name = {"f": "Full", "c": "Center", "l": "Left", "r": "Right"}
# shift width arg right if no alignment specified
if self.arg1.startswith('='):
if self.arg1.startswith("="):
self.arg2 = self.arg1
self.arg1 = None
if self.arg1 and self.arg1.lower() not in align_map:

View file

@ -272,17 +272,28 @@ from fnmatch import fnmatch
from inspect import getfullargspec, isfunction
from math import ceil
import evennia
from django.conf import settings
# i18n
from django.utils.translation import gettext as _
import evennia
from evennia import CmdSet, Command
from evennia.commands import cmdhandler
from evennia.utils import logger
from evennia.utils.ansi import strip_ansi
from evennia.utils.evtable import EvColumn, EvTable
from evennia.utils.utils import (crop, dedent, inherits_from, is_iter, m_len,
make_iter, mod_import, pad, to_str)
from evennia.utils.utils import (
crop,
dedent,
inherits_from,
is_iter,
m_len,
make_iter,
mod_import,
pad,
to_str,
)
# read from protocol NAWS later?
_MAX_TEXT_WIDTH = settings.CLIENT_DEFAULT_WIDTH

View file

@ -10,10 +10,11 @@ from ast import literal_eval
from unittest.mock import MagicMock, patch
from django.test import TestCase, override_settings
from evennia.utils import funcparser, test_resources
from parameterized import parameterized
from simpleeval import simple_eval
from evennia.utils import funcparser, test_resources
def _test_callable(*args, **kwargs):
kwargs.pop("funcparser", None)

View file

@ -49,9 +49,7 @@ class TestText2Html(TestCase):
# True Color
self.assertEqual(
'<span class="" style="color: #ff0000;">red</span>foo',
parser.format_styles(
f'\x1b[38;2;255;0;0m' + "red" + ansi.ANSI_NORMAL + "foo"
),
parser.format_styles(f"\x1b[38;2;255;0;0m" + "red" + ansi.ANSI_NORMAL + "foo"),
)
def test_remove_bells(self):

View file

@ -1,6 +1,7 @@
from django.test import TestCase
from evennia.utils.ansi import ANSIString as AN, ANSIParser
from evennia.utils.ansi import ANSIParser
from evennia.utils.ansi import ANSIString as AN
parser = ANSIParser().parse_ansi

View file

@ -12,7 +12,6 @@ import re
from html import escape as html_escape
from .ansi import *
from .hex_colors import HexColors
# All xterm256 RGB equivalents