Skip to content

Preserve PySerial URLs when opening ASRL resources on Windows - #664

Merged
MatthieuDartiailh merged 5 commits into
pyvisa:mainfrom
CAOShurong:codex/serial-url-windows
Oct 13, 2026
Merged

MatthieuDartiailh merged 5 commits into
pyvisa:mainfrom
CAOShurong:codex/serial-url-windows

Conversation

@CAOShurong

@CAOShurong CAOShurong commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to the serial URL support introduced in #386 and discussed in #385.

On Windows, SerialSession.after_parsing prefixes every board with COM before
calling serial_for_url. That is necessary for numeric VISA boards, but turns
loop:// and socket://... into unknown comloop / comsocket protocols.
The documented URL resources therefore cannot open on Windows, including the
socket handler used for TCP-to-serial converters.

Only add the prefix when the board has no ://, matching PySerial's own URL
dispatch. Numeric Windows boards still map to COM ports, POSIX device names are
unchanged, and custom URL handlers are not restricted to a built-in whitelist.
Discovery, serial attributes, I/O, error mapping and session lifetime are unchanged.

Regression coverage checks exact forwarding of six URL forms under both values
of the platform flag, native COM/POSIX mapping, and a real PySerial loopback through
ResourceManager.open_resource. The existing loopback test is unchanged.

Validation on Windows, Python 3.13.1, PyVISA 1.16.2 and PySerial 3.5:

  • Exact-main, noneditable installed API: direct PySerial loop/socket controls
    succeed, while six VISA URL cases fail before the fix. The new regression
    suite is 8 failed / 13 passed before the repair.
  • python -m pytest pyvisa_py/testsuite/test_serial.py -q: 21 passed, repeated.
    Serial/session/high-level subset: 24 passed.
  • Complete suite: baseline 334 passed / 131 skipped / 1 failed; committed source
    and independently installed wheel each 353 passed / 131 skipped. All 465 other
    existing outcomes are unchanged; the existing serial failure is fixed and
    18 added cases pass. All 484 source/installed outcomes match.
  • Full Ruff, configured python -m pre_commit run --all-files, strict Sphinx
    HTML build, sdist-to-wheel build, noneditable install and pip check: passed.
    A separate full mypy run in the fuller measurement environment reports the
    same two pre-existing tcpip.py:2102 errors on base and head; this is not an
    unconditional full-type-check-green claim.
  • Eight installed API checks, repeated, and four installed pyvisa-info /
    pyvisa-shell --backend py paths pass: loopback and synthetic local socket
    query/binary I/O, read timeout/recovery, close, unknown handler, refused
    connection and malformed URL. Git, sdist, wheel and installed Python bytes
    were compared. Initial harness assumptions were corrected against direct
    PySerial controls; the original failed runs were retained.

Physical COM/RS232 instruments, an RFC2217 server, vendor/Keysight instrumentation,
other local OS/Python versions and production acquisition were not tested. The
socket peer is a synthetic echo endpoint, not independent hardware validation;
the platform-flag cases do not establish native Linux/macOS execution.

Disclosure: Codex generated/edited the code, tests, validation harnesses and this
PR text. No personal human review is claimed.

  • Executed configured pre-commit hooks without errors
  • Added automated regression coverage
  • Added an entry to CHANGES
  • Issue-closing keyword: not applicable; [COM] Communication issue loop #385 was already closed by replace the call to serial.Serial with serial.serial_for_url #386.
  • Documented Windows COM/POSIX board formats and URL resources in
    docs/source/compliance.rst; corrected the loop/socket examples in index.rst.
    The earlier URL-handler note was in docs/source/index.rst, but the compliance
    notes were missing this information. This restores existing URL routing; no
    new interface or protocol-compliance behavior is introduced.

@hb020

hb020 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
  • Documentation/compliance changes: not applicable; this restores the existing
    documented URL routing, without a new interface or protocol-compliance change.

Well, it would be nice to document the different types of serial board formats accepted in /docs/source/compliance.rst, in the notes just under the top section Supported VISA resources. That is missing now. Same goes for USB boards, but someone else is working on that.

this restores the existing documented URL routing

Where is this? Maybe I'm missing something.

Signed-off-by: CAOShurong <170531907+CAOShurong@users.noreply.github.com>
@CAOShurong

Copy link
Copy Markdown
Contributor Author

Added the ASRL board formats and URL-handler examples to the Supported VISA resources notes in compliance.rst, including explicit-open/discovery limitations.

The earlier "documented" reference was the URL-handler note in index.rst, not the compliance notes; that omission is now corrected. Also fixed ASLRloop to ASRLloop and supplied the socket host/port in the examples.

Strict Sphinx HTML build passes; serial tests pass twice (21 each), and the full suite is 353 passed / 131 skipped. USB notes are untouched.

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.23%. Comparing base (eee01cc) to head (1bffd43).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #664      +/-   ##
==========================================
+ Coverage   54.74%   57.23%   +2.48%     
==========================================
  Files          39       39              
  Lines        6518     6542      +24     
  Branches      649      650       +1     
==========================================
+ Hits         3568     3744     +176     
+ Misses       2854     2688     -166     
- Partials       96      110      +14     
Flag Coverage Δ
unittests 57.23% <100.00%> (+2.48%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The default install skips test_serial and leaves the URL-routing regression untested. Install the existing serial extra in the unit-test matrix without changing runtime requirements or coverage thresholds.

Signed-off-by: CAOShurong <170531907+CAOShurong@users.noreply.github.com>
@MatthieuDartiailh

Copy link
Copy Markdown
Member

@CAOShurong can you address the merge conflict

@MatthieuDartiailh
MatthieuDartiailh merged commit 0d67355 into pyvisa:main Oct 13, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants