earthaccess
earthaccess copied to clipboard
Consider using ``pre-commit`` hooks for linting
Sometimes it's easy to forget to lint code (I do this all the time!) and then CI builds fail because, for example, black isn't happy. We might consider using pre-commit hooks here to handle code formatting / linting. That way things like mypy, black, etc. all run automatically when a developer runs git commit ...
@betolink @MattF-NSIDC thoughts?
TODO
- [ ] Remove
.scripts/lint.shand references to it - [ ] Add Ruff (or Flake8) hook to
.pre-commit-config.yaml(add Ruff config to pyproject.toml) - [x] Enable pre-commit.ci (I may do this independently)
- [ ] Move isort config from script into a file (pyproject.toml; or migrate to Ruff)
- [ ] Move Black config from script to file
- [ ] Move Mypy config from script to file
- [ ] Should we run Mypy with pre-commit? It can be slow (probably not yet on this project?), and pre-commit is meant to not slow you down.
- [ ] More pre-commit hooks?
- [ ] Make sure
pre-commitis a dev dependency (if it isn't already -- haven't checked) - [ ] Update
CONTRIBUTING.mdto includepre-commit install
1000 times yes. Pre-commit gets my tools out of my way and I'm never going back :heart_eyes: Not everyone will use it, so I think we should keep the CI checks... and maybe run them in pre-commit.ci?
I think we should go forward with this. While we're there, I'd like to remove Flake8 and isort to replace with Ruff (#34). Ruff also has a Black-compatible formatter that I haven't tried yet, so I would probably still leave Black in place for now?
I think we need to:
EDIT: List moved to OP
EDIT: List moved to OP
Good ones! I'll merge all the checklist items into the OP now.
Should we run Mypy with pre-commit? It can be slow (probably not yet on this project?), and pre-commit is meant to not slow you down.
Another concern with Mypy is its interface doesn't really work well with pre-commit. Mypy doesn't want to receive a list of changed files to check, it will not do a holistic analysis in this case, so it may pass when a change breaks type correctness.
We can configure pre-commit to not pass filenames, and then Mypy will run on the whole project, which will be slower. Maybe we should run Mypy as a separate CI step.