Skip to content

Replace deprecated serial_handler imports with pslab.connection#267

Open
Architrb1795 wants to merge 2 commits intofossasia:developfrom
Architrb1795:replace-serial-handler-imports
Open

Replace deprecated serial_handler imports with pslab.connection#267
Architrb1795 wants to merge 2 commits intofossasia:developfrom
Architrb1795:replace-serial-handler-imports

Conversation

@Architrb1795
Copy link

@Architrb1795 Architrb1795 commented Feb 7, 2026

Fixes #271

Summary

This PR migrates usage of the deprecated pslab.serial_handler module to the modern pslab.connection.SerialHandler API and updates the CLI to explicitly manage the connection lifecycle.

Motivation

The pslab.serial_handler module is deprecated and emits warnings duringdocumentation builds and runtime.

While migrating to pslab.connection.SerialHandler, a behavioral difference was identified: the new API does not auto-connect on initialization, whereas the deprecated implementation did.

This caused the CLI (pslab/cli.py) to rely on implicit behavior that no longer exists, potentially leading to runtime failures.

Changes Made

  • Replaced deprecated pslab.serial_handler imports with
    pslab.connection.SerialHandler in:
    • pslab/cli.py
    • pslab/external/gas_sensor.py
    • pslab/external/hcsr04.py
    • pslab/external/tcd1304.py
  • Updated CLI initialization logic to:
    • Explicitly call handler.connect()
    • Ensure handler.disconnect() is always called via a safe lifecycle
  • Updated internal documentation to reference the new API

Verification

  • tox -e docs (deprecation warning removed)
  • tox -e lint (clean)
  • CLI connection tested with both explicit port selection and auto-detection

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 7, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR replaces deprecated pslab.serial_handler imports with the modern pslab.connection.SerialHandler and updates internal docs to reference the new module, eliminating deprecation warnings during docs builds.

File-Level Changes

Change Details Files
Swap all SerialHandler imports from the deprecated serial_handler module to the supported connection module.
  • Update CLI module to import SerialHandler from pslab.connection
  • Update external gas sensor helper to import SerialHandler from pslab.connection
  • Update external HCSR04 helper to import SerialHandler from pslab.connection
  • Update external TCD1304 helper to import SerialHandler from pslab.connection
pslab/cli.py
pslab/external/gas_sensor.py
pslab/external/hcsr04.py
pslab/external/tcd1304.py
Align internal documentation with the new SerialHandler import path.
  • Replace references to pslab.serial_handler with pslab.connection in internal documentation
docs/internal.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Architrb1795
Copy link
Author

Hi maintainers,
This is a small cleanup PR to remove usage of a deprecated module and reduce docs build warnings.
Happy to make any changes if needed, thanks for reviewing!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the codebase to stop importing the deprecated pslab.serial_handler module (which emits a deprecation warning during docs builds) and instead use the modern pslab.connection API.

Changes:

  • Switched SerialHandler imports from pslab.serial_handler to pslab.connection in the CLI and external sensor drivers.
  • Updated internal documentation to reference pslab.connection instead of the deprecated module.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pslab/cli.py Updates SerialHandler import to pslab.connection.
pslab/external/gas_sensor.py Updates SerialHandler import to pslab.connection.
pslab/external/hcsr04.py Updates SerialHandler import to pslab.connection.
pslab/external/tcd1304.py Updates SerialHandler import to pslab.connection.
docs/internal.rst Updates autodoc target module to pslab.connection to avoid deprecated import warnings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pslab/cli.py Outdated
from pslab.instrument.oscilloscope import Oscilloscope
from pslab.instrument.waveform_generator import WaveformGenerator, PWMGenerator
from pslab.serial_handler import SerialHandler
from pslab.connection import SerialHandler
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pslab.connection.SerialHandler has different runtime behavior than the deprecated pslab.serial_handler.SerialHandler: it requires an explicit port (no implicit autoconnect when args.port is None) and it does not auto-connect() in __init__. In main() this file currently does handler = SerialHandler(port=args.port) and then uses it without calling handler.connect(), which will leave the serial port closed (and may also pass None as the port). Update CLI initialization to use autoconnect() when no port is provided and/or call handler.connect() before use (and ensure disconnect() in a finally).

Suggested change
from pslab.connection import SerialHandler
from pslab.serial_handler import SerialHandler

Copilot uses AI. Check for mistakes.
Copy link
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Cleaning up the deprecated pslab.serial_handler imports is a good direction, and the change set is nicely small.

However, this is not a pure warning cleanup. pslab.connection.SerialHandler can behave differently than the deprecated handler, and in pslab/cli.py the code currently creates the handler and uses it without an explicit connect(), while args.port may be None. That can leave the port closed or fail at runtime.

Please do the following before we can merge:

  1. Open an issue describing the deprecation cleanup and the expected runtime behaviour of the CLI, then link it in the PR description using GitHub best practice: Fixes #<issue-number>.

  2. Add a short screencast showing this working on your machine:

    • tox -e docs with the warning removed
    • running the CLI command you tested, showing it successfully connects (include the exact command and whether a port is provided or auto detected)
  3. Update the CLI initialization to match the intended pslab.connection.SerialHandler usage, for example call connect() explicitly or use the proper auto connect flow, and ensure clean disconnect in a safe way.

Once the CLI behaviour is verified and captured in the issue and screencast, this becomes a clean and mergeable deprecation removal.

@mariobehling
Copy link
Member

Small process note.

We have automatic Copilot PR reviews enabled on this repository. These reviews are only triggered if the contributor has GitHub Copilot enabled and an active license on their own account.

Please enable Copilot in your GitHub settings if you have access. In many regions, free licenses are available through educational institutions or developer programs. Enabling Copilot helps us speed up the auto review process and reduces manual review overhead for the core team.

The team will review your PR. Thank you for your contribution and cooperation.

@Architrb1795
Copy link
Author

https://drive.google.com/file/d/1GLzB5s8oU4dDxOSFgL_CdgA9FAJZAwgg/view?usp=sharing

Thanks for the review!

I’ve updated the CLI to explicitly manage the connection lifecycle when migrating to pslab.connection.SerialHandler, and linked the related issue (Fixes #271).

I’ve also attached a short screencast demonstrating:

  • tox -e docs running without the deprecation warning
  • Successful CLI execution
  • Graceful failure with an invalid port

Please let me know if any further adjustments are needed.

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.

2 participants