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

fix flaky pre-commit install, via nuclear option, dont try to install… #24

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

willsheffler
Copy link
Contributor

@willsheffler willsheffler commented Nov 21, 2024

… deps

Summary by Sourcery

Improve the reliability of the pre-commit hook installation by handling broken symlinks and adding error handling. Introduce an option to skip package installation during the hook setup. Enhance tests to ensure the idempotency of the installation process.

Bug Fixes:

  • Fix the flaky installation of pre-commit hooks by handling broken symlinks and adding error handling.

Enhancements:

  • Add an option to skip package installation when setting up pre-commit hooks.

Tests:

  • Add repeated calls to test the idempotency of the pre-commit hook installation function.

Copy link
Contributor

sourcery-ai bot commented Nov 21, 2024

Reviewer's Guide by Sourcery

This PR modifies the pre-commit hook installation process to make it more robust and configurable. The main changes include making package installation optional, improving symlink handling, and adding better error handling and user feedback.

Updated class diagram for install_ipd_pre_commit_hook function

classDiagram
    class ProjectConfig {
        +install_ipd_pre_commit_hook(projdir, path=None, install_packages=False)
        +ensure_pre_commit_packages()
    }
    note for install_ipd_pre_commit_hook "Improved symlink handling, optional package installation, and error handling."
Loading

File-Level Changes

Change Details Files
Refactored pre-commit hook installation function to be more robust and configurable
  • Added optional parameter 'install_packages' to control dependency installation
  • Added proper error handling with try-except block
  • Improved symlink handling by specifically checking for and removing broken symlinks
  • Added more detailed user feedback messages
  • Made package installation optional and controlled via parameter
ipd/dev/project_config.py
Enhanced test coverage for pre-commit hook installation
  • Added multiple consecutive installation attempts to verify idempotency
ipd/tests/dev/test_project_config.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

what-the-diff bot commented Nov 21, 2024

PR Summary

  • Revamped Hash Values for Key Files
    The checksum values for both the project_config.py and test_project_config.py files have been updated. This ensures we are always working on the most recent and correct versions of these important files.

  • Improved install_ipd_pre_commit_hook Function

    This function now incorporates more detailed conditions and feedback mechanisms:

    • An install_packages parameter was introduced, providing choice to decide whether or not to install new packages during each run.
    • The code now checks for dysfunctional symbolic links (symlinks) rather than merely checking if a path exists. This reduces the chance of creating redundant links to the pre-commit hook.
    • Informative print statements have been added, providing clarity whether packages got installed successfully or not.
    • We've introduced an overall error handling mechanism to manage RuntimeError scenarios. It will prevent the system from crashing, ensuring a smooth operational flow even when errors occur.
  • Augmented Unit Test for install_ipd_pre_commit_hook Function

    For install_ipd_pre_commit_hook, the unit test now includes multiple calls to check the function's robustness. This guarantees that the function behaves as expected in diverse scenarios, promoting greater code reliability and performance.

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

Overall Comments:

  • Consider enhancing the error handling to include the actual exception message rather than just printing 'error installing pre-commit hook' to help with debugging
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 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.

print('pre-commit hook installed')
else:
print('pre-commit hook installed, but packages not installed')
except RuntimeError:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Consider catching more specific exceptions and including error details in the message

Catching RuntimeError is too broad and could mask specific issues. Consider catching specific exceptions (like PermissionError, FileNotFoundError) and including the error details in the message.

    except (PermissionError, FileNotFoundError) as e:
        print(f'error installing pre-commit hook: {str(e)}')

@@ -11,6 +11,8 @@ def test_install_ipd_pre_commit_hook(tmpdir):
os.system('git init')
ipd.dev.install_ipd_pre_commit_hook('.')
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (testing): Test needs to verify new install_packages parameter behavior

The function has been updated to include an install_packages parameter, but the test doesn't verify both True and False scenarios. Consider adding assertions to check that packages are installed or not installed based on this parameter.

@willsheffler willsheffler merged commit 6dabfc3 into main Nov 21, 2024
1 check passed
@willsheffler willsheffler deleted the rfdsym branch November 21, 2024 04:43
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