From 1c43a36df10a2cdd22dfff52dc6e4daee391a862 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:25:05 +0000 Subject: [PATCH 1/2] =?UTF-8?q?ci(pre-commit.ci):=20=E2=AC=86=20pre-commit?= =?UTF-8?q?=20autoupdate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.4.0...v5.0.0) - https://github.com/charliermarsh/ruff-pre-commit → https://github.com/astral-sh/ruff-pre-commit - [github.com/astral-sh/ruff-pre-commit: v0.0.255 → v0.8.6](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.255...v0.8.6) - [github.com/pycqa/isort: 5.12.0 → 5.13.2](https://github.com/pycqa/isort/compare/5.12.0...5.13.2) - [github.com/psf/black: 23.1.0 → 24.10.0](https://github.com/psf/black/compare/23.1.0...24.10.0) - [github.com/python-poetry/poetry: 1.4.1 → 2.0.0](https://github.com/python-poetry/poetry/compare/1.4.1...2.0.0) --- .pre-commit-config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7d1978ac..0e1e56ba 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,28 +19,28 @@ exclude: | repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: debug-statements - id: detect-private-key - id: end-of-file-fixer - id: check-executables-have-shebangs - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.255" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.8.6" hooks: - id: ruff args: - --fix - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/python-poetry/poetry - rev: 1.4.1 + rev: 2.0.0 hooks: - id: poetry-check files: "^(pyproject.toml|poetry.lock)$" From 92f0531992e8ec8416c81aeb34fc787611d7f868 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:25:17 +0000 Subject: [PATCH 2/2] =?UTF-8?q?ci(pre-commit.ci):=20=F0=9F=8E=A8=20Auto=20?= =?UTF-8?q?format=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- micropy/app/stubs.py | 2 +- micropy/config/__init__.py | 2 +- micropy/data/__init__.py | 2 +- micropy/exceptions.py | 3 +- micropy/logger.py | 2 +- micropy/packages/__init__.py | 2 +- micropy/project/modules/__init__.py | 9 +- micropy/project/modules/templates.py | 1 - micropy/project/template.py | 8 +- micropy/pyd/__init__.py | 16 ++-- micropy/pyd/abc.py | 84 +++++++------------ micropy/pyd/backend_rshell.py | 3 +- micropy/pyd/backend_upydevice.py | 4 +- micropy/stubs/__init__.py | 12 +-- micropy/stubs/repositories/__init__.py | 4 +- micropy/stubs/source.py | 3 +- micropy/utils/helpers.py | 22 ++--- micropy/utils/stub.py | 1 + micropy/utils/types.py | 3 +- tests/data/esp32_test_stub/stubs/machine.py | 1 + tests/data/esp8266_test_stub/stubs/machine.py | 1 + .../esp32_test_stub/stubs/machine.py | 1 + .../esp8266_test_stub/stubs/machine.py | 1 + 23 files changed, 80 insertions(+), 107 deletions(-) diff --git a/micropy/app/stubs.py b/micropy/app/stubs.py index 643332b2..ec656090 100644 --- a/micropy/app/stubs.py +++ b/micropy/app/stubs.py @@ -179,7 +179,7 @@ def _get_desc(name: str, cfg: dict): pyb.run_script(create_stubs, DevicePath(dev_path)) except Exception as e: # TODO: Handle more usage cases - log.error(f"Failed to execute script: {str(e)}", exception=e) + log.error(f"Failed to execute script: {e!s}", exception=e) raise log.success("Done!") log.info("Copying stubs...") diff --git a/micropy/config/__init__.py b/micropy/config/__init__.py index 25790633..60bb456c 100644 --- a/micropy/config/__init__.py +++ b/micropy/config/__init__.py @@ -4,4 +4,4 @@ from .config_dict import DictConfigSource from .config_json import JSONConfigSource -__all__ = ["Config", "JSONConfigSource", "DictConfigSource"] +__all__ = ["Config", "DictConfigSource", "JSONConfigSource"] diff --git a/micropy/data/__init__.py b/micropy/data/__init__.py index 5c8e4cc8..79447349 100644 --- a/micropy/data/__init__.py +++ b/micropy/data/__init__.py @@ -8,7 +8,7 @@ from pathlib import Path -__all__ = ["ROOT", "SCHEMAS", "REPO_SOURCES", "FILES", "STUB_DIR", "LOG_FILE", "STUBBER"] +__all__ = ["FILES", "LOG_FILE", "REPO_SOURCES", "ROOT", "SCHEMAS", "STUBBER", "STUB_DIR"] # Paths MOD_PATH = Path(__file__).parent diff --git a/micropy/exceptions.py b/micropy/exceptions.py index 94cf3510..f28a2f3e 100644 --- a/micropy/exceptions.py +++ b/micropy/exceptions.py @@ -1,4 +1,5 @@ """Micropy Exceptions.""" + from __future__ import annotations @@ -21,7 +22,7 @@ class StubValidationError(StubError): """Raised when a stub fails validation.""" def __init__(self, path, errors, *args, **kwargs): - msg = f"Stub at[{str(path)}] encountered" f" the following validation errors: {str(errors)}" + msg = f"Stub at[{path!s}] encountered" f" the following validation errors: {errors!s}" super().__init__(msg, *args, **kwargs) def __str__(self): diff --git a/micropy/logger.py b/micropy/logger.py index 80988741..953c202c 100644 --- a/micropy/logger.py +++ b/micropy/logger.py @@ -254,7 +254,7 @@ def exception(self, error, **kwargs): """ name = type(error).__name__ - msg = f"{name}: {str(error)}" + msg = f"{name}: {error!s}" return self.echo(msg, log="exception", title_color="red", fg="red", accent="red", **kwargs) def success(self, msg, **kwargs): diff --git a/micropy/packages/__init__.py b/micropy/packages/__init__.py index 64f79da6..4dc16f76 100644 --- a/micropy/packages/__init__.py +++ b/micropy/packages/__init__.py @@ -43,8 +43,8 @@ def create_dependency_source( __all__ = [ + "LocalDependencySource", "Package", "PackageDependencySource", - "LocalDependencySource", "create_dependency_source", ] diff --git a/micropy/project/modules/__init__.py b/micropy/project/modules/__init__.py index 25eadb9f..070765b8 100644 --- a/micropy/project/modules/__init__.py +++ b/micropy/project/modules/__init__.py @@ -1,16 +1,15 @@ """Project Modules.""" - from .modules import HookProxy, ProjectModule from .packages import DevPackagesModule, PackagesModule from .stubs import StubsModule from .templates import TemplatesModule __all__ = [ - "TemplatesModule", - "PackagesModule", - "StubsModule", - "ProjectModule", "DevPackagesModule", "HookProxy", + "PackagesModule", + "ProjectModule", + "StubsModule", + "TemplatesModule", ] diff --git a/micropy/project/modules/templates.py b/micropy/project/modules/templates.py index 69f0be7b..6e0bbe45 100644 --- a/micropy/project/modules/templates.py +++ b/micropy/project/modules/templates.py @@ -1,6 +1,5 @@ """Project Templates Module.""" - from micropy.project.modules import ProjectModule from micropy.project.template import TemplateProvider diff --git a/micropy/project/template.py b/micropy/project/template.py index 3ae97feb..0bf17aa6 100644 --- a/micropy/project/template.py +++ b/micropy/project/template.py @@ -296,7 +296,7 @@ def render_to(self, name, parent_dir, *args, **kwargs): """ template = self.get(name, **kwargs) - self.log.debug(f"Loaded: {str(template)}") + self.log.debug(f"Loaded: {template!s}") if self.run_checks: self.log.debug(f"Verifying {template} requirements...") template.run_checks() @@ -305,7 +305,7 @@ def render_to(self, name, parent_dir, *args, **kwargs): self.log.debug(f"Create: {out_dir}") parent_dir.mkdir(exist_ok=True) out_dir.parent.mkdir(exist_ok=True, parents=True) - self.log.debug(f"Rendered: {name} to {str(out_dir)}") + self.log.debug(f"Rendered: {name} to {out_dir!s}") self.log.info(f"$[{name.capitalize()}] File Generated!") stream = template.render_stream() return stream.dump(str(out_dir)) @@ -326,13 +326,13 @@ def update(self, name, root_dir, **kwargs): """ template = self.get(name, **kwargs) - self.log.debug(f"Loaded: {str(template)}") + self.log.debug(f"Loaded: {template!s}") try: template.update(root_dir) except FileNotFoundError: self.log.debug("Template does not exist!") return self.render_to(name, root_dir, **kwargs) - self.log.debug(f"Updated: {str(template)}") + self.log.debug(f"Updated: {template!s}") return template @property diff --git a/micropy/pyd/__init__.py b/micropy/pyd/__init__.py index 0d93aaa7..976bef1f 100644 --- a/micropy/pyd/__init__.py +++ b/micropy/pyd/__init__.py @@ -13,16 +13,16 @@ from .pydevice import PyDevice __all__ = [ - "PyDevice", "ConsumerDelegate", - "ProgressStreamConsumer", - "StreamHandlers", - "MessageHandlers", - "PyDeviceConsumer", + "DevicePath", + "HostPath", "MessageConsumer", - "StreamConsumer", + "MessageHandlers", "MetaPyDevice", "MetaPyDeviceBackend", - "DevicePath", - "HostPath", + "ProgressStreamConsumer", + "PyDevice", + "PyDeviceConsumer", + "StreamConsumer", + "StreamHandlers", ] diff --git a/micropy/pyd/abc.py b/micropy/pyd/abc.py index 28793d33..176b0047 100644 --- a/micropy/pyd/abc.py +++ b/micropy/pyd/abc.py @@ -10,80 +10,65 @@ class StartHandler(Protocol): - def __call__(self, *, name: str = None, size: int | None = None) -> Any: - ... + def __call__(self, *, name: str = None, size: int | None = None) -> Any: ... class UpdateHandler(Protocol): - def __call__(self, *, size: int | None = None) -> Any: - ... + def __call__(self, *, size: int | None = None) -> Any: ... class EndHandler(Protocol): - def __call__(self) -> Any: - ... + def __call__(self) -> Any: ... class MessageHandler(Protocol): - def __call__(self, data: AnyStr) -> Any: - ... + def __call__(self, data: AnyStr) -> Any: ... class StreamConsumer(Protocol): @property @abc.abstractmethod - def on_start(self) -> StartHandler: - ... + def on_start(self) -> StartHandler: ... @property @abc.abstractmethod - def on_update(self) -> UpdateHandler: - ... + def on_update(self) -> UpdateHandler: ... @property @abc.abstractmethod - def on_end(self) -> EndHandler: - ... + def on_end(self) -> EndHandler: ... class MessageConsumer(Protocol): @property @abc.abstractmethod - def on_message(self) -> MessageHandler: - ... + def on_message(self) -> MessageHandler: ... -class PyDeviceConsumer(MessageConsumer, StreamConsumer, Protocol): - ... +class PyDeviceConsumer(MessageConsumer, StreamConsumer, Protocol): ... class MetaPyDeviceBackend(abc.ABC): location: str @abc.abstractmethod - def establish(self, target: str) -> MetaPyDeviceBackend: - ... + def establish(self, target: str) -> MetaPyDeviceBackend: ... @abc.abstractmethod - def connect(self) -> None: - ... + def connect(self) -> None: ... @abc.abstractmethod - def disconnect(self) -> None: - ... + def disconnect(self) -> None: ... @abc.abstractmethod - def reset(self) -> None: - ... + def reset(self) -> None: ... @abc.abstractmethod - def resolve_path(self, target_path: DevicePath | str | Path) -> DevicePath: - ... + def resolve_path(self, target_path: DevicePath | str | Path) -> DevicePath: ... @property @abc.abstractmethod - def connected(self) -> bool: - ... + def connected(self) -> bool: ... @abc.abstractmethod def push_file( @@ -93,8 +78,7 @@ def push_file( *, consumer: PyDeviceConsumer | None, **kwargs, - ) -> None: - ... + ) -> None: ... @abc.abstractmethod def pull_file( @@ -104,16 +88,13 @@ def pull_file( *, consumer: PyDeviceConsumer | None, **kwargs, - ) -> None: - ... + ) -> None: ... @abc.abstractmethod - def list_dir(self, path: DevicePath) -> list[DevicePath]: - ... + def list_dir(self, path: DevicePath) -> list[DevicePath]: ... @abc.abstractmethod - def remove(self, path: DevicePath) -> None: - ... + def remove(self, path: DevicePath) -> None: ... @abc.abstractmethod def copy_dir( @@ -123,12 +104,10 @@ def copy_dir( *, consumer: PyDeviceConsumer | None, **kwargs, - ): - ... + ): ... @abc.abstractmethod - def eval(self, command: str, *, consumer: MessageConsumer | None = None): - ... + def eval(self, command: str, *, consumer: MessageConsumer | None = None): ... @abc.abstractmethod def eval_script( @@ -137,8 +116,7 @@ def eval_script( target_path: DevicePath | None = None, *, consumer: PyDeviceConsumer | None = None, - ): - ... + ): ... AnyBackend = TypeVar("AnyBackend", bound=MetaPyDeviceBackend) @@ -150,29 +128,23 @@ class MetaPyDevice(abc.ABC, Generic[AnyBackend]): message_consumer: MessageConsumer | None @abc.abstractmethod - def connect(self) -> None: - ... + def connect(self) -> None: ... @abc.abstractmethod - def disconnect(self) -> None: - ... + def disconnect(self) -> None: ... @abc.abstractmethod - def copy_to(self, source_path: HostPath, target_path: DevicePath) -> None: - ... + def copy_to(self, source_path: HostPath, target_path: DevicePath) -> None: ... @abc.abstractmethod def copy_from( self, source_path: DevicePath, target_path: HostPath, *, verify_integrity: bool = True - ) -> None: - ... + ) -> None: ... @abc.abstractmethod - def remove(self, target_path: DevicePath) -> None: - ... + def remove(self, target_path: DevicePath) -> None: ... @abc.abstractmethod def run_script( self, content: AnyStr | StringIO | BytesIO, target_path: DevicePath | None = None - ): - ... + ): ... diff --git a/micropy/pyd/backend_rshell.py b/micropy/pyd/backend_rshell.py index a235816c..5be8c9c5 100644 --- a/micropy/pyd/backend_rshell.py +++ b/micropy/pyd/backend_rshell.py @@ -22,8 +22,7 @@ class RShell: ASCII_XFER: bool QUIET: bool - def connect(self, port: str): - ... + def connect(self, port: str): ... try: diff --git a/micropy/pyd/backend_upydevice.py b/micropy/pyd/backend_upydevice.py index 83476933..413ffca4 100644 --- a/micropy/pyd/backend_upydevice.py +++ b/micropy/pyd/backend_upydevice.py @@ -203,7 +203,7 @@ def write_file( target_path = self.resolve_path(target_path) self._pydevice.cmd("import gc") self._pydevice.cmd("import ubinascii") - self._pydevice.cmd(f"f = open('{str(target_path)}', 'wb')") + self._pydevice.cmd(f"f = open('{target_path!s}', 'wb')") content_iter = ( iterutils.chunked_iter(contents, self.BUFFER_SIZE) @@ -212,7 +212,7 @@ def write_file( ) content_size = len(contents) - consumer.on_start(name=f"Writing {str(target_path)}", size=content_size) + consumer.on_start(name=f"Writing {target_path!s}", size=content_size) for chunk in content_iter: cmd = ( diff --git a/micropy/stubs/__init__.py b/micropy/stubs/__init__.py index 56d659e9..63741c6a 100644 --- a/micropy/stubs/__init__.py +++ b/micropy/stubs/__init__.py @@ -16,15 +16,15 @@ from .stubs import StubManager __all__ = [ - "StubManager", - "source", - "StubsManifest", - "StubPackage", "AnyStubPackage", - "StubRepository", "MicropyStubPackage", - "MicropythonStubsPackage", "MicropythonStubsManifest", + "MicropythonStubsPackage", "RepositoryInfo", + "StubManager", + "StubPackage", + "StubRepository", "StubRepositoryPackage", + "StubsManifest", + "source", ] diff --git a/micropy/stubs/repositories/__init__.py b/micropy/stubs/repositories/__init__.py index 2acebb73..35b45a75 100644 --- a/micropy/stubs/repositories/__init__.py +++ b/micropy/stubs/repositories/__init__.py @@ -2,8 +2,8 @@ from .micropython import MicropythonStubsManifest, MicropythonStubsPackage __all__ = [ - "MicropyStubsManifest", "MicropyStubPackage", - "MicropythonStubsPackage", + "MicropyStubsManifest", "MicropythonStubsManifest", + "MicropythonStubsPackage", ] diff --git a/micropy/stubs/source.py b/micropy/stubs/source.py index 8ab71299..7a79bf68 100644 --- a/micropy/stubs/source.py +++ b/micropy/stubs/source.py @@ -28,8 +28,7 @@ class LocateStrategy(Protocol): @abc.abstractmethod - def prepare(self, location: PathStr) -> Union[PathStr, tuple[PathStr, Callable[..., Any]]]: - ... + def prepare(self, location: PathStr) -> Union[PathStr, tuple[PathStr, Callable[..., Any]]]: ... logger = Log.add_logger(__name__, show_title=False) diff --git a/micropy/utils/helpers.py b/micropy/utils/helpers.py index 3c77d591..45c3543b 100644 --- a/micropy/utils/helpers.py +++ b/micropy/utils/helpers.py @@ -32,22 +32,22 @@ from .types import PathStr __all__ = [ - "is_url", - "get_url_filename", + "create_dir_link", "ensure_existing_dir", "ensure_valid_url", - "is_downloadable", - "is_existing_dir", - "stream_download", - "search_xml", - "get_package_meta", "extract_tarbytes", - "iter_requirements", - "create_dir_link", - "is_dir_link", - "is_update_available", "get_cached_data", "get_class_that_defined_method", + "get_package_meta", + "get_url_filename", + "is_dir_link", + "is_downloadable", + "is_existing_dir", + "is_update_available", + "is_url", + "iter_requirements", + "search_xml", + "stream_download", ] diff --git a/micropy/utils/stub.py b/micropy/utils/stub.py index 18656e4c..66aaf3dc 100644 --- a/micropy/utils/stub.py +++ b/micropy/utils/stub.py @@ -1,4 +1,5 @@ """Micropy stub utils.""" + from __future__ import annotations import importlib.util diff --git a/micropy/utils/types.py b/micropy/utils/types.py index 662793a3..12151176 100644 --- a/micropy/utils/types.py +++ b/micropy/utils/types.py @@ -13,5 +13,4 @@ @runtime_checkable class SupportsLessThan(Protocol): - def __lt__(self, other: Any) -> bool: - ... + def __lt__(self, other: Any) -> bool: ... diff --git a/tests/data/esp32_test_stub/stubs/machine.py b/tests/data/esp32_test_stub/stubs/machine.py index 99a83e7b..cb012bc2 100644 --- a/tests/data/esp32_test_stub/stubs/machine.py +++ b/tests/data/esp32_test_stub/stubs/machine.py @@ -1,6 +1,7 @@ """ Module: 'machine' on esp8266 v1.9.4 """ + # MCU: (sysname='esp8266', nodename='esp8266', release='2.2.0-dev(9422289)', version='v1.9.4-8-ga9a3caad0 on 2018-05-11', machine='ESP module with ESP8266') # Stubber: 1.1.2 diff --git a/tests/data/esp8266_test_stub/stubs/machine.py b/tests/data/esp8266_test_stub/stubs/machine.py index 99a83e7b..cb012bc2 100644 --- a/tests/data/esp8266_test_stub/stubs/machine.py +++ b/tests/data/esp8266_test_stub/stubs/machine.py @@ -1,6 +1,7 @@ """ Module: 'machine' on esp8266 v1.9.4 """ + # MCU: (sysname='esp8266', nodename='esp8266', release='2.2.0-dev(9422289)', version='v1.9.4-8-ga9a3caad0 on 2018-05-11', machine='ESP module with ESP8266') # Stubber: 1.1.2 diff --git a/tests/test_stubs/esp32_test_stub/stubs/machine.py b/tests/test_stubs/esp32_test_stub/stubs/machine.py index 99a83e7b..cb012bc2 100644 --- a/tests/test_stubs/esp32_test_stub/stubs/machine.py +++ b/tests/test_stubs/esp32_test_stub/stubs/machine.py @@ -1,6 +1,7 @@ """ Module: 'machine' on esp8266 v1.9.4 """ + # MCU: (sysname='esp8266', nodename='esp8266', release='2.2.0-dev(9422289)', version='v1.9.4-8-ga9a3caad0 on 2018-05-11', machine='ESP module with ESP8266') # Stubber: 1.1.2 diff --git a/tests/test_stubs/esp8266_test_stub/stubs/machine.py b/tests/test_stubs/esp8266_test_stub/stubs/machine.py index 99a83e7b..cb012bc2 100644 --- a/tests/test_stubs/esp8266_test_stub/stubs/machine.py +++ b/tests/test_stubs/esp8266_test_stub/stubs/machine.py @@ -1,6 +1,7 @@ """ Module: 'machine' on esp8266 v1.9.4 """ + # MCU: (sysname='esp8266', nodename='esp8266', release='2.2.0-dev(9422289)', version='v1.9.4-8-ga9a3caad0 on 2018-05-11', machine='ESP module with ESP8266') # Stubber: 1.1.2