Merge pull request #3188 from volundmush/py_adjustment

Py adjustment
This commit is contained in:
Griatch 2023-05-21 10:49:16 +02:00 committed by GitHub
commit 5ea72f2db7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 13 deletions

View file

@ -171,7 +171,7 @@ Damage roll: 1d6
Here's the start of how the function could look:
```python
# in mygame/evadventure/utils.py
# in mygame/evadventure/time.py
_OBJ_STATS = """
|c{key}|n

View file

@ -179,7 +179,6 @@ def _run_code_snippet(
"""
# Try to retrieve the session
session = caller
if hasattr(caller, "sessions"):
sessions = caller.sessions.all()
@ -187,10 +186,11 @@ def _run_code_snippet(
if show_input:
for session in sessions:
data = {"text": (f">>> {pycode}", {"type": "py_input"}), "options": {"raw": True, "highlight": True}}
try:
caller.msg(">>> %s" % pycode, session=session, options={"raw": True})
caller.msg(session=session, **data)
except TypeError:
caller.msg(">>> %s" % pycode, options={"raw": True})
caller.msg(**data)
try:
# reroute standard output to game client console
@ -202,10 +202,7 @@ def _run_code_snippet(
self.caller = caller
def write(self, string):
if string.endswith("\n"):
self.caller.msg(string[:-1])
else:
self.caller.msg(string)
self.caller.msg(text=(string.rstrip("\n"), {"type": "py_output"}))
fake_std = FakeStd(caller)
sys.stdout = fake_std
@ -222,7 +219,7 @@ def _run_code_snippet(
t0 = time.time()
ret = eval(pycode_compiled, {}, available_vars)
t1 = time.time()
duration = " (runtime ~ %.4f ms)" % ((t1 - t0) * 1000)
duration = f" (runtime ~ {(t1 - t0) * 1000:.4f} ms)"
caller.msg(duration)
else:
ret = eval(pycode_compiled, {}, available_vars)
@ -246,9 +243,10 @@ def _run_code_snippet(
for session in sessions:
try:
caller.msg(ret, session=session, options={"raw": True, "client_raw": client_raw})
caller.msg((ret, {"type": "py_output"}), session=session, options={"raw": True, "client_raw": client_raw,
"highlight": True})
except TypeError:
caller.msg(ret, options={"raw": True, "client_raw": client_raw})
caller.msg((ret, {"type": "py_output"}), options={"raw": True, "client_raw": client_raw, "highlight": True})
def evennia_local_vars(caller):

View file

@ -56,7 +56,7 @@ class TestDedent(TestCase):
class TestListToString(TestCase):
"""
Default function header from utils.py:
Default function header from time.py:
list_to_string(inlist, sep=",", endsep=", and", addquote=False)
Examples:
@ -175,7 +175,7 @@ class TestANSIString(TestCase):
class TestTimeformat(TestCase):
"""
Default function header from utils.py:
Default function header from time.py:
time_format(seconds, style=0)
"""