From 2522d4df9aee5f5f26e24afcf50933e1e814e161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Roald-Arb=C3=B8l?= Date: Thu, 1 Dec 2022 10:35:05 +0000 Subject: [PATCH 1/3] create list_devices --- belay/__init__.py | 1 + belay/helpers.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/belay/__init__.py b/belay/__init__.py index 05adb55..38f6556 100644 --- a/belay/__init__.py +++ b/belay/__init__.py @@ -20,3 +20,4 @@ SpecialFunctionNameError, ) from .pyboard import PyboardException +from .helpers import list_devices diff --git a/belay/helpers.py b/belay/helpers.py index d6e2bbc..4230625 100644 --- a/belay/helpers.py +++ b/belay/helpers.py @@ -2,6 +2,7 @@ import secrets import string from functools import lru_cache, partial, wraps +from serial.tools import list_ports from . import snippets @@ -22,3 +23,10 @@ def random_python_identifier(n=16): @lru_cache def read_snippet(name): return pkg_resources.read_text(snippets, f"{name}.py") + +def list_devices(): + """Return list of available devices""" + ports = [] + for port in list(list_ports.comports()): + ports.append(port.device) + return(ports) From bcef761e0ae5545ed8f246de919c79bb92bfb5d5 Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Thu, 1 Dec 2022 09:09:59 -0800 Subject: [PATCH 2/3] simplify and lint list_devices --- belay/helpers.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/belay/helpers.py b/belay/helpers.py index 4230625..219cf4a 100644 --- a/belay/helpers.py +++ b/belay/helpers.py @@ -2,6 +2,8 @@ import secrets import string from functools import lru_cache, partial, wraps +from typing import List + from serial.tools import list_ports from . import snippets @@ -24,9 +26,13 @@ def random_python_identifier(n=16): def read_snippet(name): return pkg_resources.read_text(snippets, f"{name}.py") -def list_devices(): - """Return list of available devices""" - ports = [] - for port in list(list_ports.comports()): - ports.append(port.device) - return(ports) + +def list_devices() -> List[str]: + """Lists available device ports. + + Returns + ------- + list[str] + Available devices identifiers. + """ + return [port.device for port in list_ports.comports()] From a91b023175bac9021e38e01a2699bc4bc441136d Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Thu, 1 Dec 2022 09:20:44 -0800 Subject: [PATCH 3/3] fix up docs --- belay/__init__.py | 13 ++++++++----- belay/helpers.py | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/belay/__init__.py b/belay/__init__.py index 38f6556..b4b326b 100644 --- a/belay/__init__.py +++ b/belay/__init__.py @@ -3,12 +3,15 @@ __all__ = [ "AuthenticationError", - "minify", + "ConnectionLost", "Device", - "SpecialFunctionNameError", - "PyboardException", - "Implementation", "FeatureUnavailableError", + "Implementation", + "MaxHistoryLengthError", + "PyboardException", + "SpecialFunctionNameError", + "list_devices", + "minify", ] from ._minify import minify from .device import Device, Implementation @@ -19,5 +22,5 @@ MaxHistoryLengthError, SpecialFunctionNameError, ) -from .pyboard import PyboardException from .helpers import list_devices +from .pyboard import PyboardException diff --git a/belay/helpers.py b/belay/helpers.py index 219cf4a..4bffdb0 100644 --- a/belay/helpers.py +++ b/belay/helpers.py @@ -30,6 +30,10 @@ def read_snippet(name): def list_devices() -> List[str]: """Lists available device ports. + For example:: + + ['/dev/cu.usbmodem1143401', '/dev/cu.usbmodem113101'] + Returns ------- list[str]