Skip to content

Add initial pre-commit configuration#1280

Open
namurphy wants to merge 17 commits intospedas:masterfrom
namurphy:initial-pre-commit-config
Open

Add initial pre-commit configuration#1280
namurphy wants to merge 17 commits intospedas:masterfrom
namurphy:initial-pre-commit-config

Conversation

@namurphy
Copy link

@namurphy namurphy commented Nov 18, 2025

This PR adds an initial configuration for pre-commit in .pre-commit-config.yaml. The purpose of using pre-commit is to perform quality checks and enact automated fixes for new contributions and throughout the repository.

  • To enable pre-commit in CI, a maintainer will need to go to the pre-commit.ci website and click on the button near the top to "Sign In With GitHub". That should lead you through the process of activating pre-commit as a check on pull requests.

Thus far, I've added a bunch of pre-commit hooks from various sources. I'm enabling hooks that are passing without changes, and commenting out hooks that would require changes to implement. Some of these hooks would make changes to a wide variety of files, like the one for removing trailing whitespace. It'd probably work best to apply those changes in multiple pull requests. The autoformatting hooks could likely be lumped together into large pull requests since they change style but don't change content, but a few of the hooks will require careful code review. For ruff check specifically, it would make sense to do this in multiple smaller pull requests (e.g., subpackage by subpackage).

I hope this helps!

Comment on lines +76 to +80
# - repo: https://github.com/tox-dev/pyproject-fmt
# rev: v2.11.1
# hooks:
# - id: pyproject-fmt
# name: format pyproject.toml
Copy link
Author

@namurphy namurphy Nov 18, 2025

Choose a reason for hiding this comment

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

This hook would impose a particular opinionated style for pyproject.toml. It does help keep the file organized, but this one is fine to skip if you don't like the style.

Comment on lines +82 to +91
# - repo: https://github.com/hukkin/mdformat
# rev: 1.0.0
# hooks:
# - id: mdformat
# name: format .md files
# additional_dependencies:
# - mdformat-footnote
# - mdformat-gfm
# - mdformat-gfm-alerts
# - mdformat-ruff
Copy link
Author

Choose a reason for hiding this comment

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

mdformat autoformats Markdown files, and the additional dependencies are for GitHub flavored Markdown.

Comment on lines +173 to +177
ignore-words-list = """
fo,
inout,
tha,
thi"""
Copy link
Author

@namurphy namurphy Nov 18, 2025

Choose a reason for hiding this comment

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

This is just a subset of the possible misspellings that codespell is finding.

@jameswilburlewis
Copy link
Contributor

Thanks so much for taking the time to put this together! I'll look over your suggestions, give myself some time to wrap my head around all of this, and probably get back to you with some questions or comments.

I kind of thinking to do one big set of formatting fixups, packaged up as a squashed 'commit of doom", which will let me put it in a .git-blame-ignore-revs file. That might keep our 'git blame' annotations from getting swamped with a ton of mostly whitespace changes.

I'd probably want to avoid anything that would automatically change pyproject.toml, at least to start with -- we're now using pdm to manage our project dependencies, and every change to pyproject.toml should also come with a rebuilt version of pdm.lock, to keep the checksums in sync (but maybe this is already accounted for in the pre-commit hook?)

Is this stuff strictly on the Github side, or is there a way for developers to get this feedback immediately in their dev environment, before pushing to github?

@jameswilburlewis jameswilburlewis self-assigned this Nov 18, 2025
@jameswilburlewis jameswilburlewis added enhancement New feature or request QA/Testing Documentation Examples, notebooks, installation guides, webinars, etc python Issues involving Python and Python-related tools outside of pyspedas refactoring packaging labels Nov 18, 2025
@namurphy
Copy link
Author

I kind of thinking to do one big set of formatting fixups, packaged up as a squashed 'commit of doom", which will let me put it in a .git-blame-ignore-revs file.

That's a good idea! I was thinking one large PR for the autoformatting changes that only require a cursory code review, and then smaller pull requests for changes that need a person to look them over.

I'd probably want to avoid anything that would automatically change pyproject.toml, at least to start with -- we're now using pdm to manage our project dependencies

Good question! I don't know how well pyproject-fmt works with pdm, but I've had no problems using it with uv.

Is this stuff strictly on the Github side, or is there a way for developers to get this feedback immediately in their dev environment, before pushing to github?

I knew I forgot something! 😅 The changes can be applied to all files with pre-commit run --all-files (after doing a pip install pre-commit), or if you have uv installed, with uvx pre-commit run --all-files. To perform automated fixes on a pull request, add a comment that says pre-commit.ci autofix.

It's also possible to do pre-commit install to install the git hook scripts locally so that they get run automatically on every git commit. I find that to be very annoying, and set up an alias for doing pre-commit run --all-files manually.

@namurphy namurphy marked this pull request as ready for review November 19, 2025 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Examples, notebooks, installation guides, webinars, etc enhancement New feature or request packaging python Issues involving Python and Python-related tools outside of pyspedas QA/Testing refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments