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

Start using pre-commit #7395

Conversation

WilliamJamieson
Copy link
Collaborator

This PR adds a pre-commit config with some basic checks:

  • check-added-large-files (prevent accidental adding of large files)
  • check-ast (check all python files can be parsed without error)
  • check-case-conflict (check that file names won't conflict on case-insensitive file systems)
  • check-yaml (check that yaml files are valid yaml)
  • check-toml (check toml files are valid toml)
  • check-merge-conflict (check that no signs of git merge conflicts exist in code)
  • check-symlinks (check that any symlinks are valid)
  • debug-statements (check for and remove any python debug statemnts)
  • detect-private-key (check for patterns of known private keys)
  • end-of-file-fixer (fix the whitespace at bottom of files)
  • trailing-whitespace (remove trailing whitespace)
  • python-check-blanket-noqa (makes sure noqa have a correct reason listed)
  • python-check-mock-methods (checks for common mocking mistakes)
  • rst-directive-colons (makes sure rst directives don't have a double colon)
  • rst-inline-touching-normal (detect inline coding mistakes in rst)
  • text-unicode-replacement-char (forbid the unicode replacement character)
  • ruff (run the ruff formatter)
  • bandit (run bandit checks)

These checks run very fast and can be setup to run (and autofix in most cases) everytime one commits to git. See https://pre-commit.com/.

Note the vast majority of the changes made by this are simply fixing the whitespace.

Checklist for maintainers

  • added entry in CHANGES.rst within the relevant release section
  • updated or added relevant tests
  • updated relevant documentation
  • added relevant milestone
  • added relevant label(s)
  • ran regression tests, post a link to the Jenkins job below.
    How to run regression tests on a PR
  • Make sure the JIRA ticket is resolved properly

Copy link
Collaborator

@zacharyburnett zacharyburnett left a comment

Choose a reason for hiding this comment

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

this looks good to me, do we have to set up precommit CI integration or is it automatic on merge?

@zacharyburnett
Copy link
Collaborator

Oh, I see now it is under check-style

@WilliamJamieson
Copy link
Collaborator Author

this looks good to me, do we have to set up pre-commit CI integration or is it automatic on merge?

The bot requires a manual setup and additional config in the .pre-commit-config.yaml. Currently, I replaced the style job with one that runs pre-commit manually. The bot has some clear advantages:

  1. It allows applying autofixes (the changes that can be made manually to pass the style checks) without having to run them locally. This can be done automatically (when the bot detects an error) or upon request.
  2. The bot will autoupdate the .pre-commit-config.yaml as it requires exact pins of the style check machinery.

I figure that it this PR gets merged we can discuss adding the bot to the JWST then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants