Skip to content

Commit

Permalink
Merge pull request #130 from BrianPugh/remove-stacktrace
Browse files Browse the repository at this point in the history
Fully remove belay-internal stacktrace for install/run/exec cli commands
  • Loading branch information
BrianPugh authored Apr 24, 2023
2 parents ee403a1 + b7f6b74 commit 279d076
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
14 changes: 14 additions & 0 deletions belay/cli/common.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
from belay.pyboard import PyboardException

help_port = "Port (like /dev/ttyUSB0) or WebSocket (like ws://192.168.1.100) of device."
help_password = "Password for communication methods (like WebREPL) that require authentication." # nosec # noqa: S105


class remove_stacktrace: # noqa: N801
def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
if exc_type is not None and issubclass(exc_type, PyboardException):
print(exc_value)
return True # suppress the full stack trace
else:
return False # let other exceptions propagate normally
5 changes: 3 additions & 2 deletions belay/cli/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typer import Argument, Option

from belay import Device
from belay.cli.common import help_password, help_port
from belay.cli.common import help_password, help_port, remove_stacktrace


def exec(
Expand All @@ -13,5 +13,6 @@ def exec(
):
"""Execute python statement on-device."""
device = Device(port, password=password)
device(statement)
with remove_stacktrace():
device(statement)
device.close()
5 changes: 3 additions & 2 deletions belay/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typer import Argument, Option

from belay import Device
from belay.cli.common import help_password, help_port
from belay.cli.common import help_password, help_port, remove_stacktrace
from belay.cli.sync import sync_device as _sync_device
from belay.project import find_project_folder, load_groups, load_pyproject

Expand Down Expand Up @@ -97,7 +97,8 @@ def progress_update(description=None, **kwargs):

if run:
content = run.read_text()
device(content)
with remove_stacktrace():
device(content)
return

# Reset device so ``main.py`` has a chance to execute.
Expand Down
4 changes: 2 additions & 2 deletions belay/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typer import Argument, Option

from belay import Device
from belay.cli.common import help_password, help_port
from belay.cli.common import help_password, help_port, remove_stacktrace


def run(
Expand All @@ -23,5 +23,5 @@ def run(
"""
content = file.read_text()
with Device(port, password=password) as device:
with Device(port, password=password) as device, remove_stacktrace():
device(content)

0 comments on commit 279d076

Please sign in to comment.