Skip to content

Commit

Permalink
Update pipkin
Browse files Browse the repository at this point in the history
  • Loading branch information
aivarannamaa committed Apr 2, 2022
1 parent 8bc86ac commit 89ecd81
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
4 changes: 4 additions & 0 deletions copy_libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cp ../pipkin/pipkin/*.py thonny/vendored_libs/pipkin
#pip install filelock -t thonny\vendored_libs
7 changes: 2 additions & 5 deletions thonny/vendored_libs/pipkin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@

logger = logging.getLogger("pipkin")

__version__ = "1.0b1"
__version__ = "1.0b2"


def error(msg):
msg = "ERROR: " + msg
if sys.stderr.isatty():
print("\x1b[31m", msg, "\x1b[0m", sep="", file=sys.stderr)
else:
print(msg, file=sys.stderr)
print(msg, file=sys.stderr)

return 1

Expand Down
2 changes: 1 addition & 1 deletion thonny/vendored_libs/pipkin/bare_metal.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def write_file_in_existing_dir(self, path: str, content: bytes) -> None:

try:
self._write_file_via_serial(path, content)
except ReadOnlyFilesystemError as e:
except ReadOnlyFilesystemError:
self._read_only_filesystem = True
self._write_file_via_mount(path, content)

Expand Down
12 changes: 4 additions & 8 deletions thonny/vendored_libs/pipkin/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def read(self, size: int, timeout: float = 10, timeout_is_soft: bool = False) ->
timer = TimeHelper(timeout)

while len(self._read_buffer) < size:
self._check_for_error()
self.check_for_error()

try:
self._read_buffer.extend(self._read_queue.get(True, timer.time_left))
Expand Down Expand Up @@ -80,7 +80,7 @@ def read_until(
assert isinstance(terminator, re.Pattern)

while True:
self._check_for_error()
self.check_for_error()

match = re.search(terminator, self._read_buffer)
if match:
Expand Down Expand Up @@ -115,7 +115,7 @@ def read_all(self, check_error: bool = True) -> bytes:
self._fetch_to_buffer()

if len(self._read_buffer) == 0 and check_error:
self._check_for_error()
self.check_for_error()

try:
return self._read_buffer
Expand All @@ -128,7 +128,7 @@ def read_all_expected(self, expected: bytes, timeout: float = None) -> bytes:
assert expected == actual, "Expected %r, got %r" % (expected, actual)
return actual

def _check_for_error(self) -> None:
def check_for_error(self) -> None:
if self._error is None:
return

Expand Down Expand Up @@ -187,10 +187,6 @@ def close(self) -> None:
raise NotImplementedError()


class ConnectionFailedException(ConnectionError):
pass


class ReadingTimeoutError(TimeoutError):
def __init__(self, read_bytes: bytes):
super().__init__(f"Read bytes: {read_bytes!r}")
Expand Down
4 changes: 2 additions & 2 deletions thonny/vendored_libs/pipkin/serial_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from logging import getLogger
from textwrap import dedent

from .connection import ConnectionFailedException, MicroPythonConnection
from .connection import MicroPythonConnection

OUTPUT_ENQ = b"\x05"
OUTPUT_ACK = b"\x06"
Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__(self, port, baudrate=115200, dtr=None, rts=None, skip_reader=False)
elif error.errno == 16:
message += "\n\n" + "Try restarting the device."

raise ConnectionFailedException(message) from error
raise ConnectionRefusedError(message) from error

if skip_reader:
self._reading_thread = None
Expand Down
4 changes: 2 additions & 2 deletions thonny/vendored_libs/pipkin/webrepl_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from logging import DEBUG, getLogger
from queue import Queue

from .connection import ConnectionFailedException, MicroPythonConnection
from .connection import MicroPythonConnection

logger = getLogger(__name__)

Expand Down Expand Up @@ -76,7 +76,7 @@ async def _ws_connect(self):
self._ws = await websockets.connect(self._url, ping_interval=None)
except OSError as e:
# print("\nCould not connect:", e, file=sys.stderr)
raise ConnectionFailedException(str(e)) from e
raise ConnectionRefusedError(str(e)) from e
logger.debug("GOT WS: %r", self._ws)

# read password prompt and send password
Expand Down

0 comments on commit 89ecd81

Please sign in to comment.