KipCrossing / geotiff

A noGDAL tool for reading and writing geotiff files
GNU Lesser General Public License v2.1
216 stars 23 forks source link

Add precommit configuration #48

Closed Zeitsperre closed 2 years ago

Zeitsperre commented 2 years ago

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:

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

KipCrossing commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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).

Zeitsperre commented 2 years ago

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.