git: d1a2a3d66e08 - main - comms/py-pyserial: add patch for FreeBSD implementation of list_ports tool

From: Sofian Brabez <sbz_at_FreeBSD.org>
Date: Mon, 29 Sep 2025 20:51:59 UTC
The branch main has been updated by sbz:

URL: https://cgit.FreeBSD.org/ports/commit/?id=d1a2a3d66e087b3bb91abb22a25f3d1ef4b4f4c7

commit d1a2a3d66e087b3bb91abb22a25f3d1ef4b4f4c7
Author:     Sofian Brabez <sbz@FreeBSD.org>
AuthorDate: 2025-09-29 20:39:38 +0000
Commit:     Sofian Brabez <sbz@FreeBSD.org>
CommitDate: 2025-09-29 20:51:51 +0000

    comms/py-pyserial: add patch for FreeBSD implementation of list_ports tool
    
    This changes include a patch of the tool list_ports for the posix
    implementation on FreeBSD by using devinfo(8) and bump the revision. Upstream
    did not yet released a new version in several years.
    
    Reported by:    phk
---
 comms/py-pyserial/Makefile                      |   2 +-
 comms/py-pyserial/files/patch-serial-list_ports | 102 ++++++++++++++++++++++++
 2 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/comms/py-pyserial/Makefile b/comms/py-pyserial/Makefile
index 3ff775e902da..9a4e301b5c3f 100644
--- a/comms/py-pyserial/Makefile
+++ b/comms/py-pyserial/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	pyserial
 PORTVERSION=	3.5
-PORTREVISION=	3
+PORTREVISION=	4
 CATEGORIES=	comms python
 MASTER_SITES=	PYPI
 PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
diff --git a/comms/py-pyserial/files/patch-serial-list_ports b/comms/py-pyserial/files/patch-serial-list_ports
new file mode 100644
index 000000000000..6abb782392ac
--- /dev/null
+++ b/comms/py-pyserial/files/patch-serial-list_ports
@@ -0,0 +1,102 @@
+#
+# GitHub Pull Request: https://github.com/pyserial/pyserial/pull/778
+
+# From cc99655f0969486eab63c80add5911c246ded0f8 Mon Sep 17 00:00:00 2001
+# From: Poul-Henning Kamp <phk@FreeBSD.org>
+# Date: Mon, 21 Oct 2024 09:50:28 +0000
+# Subject: [PATCH 1/2] Implement FreeBSD list_ports using devinfo(8)
+#
+
+--- serial/tools/list_ports_freebsd.py.orig	2025-09-29 15:56:08 UTC
++++ serial/tools/list_ports_freebsd.py
+@@ -0,0 +1,69 @@
++#!/usr/bin/env python
++#
++# This is a module that gathers a list of serial ports including details on
++# GNU/Linux systems.
++#
++# This file is part of pySerial. https://github.com/pyserial/pyserial
++# (C) 2011-2015 Chris Liechti <cliechti@gmx.net>
++#
++# SPDX-License-Identifier:    BSD-3-Clause
++
++from __future__ import absolute_import
++
++import glob
++import os
++
++import subprocess
++
++from serial.tools import list_ports_common
++
++class DevInfo(list_ports_common.ListPortInfo):
++    def __init__(self, line):
++        self.props = {}
++        for n, i in enumerate(line.split()):
++            if n == 0:
++                self.description = i
++                continue
++            f = i.split('=', maxsplit=1)
++            if len(f) == 2:
++                self.props[f[0]] = f[1]
++            else:
++                self.props[f[0]] = True
++        self.device = "/dev/cua" + self.props["ttyname"]
++        if "vendor" in self.props:
++            self.vid = int(self.props["vendor"], 16)
++            self.manufacturer = self.vid
++        if "product" in self.props:
++            self.pid = int(self.props["product"], 16)
++        if "sernum" in self.props:
++            self.serial_number = self.props["sernum"]
++        if "ugen" in self.props:
++            self.location = self.props["ugen"]
++            self.subsystem = "usb"
++            self.apply_usb_info()
++        else:
++            self.subsystem = "uart"
++            self.hwid = self.description
++
++    def usb_description(self):
++        return self.props["ugen"]
++
++def comports(include_links=False):
++    x = subprocess.run(["/usr/sbin/devinfo", "-rv"], capture_output=True)
++    seen = set()
++    for line in x.stdout.decode('utf-8').split('\n'):
++        if "ttyname" in line:
++            d = DevInfo(line)
++            seen.add(d.device)
++            yield d
++    for fn in sorted(glob.glob("/dev/cua*[!.init][!.lock]")):
++        if fn not in seen:
++            d = DevInfo(fn[5:] + " ttyname=" + fn[8:])
++            seen.add(d.device)
++            yield d
++
++# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++# test
++if __name__ == '__main__':
++    for info in sorted(comports()):
++        print("{0}: {0.subsystem}".format(info))
+
+# From 119cfbe54dcdbd6b4ffa87e7f4cc8d9163cc10b6 Mon Sep 17 00:00:00 2001
+# From: Poul-Henning Kamp <phk@FreeBSD.org>
+# Date: Tue, 22 Oct 2024 19:08:10 +0000
+# Subject: [PATCH 2/2] Use absolute path to devinfo(8)
+
+--- serial/tools/list_ports_posix.py.orig	2025-09-29 15:59:42 UTC
++++ serial/tools/list_ports_posix.py
+@@ -50,11 +50,7 @@ elif plat[:3] == 'bsd' or plat[:7] == 'freebsd':
+         return [list_ports_common.ListPortInfo(d) for d in devices]
+
+ elif plat[:3] == 'bsd' or plat[:7] == 'freebsd':
+-    def comports(include_links=False):
+-        devices = glob.glob('/dev/cua*[!.init][!.lock]')
+-        if include_links:
+-            devices.extend(list_ports_common.list_links(devices))
+-        return [list_ports_common.ListPortInfo(d) for d in devices]
++    from serial.tools.list_ports_freebsd import comports
+
+ elif plat[:6] == 'netbsd':   # NetBSD
+     def comports(include_links=False):