mirror of
https://github.com/evennia/evennia.git
synced 2025-10-29 11:26:10 +00:00
Ran black on sources
This commit is contained in:
parent
86805ef306
commit
ca341278e9
2
Makefile
2
Makefile
@ -1,7 +1,7 @@
|
|||||||
# This is used with `make <option>` and is used for running various
|
# This is used with `make <option>` and is used for running various
|
||||||
# administration operations on the code.
|
# administration operations on the code.
|
||||||
|
|
||||||
BLACK_FORMAT_CONFIGS = --target-version py37 --line-length 100
|
BLACK_FORMAT_CONFIGS = --target-version py37 --line-length 100 --exclude=/docs
|
||||||
TEST_GAME_DIR = .test_game_dir
|
TEST_GAME_DIR = .test_game_dir
|
||||||
tests?=evennia
|
tests?=evennia
|
||||||
|
|
||||||
|
|||||||
@ -13,8 +13,9 @@ from evennia.utils.utils import (
|
|||||||
class_from_module,
|
class_from_module,
|
||||||
get_all_typeclasses,
|
get_all_typeclasses,
|
||||||
variable_from_module,
|
variable_from_module,
|
||||||
dbref, interactive,
|
dbref,
|
||||||
list_to_string
|
interactive,
|
||||||
|
list_to_string,
|
||||||
)
|
)
|
||||||
from evennia.utils.eveditor import EvEditor
|
from evennia.utils.eveditor import EvEditor
|
||||||
from evennia.utils.evmore import EvMore
|
from evennia.utils.evmore import EvMore
|
||||||
@ -3230,7 +3231,6 @@ class CmdTag(COMMAND_DEFAULT_CLASS):
|
|||||||
# helper functions for spawn
|
# helper functions for spawn
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
||||||
"""
|
"""
|
||||||
spawn objects from prototype
|
spawn objects from prototype
|
||||||
@ -3333,16 +3333,16 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||||||
err = f"No prototype named '{prototype_key}' was found."
|
err = f"No prototype named '{prototype_key}' was found."
|
||||||
elif nprots > 1:
|
elif nprots > 1:
|
||||||
err = "Found {} prototypes matching '{}':\n {}".format(
|
err = "Found {} prototypes matching '{}':\n {}".format(
|
||||||
nprots,
|
nprots,
|
||||||
prototype_key,
|
prototype_key,
|
||||||
", ".join(proto.get("prototype_key", "") for proto in prototypes),
|
", ".join(proto.get("prototype_key", "") for proto in prototypes),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# we have a single prototype, check access
|
# we have a single prototype, check access
|
||||||
prototype = prototypes[0]
|
prototype = prototypes[0]
|
||||||
if not self.caller.locks.check_lockstring(
|
if not self.caller.locks.check_lockstring(
|
||||||
self.caller, prototype.get("prototype_locks", ""),
|
self.caller, prototype.get("prototype_locks", ""), access_type="spawn", default=True
|
||||||
access_type="spawn", default=True):
|
):
|
||||||
err = "You don't have access to use this prototype."
|
err = "You don't have access to use this prototype."
|
||||||
|
|
||||||
if err:
|
if err:
|
||||||
@ -3440,10 +3440,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||||||
if not table:
|
if not table:
|
||||||
return True
|
return True
|
||||||
EvMore(
|
EvMore(
|
||||||
self.caller,
|
self.caller, str(table), exit_on_lastpage=True, justify_kwargs=False,
|
||||||
str(table),
|
|
||||||
exit_on_lastpage=True,
|
|
||||||
justify_kwargs=False,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@interactive
|
@interactive
|
||||||
@ -3487,7 +3484,8 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
n_updated = spawner.batch_update_objects_with_prototype(
|
n_updated = spawner.batch_update_objects_with_prototype(
|
||||||
prototype, objects=existing_objects)
|
prototype, objects=existing_objects
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log_trace()
|
logger.log_trace()
|
||||||
caller.msg(f"{n_updated} objects were updated.")
|
caller.msg(f"{n_updated} objects were updated.")
|
||||||
@ -3575,8 +3573,11 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||||||
tags = self.lhslist
|
tags = self.lhslist
|
||||||
err = self._list_prototypes(tags=tags)
|
err = self._list_prototypes(tags=tags)
|
||||||
if err:
|
if err:
|
||||||
caller.msg("No prototypes found with prototype-tag(s): {}".format(
|
caller.msg(
|
||||||
list_to_string(tags, "or")))
|
"No prototypes found with prototype-tag(s): {}".format(
|
||||||
|
list_to_string(tags, "or")
|
||||||
|
)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if "save" in self.switches:
|
if "save" in self.switches:
|
||||||
@ -3606,8 +3607,10 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||||||
prot_prototype_key = prototype.get("prototype_key")
|
prot_prototype_key = prototype.get("prototype_key")
|
||||||
|
|
||||||
if not (prototype_key or prot_prototype_key):
|
if not (prototype_key or prot_prototype_key):
|
||||||
caller.msg("A prototype_key must be given, either as `prototype_key = <prototype>` "
|
caller.msg(
|
||||||
"or as a key 'prototype_key' inside the prototype structure.")
|
"A prototype_key must be given, either as `prototype_key = <prototype>` "
|
||||||
|
"or as a key 'prototype_key' inside the prototype structure."
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if prototype_key is None:
|
if prototype_key is None:
|
||||||
@ -3615,14 +3618,14 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||||||
|
|
||||||
if prot_prototype_key != prototype_key:
|
if prot_prototype_key != prototype_key:
|
||||||
caller.msg("(Replacing `prototype_key` in prototype with given key.)")
|
caller.msg("(Replacing `prototype_key` in prototype with given key.)")
|
||||||
prototype['prototype_key'] = prototype_key
|
prototype["prototype_key"] = prototype_key
|
||||||
|
|
||||||
if prototype_desc is not None and prot_prototype_key != prototype_desc:
|
if prototype_desc is not None and prot_prototype_key != prototype_desc:
|
||||||
caller.msg("(Replacing `prototype_desc` in prototype with given desc.)")
|
caller.msg("(Replacing `prototype_desc` in prototype with given desc.)")
|
||||||
prototype['prototype_desc'] = prototype_desc
|
prototype["prototype_desc"] = prototype_desc
|
||||||
if prototype_tags is not None and prototype.get("prototype_tags") != prototype_tags:
|
if prototype_tags is not None and prototype.get("prototype_tags") != prototype_tags:
|
||||||
caller.msg("(Replacing `prototype_tags` in prototype with given tag(s))" )
|
caller.msg("(Replacing `prototype_tags` in prototype with given tag(s))")
|
||||||
prototype['prototype_tags'] = prototype_tags
|
prototype["prototype_tags"] = prototype_tags
|
||||||
|
|
||||||
string = ""
|
string = ""
|
||||||
# check for existing prototype (exact match)
|
# check for existing prototype (exact match)
|
||||||
@ -3635,11 +3638,17 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||||||
if old_prototype:
|
if old_prototype:
|
||||||
if not diffstr:
|
if not diffstr:
|
||||||
string = f"|yAlready existing Prototype:|n\n{new_prototype_detail}\n"
|
string = f"|yAlready existing Prototype:|n\n{new_prototype_detail}\n"
|
||||||
question = "\nThere seems to be no changes. Do you still want to (re)save? [Y]/N"
|
question = (
|
||||||
|
"\nThere seems to be no changes. Do you still want to (re)save? [Y]/N"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
string = (f"|yExisting prototype \"{prototype_key}\" found. Change:|n\n{diffstr}\n"
|
string = (
|
||||||
f"|yNew changed prototype:|n\n{new_prototype_detail}")
|
f'|yExisting prototype "{prototype_key}" found. Change:|n\n{diffstr}\n'
|
||||||
question = "\n|yDo you want to apply the change to the existing prototype?|n [Y]/N"
|
f"|yNew changed prototype:|n\n{new_prototype_detail}"
|
||||||
|
)
|
||||||
|
question = (
|
||||||
|
"\n|yDo you want to apply the change to the existing prototype?|n [Y]/N"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
string = f"|yCreating new prototype:|n\n{new_prototype_detail}"
|
string = f"|yCreating new prototype:|n\n{new_prototype_detail}"
|
||||||
question = "\nDo you want to continue saving? [Y]/N"
|
question = "\nDo you want to continue saving? [Y]/N"
|
||||||
@ -3692,8 +3701,11 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||||||
except protlib.PermissionError as err:
|
except protlib.PermissionError as err:
|
||||||
retmsg = f"|rError deleting:|R {err}|n"
|
retmsg = f"|rError deleting:|R {err}|n"
|
||||||
else:
|
else:
|
||||||
retmsg = ("Deletion successful" if success else
|
retmsg = (
|
||||||
"Deletion failed (does the prototype exist?)")
|
"Deletion successful"
|
||||||
|
if success
|
||||||
|
else "Deletion failed (does the prototype exist?)"
|
||||||
|
)
|
||||||
caller.msg(retmsg)
|
caller.msg(retmsg)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -3726,7 +3738,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
|||||||
try:
|
try:
|
||||||
for obj in spawner.spawn(prototype):
|
for obj in spawner.spawn(prototype):
|
||||||
self.caller.msg("Spawned %s." % obj.get_display_name(self.caller))
|
self.caller.msg("Spawned %s." % obj.get_display_name(self.caller))
|
||||||
if not prototype.get('location') and not noloc:
|
if not prototype.get("location") and not noloc:
|
||||||
# we don't hardcode the location in the prototype (unless the user
|
# we don't hardcode the location in the prototype (unless the user
|
||||||
# did so manually) - that would lead to it having to be 'removed' every
|
# did so manually) - that would lead to it having to be 'removed' every
|
||||||
# time we try to update objects with this prototype in the future.
|
# time we try to update objects with this prototype in the future.
|
||||||
|
|||||||
@ -1366,7 +1366,9 @@ class TestBuilding(CommandTest):
|
|||||||
|
|
||||||
# spawn/examine with invalid prototype
|
# spawn/examine with invalid prototype
|
||||||
# shows error
|
# shows error
|
||||||
self.call(building.CmdSpawn(), "/examine NO_EXISTS", "No prototype named 'NO_EXISTS' was found.")
|
self.call(
|
||||||
|
building.CmdSpawn(), "/examine NO_EXISTS", "No prototype named 'NO_EXISTS' was found."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestComms(CommandTest):
|
class TestComms(CommandTest):
|
||||||
|
|||||||
@ -2179,8 +2179,11 @@ def _format_diff_text_and_options(diff, minimal=True, **kwargs):
|
|||||||
vsep = "" if len(vold) < 78 else "\n"
|
vsep = "" if len(vold) < 78 else "\n"
|
||||||
|
|
||||||
if instruction == "ADD":
|
if instruction == "ADD":
|
||||||
texts.append(" |c[{optnum}] |yADD|n: {new}".format(
|
texts.append(
|
||||||
optnum=optnum, new=_visualize(new, rootname)))
|
" |c[{optnum}] |yADD|n: {new}".format(
|
||||||
|
optnum=optnum, new=_visualize(new, rootname)
|
||||||
|
)
|
||||||
|
)
|
||||||
elif instruction == "REMOVE" and not new:
|
elif instruction == "REMOVE" and not new:
|
||||||
if rootname == "tags" and old[1] == protlib.PROTOTYPE_TAG_CATEGORY:
|
if rootname == "tags" and old[1] == protlib.PROTOTYPE_TAG_CATEGORY:
|
||||||
# special exception for the prototype-tag mechanism
|
# special exception for the prototype-tag mechanism
|
||||||
@ -2188,8 +2191,11 @@ def _format_diff_text_and_options(diff, minimal=True, **kwargs):
|
|||||||
# not be listed as REMOVE.
|
# not be listed as REMOVE.
|
||||||
return texts, options, optnum
|
return texts, options, optnum
|
||||||
|
|
||||||
texts.append(" |c[{optnum}] |rREMOVE|n: {old}".format(
|
texts.append(
|
||||||
optnum=optnum, old=_visualize(old, rootname)))
|
" |c[{optnum}] |rREMOVE|n: {old}".format(
|
||||||
|
optnum=optnum, old=_visualize(old, rootname)
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
vinst = "|y{}|n".format(instruction)
|
vinst = "|y{}|n".format(instruction)
|
||||||
texts.append(
|
texts.append(
|
||||||
@ -2294,8 +2300,9 @@ def node_apply_diff(caller, **kwargs):
|
|||||||
if not custom_location:
|
if not custom_location:
|
||||||
diff.pop("location", None)
|
diff.pop("location", None)
|
||||||
|
|
||||||
txt, options = _format_diff_text_and_options(diff, objects=update_objects,
|
txt, options = _format_diff_text_and_options(
|
||||||
base_obj=base_obj, prototype=prototype)
|
diff, objects=update_objects, base_obj=base_obj, prototype=prototype
|
||||||
|
)
|
||||||
|
|
||||||
if options:
|
if options:
|
||||||
text = [
|
text = [
|
||||||
|
|||||||
@ -124,13 +124,13 @@ def homogenize_prototype(prototype, custom_keys=None):
|
|||||||
|
|
||||||
# add required missing parts that had defaults before
|
# add required missing parts that had defaults before
|
||||||
|
|
||||||
homogenized["prototype_key"] = homogenized.get("prototype_key",
|
homogenized["prototype_key"] = homogenized.get(
|
||||||
|
"prototype_key",
|
||||||
# assign a random hash as key
|
# assign a random hash as key
|
||||||
"prototype-{}".format(
|
"prototype-{}".format(hashlib.md5(bytes(str(time.time()), "utf-8")).hexdigest()[:7]),
|
||||||
hashlib.md5(bytes(str(time.time()), "utf-8")).hexdigest()[:7]))
|
)
|
||||||
homogenized["prototype_tags"] = homogenized.get("prototype_tags", [])
|
homogenized["prototype_tags"] = homogenized.get("prototype_tags", [])
|
||||||
homogenized["prototype_locks"] = homogenized.get(
|
homogenized["prototype_locks"] = homogenized.get("prototype_lock", _PROTOTYPE_FALLBACK_LOCK)
|
||||||
"prototype_lock", _PROTOTYPE_FALLBACK_LOCK)
|
|
||||||
homogenized["prototype_desc"] = homogenized.get("prototype_desc", "")
|
homogenized["prototype_desc"] = homogenized.get("prototype_desc", "")
|
||||||
if "typeclass" not in prototype and "prototype_parent" not in prototype:
|
if "typeclass" not in prototype and "prototype_parent" not in prototype:
|
||||||
homogenized["typeclass"] = settings.BASE_OBJECT_TYPECLASS
|
homogenized["typeclass"] = settings.BASE_OBJECT_TYPECLASS
|
||||||
@ -752,7 +752,7 @@ def prototype_to_str(prototype):
|
|||||||
)
|
)
|
||||||
attrs = "|cattrs:|n\n {attrs}".format(attrs="\n ".join(out))
|
attrs = "|cattrs:|n\n {attrs}".format(attrs="\n ".join(out))
|
||||||
if "tags" in prototype:
|
if "tags" in prototype:
|
||||||
tags = prototype['tags']
|
tags = prototype["tags"]
|
||||||
out = []
|
out = []
|
||||||
for (tagkey, category, data) in tags:
|
for (tagkey, category, data) in tags:
|
||||||
out.append(
|
out.append(
|
||||||
|
|||||||
@ -171,13 +171,14 @@ class Unset:
|
|||||||
Helper class representing a non-set diff element.
|
Helper class representing a non-set diff element.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "<Unset>"
|
return "<Unset>"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Helper
|
# Helper
|
||||||
|
|
||||||
|
|
||||||
@ -405,7 +406,9 @@ def prototype_diff(prototype1, prototype2, maxdepth=2, homogenize=False, implici
|
|||||||
new_map = {part[0] if is_iter(part) else part: part for part in new}
|
new_map = {part[0] if is_iter(part) else part: part for part in new}
|
||||||
all_keys = set(list(old_map.keys()) + list(new_map.keys()))
|
all_keys = set(list(old_map.keys()) + list(new_map.keys()))
|
||||||
return {
|
return {
|
||||||
key: _recursive_diff(old_map.get(key, _unset), new_map.get(key, _unset), depth=depth + 1)
|
key: _recursive_diff(
|
||||||
|
old_map.get(key, _unset), new_map.get(key, _unset), depth=depth + 1
|
||||||
|
)
|
||||||
for key in all_keys
|
for key in all_keys
|
||||||
}
|
}
|
||||||
elif old != new:
|
elif old != new:
|
||||||
@ -520,8 +523,9 @@ def prototype_diff_from_object(prototype, obj, implicit_keep=True):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
obj_prototype = prototype_from_object(obj)
|
obj_prototype = prototype_from_object(obj)
|
||||||
diff = prototype_diff(obj_prototype, protlib.homogenize_prototype(prototype),
|
diff = prototype_diff(
|
||||||
implicit_keep=implicit_keep)
|
obj_prototype, protlib.homogenize_prototype(prototype), implicit_keep=implicit_keep
|
||||||
|
)
|
||||||
return diff, obj_prototype
|
return diff, obj_prototype
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -212,7 +212,7 @@ class TestUtils(EvenniaTest):
|
|||||||
"puppet:pperm(Developer);tell:perm(Admin);view:all()",
|
"puppet:pperm(Developer);tell:perm(Admin);view:all()",
|
||||||
"KEEP",
|
"KEEP",
|
||||||
),
|
),
|
||||||
"prototype_tags": (None, None, 'KEEP'),
|
"prototype_tags": (None, None, "KEEP"),
|
||||||
"attrs": {
|
"attrs": {
|
||||||
"oldtest": (
|
"oldtest": (
|
||||||
("oldtest", "to_keep", None, ""),
|
("oldtest", "to_keep", None, ""),
|
||||||
@ -269,7 +269,7 @@ class TestUtils(EvenniaTest):
|
|||||||
new_prot = spawner.prototype_from_object(self.obj1)
|
new_prot = spawner.prototype_from_object(self.obj1)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
{
|
{
|
||||||
"aliases": ['foo'],
|
"aliases": ["foo"],
|
||||||
"attrs": [
|
"attrs": [
|
||||||
("desc", "changed desc", None, ""),
|
("desc", "changed desc", None, ""),
|
||||||
("fooattr", "fooattrval", None, ""),
|
("fooattr", "fooattrval", None, ""),
|
||||||
@ -294,9 +294,7 @@ class TestUtils(EvenniaTest):
|
|||||||
"view:all()",
|
"view:all()",
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'tags': [
|
"tags": [("footag", "foocategory", None), (Something, "from_prototype", None)],
|
||||||
('footag', 'foocategory', None),
|
|
||||||
(Something, 'from_prototype', None)],
|
|
||||||
"permissions": ["builder"],
|
"permissions": ["builder"],
|
||||||
"prototype_desc": "Built from Obj",
|
"prototype_desc": "Built from Obj",
|
||||||
"prototype_key": Something,
|
"prototype_key": Something,
|
||||||
@ -927,7 +925,7 @@ class TestMenuModule(EvenniaTest):
|
|||||||
"\n- |wprototype_locks:|n"
|
"\n- |wprototype_locks:|n"
|
||||||
"\n- |wprototype_tags:|n"
|
"\n- |wprototype_tags:|n"
|
||||||
"\n- |wtags:|n |c[3] |yADD|n: foo |W(category:|n None|W)|n"
|
"\n- |wtags:|n |c[3] |yADD|n: foo |W(category:|n None|W)|n"
|
||||||
"\n- |wtypeclass:|n"
|
"\n- |wtypeclass:|n",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|||||||
@ -269,7 +269,7 @@ class EvMore(object):
|
|||||||
Paginate by slice. This is done with an eye on memory efficiency (usually for
|
Paginate by slice. This is done with an eye on memory efficiency (usually for
|
||||||
querysets); to avoid fetching all objects at the same time.
|
querysets); to avoid fetching all objects at the same time.
|
||||||
"""
|
"""
|
||||||
return self._data[pageno * self.height: pageno * self.height + self.height]
|
return self._data[pageno * self.height : pageno * self.height + self.height]
|
||||||
|
|
||||||
# inits for different input types
|
# inits for different input types
|
||||||
|
|
||||||
@ -332,8 +332,9 @@ class EvMore(object):
|
|||||||
# no justification. Simple division by line
|
# no justification. Simple division by line
|
||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
|
|
||||||
self._data = ["\n".join(lines[i: i + self.height])
|
self._data = [
|
||||||
for i in range(0, len(lines), self.height)]
|
"\n".join(lines[i : i + self.height]) for i in range(0, len(lines), self.height)
|
||||||
|
]
|
||||||
self._npages = len(self._data)
|
self._npages = len(self._data)
|
||||||
self._paginator = self.paginator_index
|
self._paginator = self.paginator_index
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user