Skip to content

Conversation

jmgate
Copy link
Collaborator

@jmgate jmgate commented Jul 8, 2025

Type: Task

Description

Trying to turn on all available Ruff linters.

Summary by Sourcery

Enable all available Ruff lint rules, adjust code to conform to them, and update tooling configuration accordingly.

Enhancements:

  • Enable all available Ruff rule codes in lint configuration
  • Add per-file Ruff ignore rules for tests, docs, and examples
  • Configure pyupgrade plugin in Ruff to preserve runtime typing
  • Refactor code to satisfy newly enabled lint rules (simplify constructs, update encoding usage, add noqa directives)
  • Remove obsolete abstract_method module and related raise statements
  • Add test package initializer to support relative imports

CI:

  • Update pre-commit configuration to use ruff-check hook

Documentation:

  • Remove obsolete abstract_method.rst from documentation

Tests:

  • Add test/init.py to initialize test package

@jmgate jmgate self-assigned this Jul 8, 2025
Copy link

sourcery-ai bot commented Jul 8, 2025

Reviewer's Guide

This PR turns on all available Ruff lint rules and supplements the linting setup (including pyupgrade), updates the CI pre-commit hook to use ruff-check, refactors the codebase to satisfy the new lint constraints (removing obsolete abstract_method patterns and adjusting code style), introduces a test package initializer, and cleans up corresponding documentation.

Class diagram for removal of AbstractMethod and related changes

classDiagram
    class StatsCollector {
        <<abstract>>
        +collect()
        +unproxied_stats()
        +finish()
    }
    %% AbstractMethod was removed, so no longer shown as a base or used in exceptions
    %% collect and unproxied_stats no longer raise AbstractMethod
    class TraceCollector {
        <<abstract>>
        +trace_args()
        +command(command: str)
    }
    %% AbstractMethod was removed, so no longer shown as a base or used in exceptions
    %% trace_args no longer raises AbstractMethod
Loading

Class diagram for ShellLogger method renaming and log serialization

classDiagram
    class ShellLogger {
        +update_done_time()
        +update_duration()  %% was __update_duration
        +print(msg: str, end: str = "\n")
        +to_html() : Union[Iterator[str], list[Iterator[str]]]
        +log(...)
        +log_book
        +done_time
        +duration
    }
    class ShellLoggerJSONEncoder {
        +default(obj: object) : object
    }
    ShellLoggerJSONEncoder --> ShellLogger : serializes
Loading

File-Level Changes

Change Details Files
Enhance Ruff lint configuration
  • Expanded extend-select to include all rule categories
  • Added per-file ignore patterns for tests, docs, and examples
  • Enabled pyupgrade typing preservation
pyproject.toml
Switch CI hook to ruff-check
  • Replaced pre-commit hook id from “ruff” to “ruff-check”
.pre-commit-config.yaml
Remove obsolete abstract_method artifacts
  • Deleted abstract_method module and its documentation
  • Removed AbstractMethod imports and raise statements in collectors
shell_logger/abstract_method.py
doc/source/abstract_method.rst
shell_logger/stats_collector.py
shell_logger/trace_collector.py
Refactor code to satisfy stricter lint rules
  • Rewrote stats collector loop as a generator expression and removed empty passes
  • Renamed private method and its calls, adding noqa for print statements
  • Standardized os.write calls to use byte literals
  • Adjusted imports and return values in HTML utilities
  • Simplified dict building in JSON serializer and added appropriate noqa comments
  • Added noqa for OSError catch
shell_logger/stats_collector.py
shell_logger/shell_logger.py
shell_logger/shell.py
shell_logger/html_utilities.py
shell_logger/trace_collector.py
Establish test package
  • Added test/init.py to enable relative imports in tests
test/__init__.py

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 @jmgate - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `shell_logger/shell_logger.py:251` </location>
<code_context>
         """
         self.done_time = datetime.now()

-    def __update_duration(self) -> None:
+    def update_duration(self) -> None:
         """
         Update the :attr:`duration` attribute.
</code_context>

<issue_to_address>
Renaming __update_duration to update_duration improves clarity and avoids name mangling.

This also improves accessibility for testing and aligns with standard Python naming for non-private methods.
</issue_to_address>

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.

@jmgate jmgate force-pushed the update-ruff-linters branch from 5c8cea5 to 781371b Compare July 8, 2025 16:00
Copy link

codecov bot commented Jul 8, 2025

Codecov Report

Attention: Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 78.67%. Comparing base (1acd254) to head (76ba7c7).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
shell_logger/shell_logger.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #213      +/-   ##
==========================================
+ Coverage   77.92%   78.67%   +0.75%     
==========================================
  Files           7        6       -1     
  Lines         847      830      -17     
  Branches      145      143       -2     
==========================================
- Hits          660      653       -7     
+ Misses        147      138       -9     
+ Partials       40       39       -1     

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

jmgate added 2 commits July 8, 2025 10:27
I think its existence was a historical artifact of starting this project
before the @AbstractMethod decorator was available.
@jmgate jmgate force-pushed the update-ruff-linters branch from 781371b to 6ddc335 Compare July 8, 2025 16:28
@jmgate
Copy link
Collaborator Author

jmgate commented Jul 8, 2025

@sourcery-ai review

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 @jmgate - I've reviewed your changes - here's some feedback:

  • After removing abstract_method.py, verify that all formerly custom abstract-method errors are now correctly enforced via @abstractmethod and that any tests expecting the old AbstractMethod exception are updated to catch TypeError instead.
  • The rename of __update_duration to update_duration is a breaking change—ensure no external code or serialization paths rely on the old private method name, or consider adding an alias for backwards compatibility.
  • In stats_collectors, using collectors.extend(generator) works but is less self-documenting than a direct list comprehension; consider assigning collectors = [collector(...) for collector in ...] to match the declared return type and improve readability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- After removing `abstract_method.py`, verify that all formerly custom abstract-method errors are now correctly enforced via `@abstractmethod` and that any tests expecting the old `AbstractMethod` exception are updated to catch `TypeError` instead.
- The rename of `__update_duration` to `update_duration` is a breaking change—ensure no external code or serialization paths rely on the old private method name, or consider adding an alias for backwards compatibility.
- In `stats_collectors`, using `collectors.extend(generator)` works but is less self-documenting than a direct list comprehension; consider assigning `collectors = [collector(...) for collector in ...]` to match the declared return type and improve readability.

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.

Sourcery suggested:

    In stats_collectors, using collectors.extend(generator) works but is
    less self-documenting than a direct list comprehension; consider
    assigning collectors = [collector(...) for collector in ...] to
    match the declared return type and improve readability.
@jmgate jmgate merged commit 68c103d into master Jul 8, 2025
15 checks passed
@jmgate jmgate deleted the update-ruff-linters branch July 8, 2025 16:45
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.

1 participant