Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce code duplication #182

Merged
merged 1 commit into from
Dec 29, 2024
Merged

Reduce code duplication #182

merged 1 commit into from
Dec 29, 2024

Conversation

rschaeuble
Copy link
Contributor

@rschaeuble rschaeuble commented Dec 24, 2024

Summary by Sourcery

Enhancements:

  • Introduce a helper function res_tester_config to consolidate the logic for retrieving resonance tester configuration parameters, handling compatibility with both old and new Klipper versions.

Copy link
Contributor

sourcery-ai bot commented Dec 24, 2024

Reviewer's Guide by Sourcery

This pull request refactors the code to reduce duplication by introducing a helper function res_tester_config in shaketune/helpers/compat.py. This function retrieves configuration values from the resonance_tester object, handling compatibility with both old and new Klipper versions. The axes_shaper_calibration, compare_belts_responses, and excitate_axis_at_freq commands now use this helper function.

Class diagram showing the new helper function and its usage

classDiagram
    class ResTesterConfig {
        +default_min_freq
        +default_max_freq
        +default_accel_per_hz
        +test_points
    }

    class compat {
        +res_tester_config(config) ResTesterConfig
    }

    class axes_shaper_calibration {
        +axes_shaper_calibration(gcmd, config, st_process)
    }

    class compare_belts_responses {
        +compare_belts_responses(gcmd, config, st_process)
    }

    class excitate_axis_at_freq {
        +excitate_axis_at_freq(gcmd, config, st_process)
    }

    axes_shaper_calibration ..> compat : uses
    compare_belts_responses ..> compat : uses
    excitate_axis_at_freq ..> compat : uses
    compat ..> ResTesterConfig : creates
Loading

File-Level Changes

Change Details Files
Introduce res_tester_config helper function
  • Created the res_tester_config function to centralize the logic for retrieving resonance tester configuration values.
  • The function handles compatibility with both old and new Klipper versions by checking for the existence of the test attribute on the resonance_tester object.
  • Returns a namedtuple containing default minimum frequency, maximum frequency, acceleration per Hz, and test points.
shaketune/helpers/compat.py
Use res_tester_config in existing commands
  • Replaced the duplicated code for retrieving resonance tester configuration values with a call to the res_tester_config helper function.
  • Simplified the logic in the commands by using the returned namedtuple from res_tester_config.
shaketune/commands/axes_shaper_calibration.py
shaketune/commands/compare_belts_responses.py
shaketune/commands/excitate_axis_at_freq.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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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
Contributor

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

Overall Comments:

  • The file header comment in compat.py appears to be copied from compare_belts_responses.py - please update it to describe the actual purpose of this compatibility helper module.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

shaketune/helpers/compat.py Show resolved Hide resolved
shaketune/helpers/compat.py Outdated Show resolved Hide resolved
@Frix-x
Copy link
Owner

Frix-x commented Dec 29, 2024

Thanks for the PR!
It's indeed a good idea to have added this compat.py file! I'll probably populate it with a couple of other things that were added for compatibility in this new file later on (like the minimum_cruise_ratio that use the same kind of logic for before/after this addition in Klipper).

I'll merge it :)

@Frix-x Frix-x merged commit f07809f into Frix-x:develop Dec 29, 2024
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