Run black reformatter on code
This commit is contained in:
parent
4582eb4085
commit
bd3e31bf3c
178 changed files with 4511 additions and 3385 deletions
|
|
@ -69,8 +69,7 @@ from dataclasses import dataclass
|
|||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
from evennia.utils.utils import (
|
||||
variable_from_module, make_iter, all_from_module)
|
||||
from evennia.utils.utils import variable_from_module, make_iter, all_from_module
|
||||
from evennia.utils import logger
|
||||
from evennia.utils.utils import lazy_property
|
||||
from evennia.locks.lockhandler import LockHandler
|
||||
|
|
@ -86,6 +85,7 @@ class FileHelpEntry:
|
|||
help command.
|
||||
|
||||
"""
|
||||
|
||||
key: str
|
||||
aliases: list
|
||||
help_category: str
|
||||
|
|
@ -147,7 +147,7 @@ class FileHelpEntry:
|
|||
"""
|
||||
try:
|
||||
return reverse(
|
||||
'help-entry-detail',
|
||||
"help-entry-detail",
|
||||
kwargs={"category": slugify(self.help_category), "topic": slugify(self.key)},
|
||||
)
|
||||
except Exception:
|
||||
|
|
@ -192,8 +192,7 @@ class FileHelpStorageHandler:
|
|||
"""
|
||||
Initialize the storage.
|
||||
"""
|
||||
self.help_file_modules = [str(part).strip()
|
||||
for part in make_iter(help_file_modules)]
|
||||
self.help_file_modules = [str(part).strip() for part in make_iter(help_file_modules)]
|
||||
self.help_entries = []
|
||||
self.help_entries_dict = {}
|
||||
self.load()
|
||||
|
|
@ -206,13 +205,11 @@ class FileHelpStorageHandler:
|
|||
loaded_help_dicts = []
|
||||
|
||||
for module_or_path in self.help_file_modules:
|
||||
help_dict_list = variable_from_module(
|
||||
module_or_path, variable="HELP_ENTRY_DICTS"
|
||||
)
|
||||
help_dict_list = variable_from_module(module_or_path, variable="HELP_ENTRY_DICTS")
|
||||
if not help_dict_list:
|
||||
help_dict_list = [
|
||||
dct for dct in all_from_module(module_or_path).values()
|
||||
if isinstance(dct, dict)]
|
||||
dct for dct in all_from_module(module_or_path).values() if isinstance(dct, dict)
|
||||
]
|
||||
if help_dict_list:
|
||||
loaded_help_dicts.extend(help_dict_list)
|
||||
else:
|
||||
|
|
@ -223,19 +220,23 @@ class FileHelpStorageHandler:
|
|||
unique_help_entries = {}
|
||||
|
||||
for dct in loaded_help_dicts:
|
||||
key = dct.get('key').lower().strip()
|
||||
category = dct.get('category', _DEFAULT_HELP_CATEGORY).strip()
|
||||
aliases = list(dct.get('aliases', []))
|
||||
entrytext = dct.get('text', '')
|
||||
locks = dct.get('locks', '')
|
||||
key = dct.get("key").lower().strip()
|
||||
category = dct.get("category", _DEFAULT_HELP_CATEGORY).strip()
|
||||
aliases = list(dct.get("aliases", []))
|
||||
entrytext = dct.get("text", "")
|
||||
locks = dct.get("locks", "")
|
||||
|
||||
if not key and entrytext:
|
||||
logger.error(f"Cannot load file-help-entry (missing key or text): {dct}")
|
||||
continue
|
||||
|
||||
unique_help_entries[key] = FileHelpEntry(
|
||||
key=key, help_category=category, aliases=aliases, lock_storage=locks,
|
||||
entrytext=entrytext)
|
||||
key=key,
|
||||
help_category=category,
|
||||
aliases=aliases,
|
||||
lock_storage=locks,
|
||||
entrytext=entrytext,
|
||||
)
|
||||
|
||||
self.help_entries_dict = unique_help_entries
|
||||
self.help_entries = list(unique_help_entries.values())
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ class TestParseSubtopics(TestCase):
|
|||
"""
|
||||
self.maxDiff = None
|
||||
|
||||
entry = dedent("""
|
||||
entry = dedent(
|
||||
"""
|
||||
Main topic text
|
||||
# subtopics
|
||||
## foo
|
||||
|
|
@ -36,7 +37,9 @@ class TestParseSubtopics(TestCase):
|
|||
Bar subcategory
|
||||
### moo
|
||||
Bar/Moo subcategory
|
||||
""", indent=0)
|
||||
""",
|
||||
indent=0,
|
||||
)
|
||||
expected = {
|
||||
None: "Main topic text",
|
||||
"foo": {
|
||||
|
|
@ -45,15 +48,10 @@ class TestParseSubtopics(TestCase):
|
|||
None: "\nFoo/Moo subsub-category\n",
|
||||
"dum": {
|
||||
None: "\nFoo/Moo/Dum subsubsub-category\n",
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
"bar": {
|
||||
None: "\nBar subcategory\n",
|
||||
"moo": {
|
||||
None: "\nBar/Moo subcategory"
|
||||
}
|
||||
}
|
||||
"bar": {None: "\nBar subcategory\n", "moo": {None: "\nBar/Moo subcategory"}},
|
||||
}
|
||||
|
||||
actual_result = help_utils.parse_entry_for_subcategories(entry)
|
||||
|
|
@ -65,28 +63,30 @@ class TestParseSubtopics(TestCase):
|
|||
|
||||
"""
|
||||
|
||||
entry = dedent("""
|
||||
entry = dedent(
|
||||
"""
|
||||
Main topic text
|
||||
# SUBTOPICS
|
||||
## creating extra stuff
|
||||
Help on creating extra stuff.
|
||||
""", indent=0)
|
||||
""",
|
||||
indent=0,
|
||||
)
|
||||
expected = {
|
||||
None: "Main topic text",
|
||||
"creating extra stuff": {
|
||||
None: "\nHelp on creating extra stuff."
|
||||
}
|
||||
"creating extra stuff": {None: "\nHelp on creating extra stuff."},
|
||||
}
|
||||
|
||||
actual_result = help_utils.parse_entry_for_subcategories(entry)
|
||||
self.assertEqual(expected, actual_result)
|
||||
|
||||
|
||||
# test filehelp system
|
||||
|
||||
HELP_ENTRY_DICTS = [
|
||||
{
|
||||
"key": "evennia",
|
||||
"aliases": ['ev'],
|
||||
"aliases": ["ev"],
|
||||
"category": "General",
|
||||
"text": """
|
||||
Evennia is a MUD game server in Python.
|
||||
|
|
@ -105,7 +105,7 @@ HELP_ENTRY_DICTS = [
|
|||
|
||||
There is also a discord channel you can find from the sidebard on evennia.com.
|
||||
|
||||
"""
|
||||
""",
|
||||
},
|
||||
{
|
||||
"key": "building",
|
||||
|
|
@ -114,12 +114,11 @@ HELP_ENTRY_DICTS = [
|
|||
Evennia comes with a bunch of default building commands. You can
|
||||
find a building tutorial in the evennia documentation.
|
||||
|
||||
"""
|
||||
}
|
||||
""",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
||||
class TestFileHelp(TestCase):
|
||||
"""
|
||||
Test the File-help system
|
||||
|
|
@ -135,7 +134,7 @@ class TestFileHelp(TestCase):
|
|||
result = storage.all()
|
||||
|
||||
for inum, helpentry in enumerate(result):
|
||||
self.assertEqual(HELP_ENTRY_DICTS[inum]['key'], helpentry.key)
|
||||
self.assertEqual(HELP_ENTRY_DICTS[inum].get('aliases', []), helpentry.aliases)
|
||||
self.assertEqual(HELP_ENTRY_DICTS[inum]['category'], helpentry.help_category)
|
||||
self.assertEqual(HELP_ENTRY_DICTS[inum]['text'], helpentry.entrytext)
|
||||
self.assertEqual(HELP_ENTRY_DICTS[inum]["key"], helpentry.key)
|
||||
self.assertEqual(HELP_ENTRY_DICTS[inum].get("aliases", []), helpentry.aliases)
|
||||
self.assertEqual(HELP_ENTRY_DICTS[inum]["category"], helpentry.help_category)
|
||||
self.assertEqual(HELP_ENTRY_DICTS[inum]["text"], helpentry.entrytext)
|
||||
|
|
|
|||
|
|
@ -19,11 +19,9 @@ _LUNR_EXCEPTION = None
|
|||
_LUNR_GET_BUILDER = None
|
||||
_LUNR_BUILDER_PIPELINE = None
|
||||
|
||||
_RE_HELP_SUBTOPICS_START = re.compile(
|
||||
r"^\s*?#\s*?subtopics\s*?$", re.I + re.M)
|
||||
_RE_HELP_SUBTOPICS_START = re.compile(r"^\s*?#\s*?subtopics\s*?$", re.I + re.M)
|
||||
_RE_HELP_SUBTOPIC_SPLIT = re.compile(r"^\s*?(\#{2,6}\s*?\w+?[a-z0-9 \-\?!,\.]*?)$", re.M + re.I)
|
||||
_RE_HELP_SUBTOPIC_PARSE = re.compile(
|
||||
r"^(?P<nesting>\#{2,6})\s*?(?P<name>.*?)$", re.I + re.M)
|
||||
_RE_HELP_SUBTOPIC_PARSE = re.compile(r"^(?P<nesting>\#{2,6})\s*?(?P<name>.*?)$", re.I + re.M)
|
||||
|
||||
MAX_SUBTOPIC_NESTING = 5
|
||||
|
||||
|
|
@ -57,6 +55,7 @@ def help_search_with_index(query, candidate_entries, suggestion_maxnum=5, fields
|
|||
from lunr import get_default_builder as _LUNR_GET_BUILDER
|
||||
from lunr import stop_word_filter
|
||||
from lunr.stemmer import stemmer
|
||||
|
||||
# from lunr.trimmer import trimmer
|
||||
|
||||
# pre-create a lunr index-builder pipeline where we've removed some of
|
||||
|
|
@ -90,12 +89,7 @@ def help_search_with_index(query, candidate_entries, suggestion_maxnum=5, fields
|
|||
builder.pipeline.reset()
|
||||
builder.pipeline.add(*_LUNR_BUILDER_PIPELINE)
|
||||
|
||||
search_index = _LUNR(
|
||||
ref="key",
|
||||
fields=fields,
|
||||
documents=indx,
|
||||
builder=builder
|
||||
)
|
||||
search_index = _LUNR(ref="key", fields=fields, documents=indx, builder=builder)
|
||||
|
||||
try:
|
||||
matches = search_index.search(query)[:suggestion_maxnum]
|
||||
|
|
@ -175,7 +169,7 @@ def parse_entry_for_subcategories(entry):
|
|||
|
||||
"""
|
||||
topic, *subtopics = _RE_HELP_SUBTOPICS_START.split(entry, maxsplit=1)
|
||||
structure = {None: topic.strip('\n')}
|
||||
structure = {None: topic.strip("\n")}
|
||||
|
||||
if subtopics:
|
||||
subtopics = subtopics[0]
|
||||
|
|
@ -193,12 +187,13 @@ def parse_entry_for_subcategories(entry):
|
|||
if subtopic_match:
|
||||
# a new sub(-sub..) category starts.
|
||||
mdict = subtopic_match.groupdict()
|
||||
subtopic = mdict['name'].lower().strip()
|
||||
new_nesting = len(mdict['nesting']) - 1
|
||||
subtopic = mdict["name"].lower().strip()
|
||||
new_nesting = len(mdict["nesting"]) - 1
|
||||
|
||||
if new_nesting > MAX_SUBTOPIC_NESTING:
|
||||
raise RuntimeError(
|
||||
f"Can have max {MAX_SUBTOPIC_NESTING} levels of nested help subtopics.")
|
||||
f"Can have max {MAX_SUBTOPIC_NESTING} levels of nested help subtopics."
|
||||
)
|
||||
|
||||
nestdiff = new_nesting - current_nesting
|
||||
if nestdiff < 0:
|
||||
|
|
@ -226,7 +221,5 @@ def parse_entry_for_subcategories(entry):
|
|||
if key in dct:
|
||||
dct = dct[key]
|
||||
else:
|
||||
dct[key] = {
|
||||
None: part
|
||||
}
|
||||
dct[key] = {None: part}
|
||||
return structure
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue