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

Add precommit configuration #48

Merged
merged 10 commits into from
Jul 15, 2022
Merged

Add precommit configuration #48

merged 10 commits into from
Jul 15, 2022

Conversation

Zeitsperre
Copy link
Collaborator

Closes #46.

What does this introduce?

Pre-commit is a tool for running checks on code changes prior to committing them, preventing errors and inconsistencies from being introduced. I've added a pretty simple configuration that does a handful of things:

  • Runs black and a subset of black-compatible flake8 checks over the code base
  • Removes trailing whitespaces and adds an empty newline at the end of files
  • Sorts import statements consistent with Black
  • Checks for redundant # noqa statements

I've also added, but commented out, a few checks that require some effort.

  • Check Manifest file for any missing/unaccounted files (requires manifest file made in Add a MANIFEST.in file, docs typo fixes #47.)
  • PyDocStyle is a grammatical linter for writing consistent docstrings. Many changes needed. Willing to open more PRs for this.

@Zeitsperre Zeitsperre added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 1, 2022
@Zeitsperre Zeitsperre self-assigned this Jul 1, 2022
@KipCrossing
Copy link
Owner

@Zeitsperre What's the best way to test this on my local?

Should we add a check for mypy too?

#47 has been approved, so feel free to merge

PyDocStyle sounds very opinionated, we should discuss the advantages in another PR.

@Zeitsperre
Copy link
Collaborator Author

@Zeitsperre What's the best way to test this on my local?

To configure pre-commit in the repo:

$ pip install pre-commit
$ pre-commit install

This will make it so that anytime you commit a file, the pre-commit linters and checkers will run automatically.

To run the checks manually:

$ pre-commit run --all-files

Should we add a check for mypy too?

We can! And will do!

#47 has been approved, so feel free to merge

Thanks!

PyDocStyle sounds very opinionated, we should discuss the advantages in another PR.

Sounds good to me. The documentation conventions/style can be different depending on preferences. I'm partial to numpy-docstyle conventions, but others are supported. Will open an issue concerning it.

@KipCrossing
Copy link
Owner

KipCrossing commented Jul 8, 2022

Should we add pre-commit as a dev requirement?

And perhaps some instructions on how to use it?

Maybe there's a way to initiate pre-commit install via the setup.py when a dev install is run. - OR would that be a bit intrusive and we should instead leave it as an option in the readme

@KipCrossing
Copy link
Owner

BTW, I've tested it and it looks like it will be a handy tool; especially to save some time when waiting for CI on GitHub just for it to fail (eg mypy).

Copy link
Owner

@KipCrossing KipCrossing left a comment

Choose a reason for hiding this comment

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

Feel free to merge - but at the very least we should mention the pre-commit option in the CONTRIBUTING doc

@Zeitsperre
Copy link
Collaborator Author

Zeitsperre commented Jul 12, 2022

Hi @KipCrossing sorry for the delay!

In terms of time-saving, pre-commit is fantastic, and I've integrated it into many of the projects I help run. I can copy-paste some explanatory flavour text into the docs somewhere in this PR.

I like your idea of installing pre-commit when one makes a dev install. I know there's a way to do this. Can certainly look into it.

Edit: Looks like there's a suggestion in the docs https://pre-commit.com/#automatically-enabling-pre-commit-on-repositories

Edit 2: Some discussions within the pre-commit issues talk about how it would be a bit overarching to install pre-commit on clone/install. The better approach is to be clear in the dev docs about how to effectively contribute.

@Zeitsperre Zeitsperre merged commit d602f3e into main Jul 15, 2022
@Zeitsperre Zeitsperre deleted the add_precommit_configuration branch July 15, 2022 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use a pre-commit configuration
2 participants