Skip to content

Commit

Permalink
Initial setup of QA pre-commit tools [cf-units] (#522)
Browse files Browse the repository at this point in the history
* Added extra pre-commit default hooks

* Added codespell pre-commit hook

* Added mypy and configuration

* Added mypy exrts dependency

* Added ignores for mypy (including one in sp-repo-review)

* Added validate-pyproject

* Added numpydoc precommit hook and ignored errors in pyproject.toml

* Updated ignore_list of sp-repo-review for errors that have been
addressed in this branch

* Fixed sp-repo-review "PC901" (Custom pre-commit CI message)

* Added extra pytest config, as recommended by sp-repo-review.

* Added `filterwarnings=error` option for pytest and an exception for thie
existing known Deprecation warnings

* - Enabled all Ruff checks.
  - Required lots of additions to the Ruff ignore list
  - Extra additions to mypy ignore list
- Autofixes from Ruff linter
- Fixes from codespell

* Tidy up pyproject.toml.
  - Removed some duplicate ruff ignores
  - Reorded some subsections

* Updated Ruff config:
  - Added: `force-sort-within-sections = true`
  - Auto updated files resultig from above
  - file specific ignores

* Auto-corrections for
  - Trailing witespace
  - No neline at end of file
  - Some Ruff linting

* - Update Ruff version.
- Add trailing / to mypy exclude paths

* Try different approach to MyPy ignore files in .pre-commit config

* Update pyproject.toml

Added extra ignores in mypy for _udunits generated code

* Update pyproject.toml

Re-added PY005 test to sp-repo-review ignore list.

* Roll back changes to _antlr4_runtime and add .pre-commit exclusion for
this directory

* Added reference comment to .pre-commit-config.yaml

* Removed redundant setting

* Removed comment

* Alphabetise repo-review ignore list

* Ahphabetised pre-commit hooks, as per template

* Added explanation comments to Ruff ignores

* Added reference to common SciTools linting rules Wiki

* Removed D212 from Ruff select

* Reinstate D212 Ruff rule.
This also updated one docstring in cf_units/__init__.py (correctly) due
to the removal of a redundant `noqa: E501` marker in a previous commit
  • Loading branch information
ukmo-ccbunney authored Nov 21, 2024
1 parent 4ad25ba commit 03aed8e
Show file tree
Hide file tree
Showing 28 changed files with 568 additions and 501 deletions.
2 changes: 1 addition & 1 deletion .git_archival.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true)$
ref-names: $Format:%D$
ref-names: $Format:%D$
6 changes: 3 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Submitting changes

1. Push your branch to your fork of cf-units.
1. Submit your pull request.
1. Note that all authors on pull requests will automatically be asked to sign the
1. Note that all authors on pull requests will automatically be asked to sign the
[SciTools Contributor Licence Agreement](https://cla-assistant.io/SciTools/)
(CLA), if they have not already done so.
(CLA), if they have not already done so.
1. Chillax!

If in doubt, please post in the
[cf-units Discussions space](https://github.com/SciTools/cf-units/discussions)
[cf-units Discussions space](https://github.com/SciTools/cf-units/discussions)
and we'll be happy to help you.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ assignees: ''
## How to Reproduce
Steps to reproduce the behaviour:

1.
2.
3.
1.
2.
3.

## Expected Behaviour
<!-- A clear and concise description of what you expected to happen -->

## Environment
## Environment
- OS & Version: [e.g., Ubuntu 20.04 LTS]
- cf-units Version: [e.g., From the command line run `python -c "import cf_units; print(cf_units.__version__)"`]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
- name: "Building sdist"
shell: bash
run: |
pipx run build --sdist
pipx run build --sdist
- uses: actions/upload-artifact@v4
with:
Expand Down
76 changes: 64 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# See https://pre-commit.ci/#configuration
# See https://github.com/scientific-python/cookie#sp-repo-review for repo-review
# See https://github.com/SciTools/.github/wiki/Linting for common SciTools linters

ci:
autofix_prs: false
autoupdate_commit_msg: "chore: update pre-commit hooks"

exclude: 'cf_units/_udunits2_parser/_antlr4_runtime/'

minimum_pre_commit_version: 1.21.0

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -16,28 +26,51 @@ repos:
- id: check-merge-conflict
# Check for debugger imports and py37+ `breakpoint()` calls in Python source.
- id: debug-statements
# Check TOML file syntax.
- id: check-toml
# Check YAML file syntax.
- id: check-yaml
# Makes sure files end in a newline and only a newline.
# Duplicates Ruff W292 but also works on non-Python files.
- id: end-of-file-fixer
# Replaces or checks mixed line ending.
- id: mixed-line-ending
# Don't commit to main branch.
- id: no-commit-to-branch
# Trims trailing whitespace.
# Duplicates Ruff W291 but also works on non-Python files.
- id: trailing-whitespace

- repo: https://github.com/aio-libs/sort-all
rev: v1.3.0
hooks:
- id: sort-all
types: [file, python]

- repo: https://github.com/scientific-python/cookie
rev: 2024.08.19
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"] # TODO: Only neededed if extra dependencies are required
#args: ["--show=errskip"] # show everything for the moment
# Hooks from all other repos
# NOTE : keep these in hook-name (aka 'id') order

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.19.1
hooks:
- id: blacken-docs
types: [file, rst]

- repo: https://github.com/codespell-project/codespell
rev: "v2.3.0"
hooks:
- id: codespell
types_or: [asciidoc, python, markdown, rst]
additional_dependencies: [tomli]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.13.0'
hooks:
- id: mypy
additional_dependencies:
- 'types-requests'
exclude: 'docs/|cf_units/_udunits2_parser/parser/.*\.py|cf_units/_udunits2_parser/_antlr4_runtime/.*\.py'

- repo: https://github.com/numpy/numpydoc
rev: v1.8.0
hooks:
- id: numpydoc-validation
types: [file, python]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.4"
hooks:
Expand All @@ -47,3 +80,22 @@ repos:
args: [--fix, --show-fixes]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/aio-libs/sort-all
rev: v1.3.0
hooks:
- id: sort-all
types: [file, python]

- repo: https://github.com/scientific-python/cookie
rev: 2024.08.19
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"] # TODO: Only neededed if extra dependencies are required
#args: ["--show=errskip"] # show everything for the moment

- repo: https://github.com/abravalheri/validate-pyproject
# More exhaustive than Ruff RUF200.
rev: "v0.23"
hooks:
- id: validate-pyproject
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ recursive-include requirements *
recursive-include docs *
prune docs/build

exclude cf_units/etc/site.cfg
exclude cf_units/etc/site.cfg
Loading

0 comments on commit 03aed8e

Please sign in to comment.