Skip to content

Commit

Permalink
Merge pull request #64 from BrianPugh/codecov
Browse files Browse the repository at this point in the history
Fix Double Responses
  • Loading branch information
BrianPugh authored Dec 7, 2022
2 parents 6e7fb5a + 1da6769 commit 229e0f5
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 217 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. image:: https://raw.githubusercontent.com/BrianPugh/belay/main/assets/logo_white_400w.png

|Python compat| |PyPi| |GHA tests| |readthedocs|
|Python compat| |PyPi| |GHA tests| |Codecov report| |readthedocs|


.. inclusion-marker-do-not-remove
Expand Down
1 change: 1 addition & 0 deletions belay/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ def __call__(
cmd = minify_code(cmd)

if isexpression(cmd):
# Belay Tasks are inherently expressions as well.
cmd = f"print('_BELAYR' + repr({cmd}))"

if (
Expand Down
10 changes: 3 additions & 7 deletions belay/executers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,13 @@ def __call__(

name = f.__name__
src_code, src_lineno, src_file = getsource(f)
src_lineno -= 1 # Because of the injected ``@__belay`` decorator below

# Add the __belay decorator for handling result serialization.
src_code = f"@__belay({repr(name)})\n" + src_code

# Send the source code over to the device.
self._belay_device(src_code, minify=minify)

@wraps(f)
def func_executer(*args, **kwargs):
cmd = f"_belay_{name}(*{repr(args)}, **{repr(kwargs)})"
cmd = f"{name}(*{repr(args)}, **{repr(kwargs)})"

return self._belay_device._traceback_execute(
src_file, src_lineno, name, cmd, record=record
Expand All @@ -117,7 +113,7 @@ def gen_executer(*args, **kwargs):
)
# Step 1: Create the on-device generator
gen_identifier = random_python_identifier()
cmd = f"{gen_identifier} = _belay_{name}(*{repr(args)}, **{repr(kwargs)})"
cmd = f"{gen_identifier} = {name}(*{repr(args)}, **{repr(kwargs)})"
self._belay_device._traceback_execute(
src_file, src_lineno, name, cmd, record=False
)
Expand All @@ -127,7 +123,7 @@ def gen_inner():
send_val = None
try:
while True:
cmd = f"__belay_gen_next({gen_identifier}, {repr(send_val)})"
cmd = f"__belay_next({gen_identifier}, {repr(send_val)})"
send_val = yield self._belay_device._traceback_execute(
src_file, src_lineno, name, cmd, record=False
)
Expand Down
4 changes: 0 additions & 4 deletions belay/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ def isexpression(code: str) -> bool:
``True`` if ``code`` is an expression; returns
``False`` otherwise (statement or invalid).
"""
if code.startswith("__belay_gen_next("):
# Special expression used internally for generators
return False

try:
compile(code, "<stdin>", "eval")
except SyntaxError:
Expand Down
23 changes: 2 additions & 21 deletions belay/snippets/startup.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
import os, sys
def __belay(name):
def inner(f):
def func_wrapper(*args, **kwargs):
res = f(*args, **kwargs)
print("_BELAYR" + repr(res))
return res
def gen_wrapper(*args, **kwargs):
send_val = None
gen = f(*args, **kwargs)
try:
while True:
res = gen.send(send_val)
print("_BELAYR" + repr(res))
send_val = yield res
except StopIteration:
pass
globals()["_belay_" + name] = gen_wrapper if isinstance(f, type(lambda: (yield))) else func_wrapper
return f
return inner
def __belay_gen_next(x, val):
def __belay_next(x, val):
try:
x.send(val)
return x.send(val)
except StopIteration:
print("_BELAYS")
Loading

0 comments on commit 229e0f5

Please sign in to comment.