Skip to content

Commit

Permalink
complete reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh committed May 30, 2023
1 parent 54fce34 commit 0f4fa99
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 33 deletions.
5 changes: 1 addition & 4 deletions belay/cli/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def update(packages: List[str] = Argument(None, help="Specific package(s) to upd
packages = packages if packages else None

for group in groups:
if packages is None:
group_packages = None
else:
group_packages = [x for x in packages if x in group.config.dependencies]
group_packages = None if packages is None else [x for x in packages if x in group.config.dependencies]

group.download(
packages=group_packages,
Expand Down
2 changes: 1 addition & 1 deletion belay/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def setup(
if f is None:
return wraps_partial(Device.setup, autoinit=autoinit, implementation=implementation, **kwargs) # type: ignore[reportGeneralTypeIssues]
if signature(f).parameters and autoinit:
raise ValueError(f"Method {f} decorated with " '"@Device.setup(autoinit=True)" ' "must have no arguments.")
raise ValueError(f"Method {f} decorated with @Device.setup(autoinit=True) must have no arguments.")

f.__belay__ = MethodMetadata(
executer=SetupExecuter,
Expand Down
5 changes: 1 addition & 4 deletions belay/device_sync_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ def preprocess_src_file(
tmp_dir = Path(tmp_dir)
src_file = Path(src_file)

if src_file.is_absolute():
transformed = tmp_dir / src_file.relative_to(tmp_dir.anchor)
else:
transformed = tmp_dir / src_file
transformed = tmp_dir / src_file.relative_to(tmp_dir.anchor) if src_file.is_absolute() else tmp_dir / src_file
transformed.parent.mkdir(parents=True, exist_ok=True)

if src_file.suffix == ".py":
Expand Down
5 changes: 1 addition & 4 deletions belay/packagemanager/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ def download(
if not packages:
return

if console:
cm = console.status("[bold green]Updating Dependencies")
else:
cm = nullcontext()
cm = console.status("[bold green]Updating Dependencies") if console else nullcontext()

def log(*args, **kwargs):
if console:
Expand Down
9 changes: 3 additions & 6 deletions belay/pyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def find(buf):
# loop until new data has arrived.
if time.time() > deadline:
raise PyboardError(
f"Timed out reading until {repr(ending)}\n" f" Received: {repr(self._consumed_buf)}"
f"Timed out reading until {repr(ending)}\n Received: {repr(self._consumed_buf)}"
)

if not self.serial.in_waiting:
Expand Down Expand Up @@ -533,10 +533,7 @@ def raw_paste_write(self, command_bytes):
self.read_until(b"\x04")

def exec_raw_no_follow(self, command):
if isinstance(command, bytes):
command_bytes = command
else:
command_bytes = bytes(command, encoding="utf8")
command_bytes = command if isinstance(command, bytes) else bytes(command, encoding="utf8")

# check we have a prompt
self.read_until(b">")
Expand Down Expand Up @@ -600,7 +597,7 @@ def fs_ls(self, src):
self.exec(cmd, data_consumer=stdout_write_bytes)

def fs_cat(self, src, chunk_size=256):
cmd = "with open('%s') as f:\n while 1:\n" " b=f.read(%u)\n if not b:break\n print(b,end='')" % (
cmd = "with open('%s') as f:\n while 1:\n b=f.read(%u)\n if not b:break\n print(b,end='')" % (
src,
chunk_size,
)
Expand Down
5 changes: 1 addition & 4 deletions belay/sync_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ def preprocess_src_file(
tmp_dir = Path(tmp_dir)
src_file = Path(src_file)

if src_file.is_absolute():
transformed = tmp_dir / src_file.relative_to(tmp_dir.anchor)
else:
transformed = tmp_dir / src_file
transformed = tmp_dir / src_file.relative_to(tmp_dir.anchor) if src_file.is_absolute() else tmp_dir / src_file
transformed.parent.mkdir(parents=True, exist_ok=True)

if src_file.suffix == ".py":
Expand Down
11 changes: 2 additions & 9 deletions belay/webrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,13 @@ def __init__(self, s: socket.socket):

def write(self, data):
data_len = len(data)
if data_len < 126:
# TODO: hardcoded "binary" type
hdr = struct.pack(">BB", 0x82, data_len)
else:
hdr = struct.pack(">BBH", 0x82, 126, data_len)
hdr = struct.pack(">BB", 130, data_len) if data_len < 126 else struct.pack(">BBH", 130, 126, data_len)
self.s.send(hdr)
self.s.send(data)

def writetext(self, data: bytes):
data_len = len(data)
if data_len < 126:
hdr = struct.pack(">BB", 0x81, data_len)
else:
hdr = struct.pack(">BBH", 0x81, 126, data_len)
hdr = struct.pack(">BB", 129, data_len) if data_len < 126 else struct.pack(">BBH", 129, 126, data_len)
self.s.send(hdr)
self.s.send(data)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def foo(a, b):

def test_device_traceback_execute(mocker, mock_device, tmp_path):
src_file = tmp_path / "main.py"
src_file.write_text("\n" "@device.task\n" "def f():\n" ' raise Exception("This is raised on-device.")')
src_file.write_text('\n@device.task\ndef f():\n raise Exception("This is raised on-device.")')
exception = belay.PyboardException(
"Traceback (most recent call last):\r\n"
' File "<stdin>", line 1, in <module>\r\n'
Expand Down

0 comments on commit 0f4fa99

Please sign in to comment.