feat(teensyrom): cross-platform USB-serial auto-detection#72
Merged
Conversation
Replace the macOS-only system_profiler + /dev/cu.usbmodem globbing with a single pyserial list_ports.comports() path that works on macOS, Linux, and Windows. Identify the board by its USB (VID 0x16C0, PID 0x0489) with a "teensyrom" product-string fallback, and return the enumerated device path directly (COMn / /dev/ttyACM* / /dev/cu.usbmodem*) — no per-platform node resolution. Add scripts/diags/tr_serial_probe.py to make a failed detect explain itself (env, per-port fields, match decision) instead of a bare None.
…xtra CI installs only the midi extra, so pyserial is absent and the tests that patched serial.tools.list_ports.comports errored at patch time, while ruff format also wanted two files reflowed. Isolate the pyserial call behind _list_comports() (returns [] when pyserial is missing or enumeration fails) so the auto-detect tests patch that helper instead of the serial module — no pyserial needed. Apply ruff format.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #72 +/- ##
==========================================
+ Coverage 79.56% 79.65% +0.08%
==========================================
Files 76 76
Lines 15426 15403 -23
Branches 2321 2315 -6
==========================================
- Hits 12274 12269 -5
+ Misses 2622 2607 -15
+ Partials 530 527 -3 ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
autodetect_serial_port()was macOS-only: it shelled out tosystem_profilerfor the board's USB serial number, then globbed
/dev/cu.usbmodem<serial>*forthe node. Off macOS it hard-returned
None, sotr://(auto-detect) required anexplicit
[teensyrom].serial_porton Linux and Windows.This replaces that with a single pyserial
list_ports.comports()path thatworks on macOS, Linux, and Windows. The board is identified by its USB
(VID
0x16C0, PID0x0489) — the only stable, driver-independent keyacross platforms — with a case-insensitive
"teensyrom"product/descriptionsubstring accepted as a fallback where the OS surfaces the USB product string.
Each
comports()entry already carries the resolved device path, so there's noper-platform node resolution: it returns
COMn//dev/ttyACM*//dev/cu.usbmodem*directly. pyserial is already thetrextra dependency.The generic Windows
usbser.sysdriver exposes no product string (product isNone, description is the bareUSB Serial Device (COMn)), which is why the(VID, PID) key leads and the product-name match is only a fallback.
Changes
teensyrom_dma.py: rewriteautodetect_serial_port()onlist_ports; add apure, duck-typed
_is_teensyrom_port()matcher +_TEENSY_USB_VID/_TEENSYROM_USB_PIDconstants; isolate the pyserial call behind_list_comports()(returns[]when pyserial is missing or enumerationfails); drop the dead
system_profiler/glob machinery and itsglob/json/subprocess/sysimports.backend.py: drop the "macOS only" wording from the auto-detect log commentand the missing-
serial_porterror message.scripts/diags/tr_serial_probe.py: new diagnostic — runs the sameenumeration and prints the environment, each port's fields, and the match
decision, so a failed auto-detect explains itself instead of a bare
None.no product string, product-string fallback, rejection) and
_list_comports-mocked
autodetecttests incl. the multi-board warning. The tests patch_list_comports, so they need no pyserial (thetrextra) installed.Verification
mypy --strict, pyright, full unittest suite(1902 tests) all pass — including with pyserial absent (the CI extra set).
Windows (via the new diagnostic); the resolved path feeds the unchanged
SerialTransport.