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 8360f178de
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: Here's the start of how the function could look:
```python ```python
# in mygame/evadventure/utils.py # in mygame/evadventure/time.py
_OBJ_STATS = """ _OBJ_STATS = """
|c{key}|n |c{key}|n

View file

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

View file

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