pypsa-eur icon indicating copy to clipboard operation
pypsa-eur copied to clipboard

Add pre-commit for formatting, liniting and code checking.

Open euronion opened this issue 2 years ago • 6 comments

Closes #242 . Closes #239 .

Changes proposed in this Pull Request

Add checks, formatters and linters using pre-commit to the repository. Especially includes:

  • black formatting for Python
  • formatting for yaml files
  • REUSE check for FSFE REUSE compliance

Question:

  • [x] Should pre-commit be added to the environment.yaml? --> No
  • [ ] Other hooks we should add?

TODOs:

  • [ ] Update documentation: Add pre-commit encouragement (PR template + docu from atlite as template?)
  • [ ] Remove pep8 recommendation from documentation
  • [ ] Connect this repository with the (http://precommit.ci/) after merging this PR
  • [ ] Add this PR after the next major release as an immediate minor release (mainly formattting) to keep change transparency for git blame

Checklist

  • [x] I tested my contribution locally and it seems to work fine.
  • [x] Code and workflow changes are sufficiently documented.
  • [ ] Newly introduced dependencies are added to envs/environment.yaml and envs/environment.docs.yaml.
  • [n/a] Changes in configuration options are added in all of config.default.yaml, config.tutorial.yaml, and test/config.test1.yaml.
  • [n/a] Changes in configuration options are also documented in doc/configtables/*.csv and line references are adjusted in doc/configuration.rst and doc/tutorial.rst.
  • [ ] A note for the release notes doc/release_notes.rst is amended in the format of previous release notes.

euronion avatar Jan 11 '22 11:01 euronion

What I also use for linopy:

Isort sorts imports of packages

-   repo: https://github.com/PyCQA/isort
    rev: 5.9.3
    hooks:
      - id: isort
        args: ["--profile", "black", "--filter-files"]

codespell checks for spelling errors in comments and docstrings

-   repo: https://github.com/codespell-project/codespell
    rev: v2.1.0
    hooks:
    -   id: codespell
        types_or: [python, rst, markdown]
        files: ^(scripts|doc)/

FabianHofmann avatar Jan 11 '22 15:01 FabianHofmann

Added. isort may be a bit controversial.

I had to exclude a regex for all CAPITAL CASE words for codespell, as it complained about the code strings THS and BA in scripts/build_shapes.py

euronion avatar Jan 12 '22 14:01 euronion

Re question what to add: I like under pre-commit-hooks

  - id: check-added-large-files
    args: ['--maxkb=1000']

fneum avatar Jan 13 '22 16:01 fneum

Re question what to add: I like under pre-commit-hooks

  - id: check-added-large-files
    args: ['--maxkb=1000']

Added, but with 2 MB as a limit. Our pictures in the documentations are sometimes larger than 1 MB.

euronion avatar Jan 13 '22 17:01 euronion

Added, but with 2 MB as a limit. Our pictures in the documentations are sometimes larger than 1 MB.

Fair enough :1234:

fneum avatar Jan 13 '22 17:01 fneum

This is now hot again @FabianHofmann @euronion.

fneum avatar Jul 27 '22 11:07 fneum

Given that we already have a large number of commits in the master I suggest we postpone it (again) until a minor release.

euronion avatar Aug 22 '22 12:08 euronion