From 89ecd815f012a218610f8e296a762927ec3170ab Mon Sep 17 00:00:00 2001 From: Aivar Annamaa Date: Sat, 2 Apr 2022 10:58:06 +0300 Subject: [PATCH] Update pipkin --- copy_libs.sh | 4 ++++ thonny/vendored_libs/pipkin/__init__.py | 7 ++----- thonny/vendored_libs/pipkin/bare_metal.py | 2 +- thonny/vendored_libs/pipkin/connection.py | 12 ++++-------- thonny/vendored_libs/pipkin/serial_connection.py | 4 ++-- thonny/vendored_libs/pipkin/webrepl_connection.py | 4 ++-- 6 files changed, 15 insertions(+), 18 deletions(-) create mode 100755 copy_libs.sh diff --git a/copy_libs.sh b/copy_libs.sh new file mode 100755 index 000000000..e8f214188 --- /dev/null +++ b/copy_libs.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +cp ../pipkin/pipkin/*.py thonny/vendored_libs/pipkin +#pip install filelock -t thonny\vendored_libs diff --git a/thonny/vendored_libs/pipkin/__init__.py b/thonny/vendored_libs/pipkin/__init__.py index de988abf4..5f53f54e2 100644 --- a/thonny/vendored_libs/pipkin/__init__.py +++ b/thonny/vendored_libs/pipkin/__init__.py @@ -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 diff --git a/thonny/vendored_libs/pipkin/bare_metal.py b/thonny/vendored_libs/pipkin/bare_metal.py index 343e16e80..c322adcae 100644 --- a/thonny/vendored_libs/pipkin/bare_metal.py +++ b/thonny/vendored_libs/pipkin/bare_metal.py @@ -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) diff --git a/thonny/vendored_libs/pipkin/connection.py b/thonny/vendored_libs/pipkin/connection.py index fc1782fa4..cf8706aa0 100644 --- a/thonny/vendored_libs/pipkin/connection.py +++ b/thonny/vendored_libs/pipkin/connection.py @@ -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)) @@ -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: @@ -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 @@ -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 @@ -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}") diff --git a/thonny/vendored_libs/pipkin/serial_connection.py b/thonny/vendored_libs/pipkin/serial_connection.py index 205cc7287..abe23aeee 100644 --- a/thonny/vendored_libs/pipkin/serial_connection.py +++ b/thonny/vendored_libs/pipkin/serial_connection.py @@ -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" @@ -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 diff --git a/thonny/vendored_libs/pipkin/webrepl_connection.py b/thonny/vendored_libs/pipkin/webrepl_connection.py index cec4b71e9..ab03e0b0e 100644 --- a/thonny/vendored_libs/pipkin/webrepl_connection.py +++ b/thonny/vendored_libs/pipkin/webrepl_connection.py @@ -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__) @@ -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