Skip to content

Commit

Permalink
[nc-time-axis] QA refresh linter hooks (#293)
Browse files Browse the repository at this point in the history
* Updated pre-commit-config.yaml with:
  - trailing-whitespace hook
  - CI chore
  - global file list

* Added blacken-docs hook.
  - Required manually disabling on @savefig lines in docs/examples.rst
  - Update files list to include doc/*.rst in filespre-commit-config.yaml

* small update to tpyes in codespell hook

* Added Ruff linter to replace black, flake8 and isort.
Includes Ruff autofixes:
 - 11 × D212 (multi-line-summary-first-line)
 - 1 × RET506 (superfluous-else-raise)
 - 1 × RET505 (superfluous-else-return)
 - 1 × I001 (unsorted-imports)
Added `PLR5501` to exclude list to preserve readability of TODO
block in convert method

* Ignores for Ruff linter

* Autofixes

* Added mypy linter and exceptions

* Added numpydoc and exceptions

* Reorder hooks alphabetically

* Added sort-all hook

* Added validate-pyproject hook

* Added sp-repo-review hook and excludes.
  - Applied some fixes to [tool.pytest.ini_options]

* Added references to SciTools linters Wiki

* Fixed repo-review "PP304" [Sets the log level in pytest]

* Fixed sp-repo-review: "GH212" [Require GHA update grouping]

* Removed wheel from build (Fixes sp-repo-review "PP003")

* Alphabetised pyproject.toml sections (manually)

* Try to fix brocken docs build

* Fixed docs build (had to make `.. blacken-docs:off` apply to whole code block

* Better comment on ruff select list

* Added annotations to ruff ignore list
  • Loading branch information
ukmo-ccbunney authored Nov 21, 2024
1 parent 2cf61f9 commit bc581bf
Show file tree
Hide file tree
Showing 16 changed files with 384 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ignore =
W503,
# W504: line break after binary operator
W504
exclude =
exclude =
.eggs
build
docs/conf.py
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]
- nc-time-axis Version: [e.g., From the command line run `python -c "import nc_time_axis; print(nc_time_axis.__version__)"`]

Expand Down
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ updates:
day: "thursday"
time: "01:00"
timezone: "Europe/London"
groups:
dependencies:
patterns:
- "*"
labels:
- "New: Pull Request"
- "Bot"
87 changes: 69 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
# 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
# See https://github.com/SciTools/.github/wiki/Linting for common linter rules

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

# Alphabetised, for lack of a better order.
files: |
(?x)(
docs\/.+\.(py|rst)|
pyproject\.toml|
setup\.py|
src\/.+\.py
)
minimum_pre_commit_version: 1.21.0

repos:

# Hook for pre-commit's built-in checks:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v5.0.0'
hooks:
Expand All @@ -19,37 +38,69 @@ repos:
- id: check-toml
# Check YAML file syntax.
- id: check-yaml
# Makes sure files end in a newline and only a newline
# 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/psf/black
rev: '24.10.0'
# Hooks for all other repos.
# Keep these alphabetised by hook (aka 'id') order.

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.19.1
hooks:
- id: black
- 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
exclude: 'noxfile\.py|docs/conf\.py'

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

- repo: https://github.com/PyCQA/flake8
rev: '7.1.1'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.4"
hooks:
- id: flake8
- id: ruff
types: [file, python]
args: [--fix, --show-fixes]
- id: ruff-format
types: [file, python]
args: [--config=./.flake8]

- repo: https://github.com/pycqa/isort
rev: '5.13.2'
- repo: https://github.com/aio-libs/sort-all
rev: v1.3.0
hooks:
- id: isort
- id: sort-all
types: [file, python]
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/codespell-project/codespell
rev: 'v2.3.0'
- repo: https://github.com/scientific-python/cookie
rev: 2024.08.19
hooks:
- id: codespell
types_or: [python, markdown, rst]
additional_dependencies: [tomli]
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
args: ["--show=errskip"]

- repo: https://github.com/abravalheri/validate-pyproject
# More exhaustive than Ruff RUF200.
rev: "v0.23"
hooks:
- id: validate-pyproject
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ We would love to hear from you!
- [View/discuss existing pull requests](https://github.com/SciTools/nc-time-axis/pulls)
- [Raise a new pull request](https://github.com/SciTools/nc-time-axis/compare)

Note that all authors on pull requests will automatically be asked to sign the
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.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BSD 3-Clause License
Copyright (c) 2016, Met Office.
Copyright (c) 2016, Met Office.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
21 changes: 18 additions & 3 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Basic Usage
`matplotlib`_. To register its converters, simply ``import nc_time_axis``. Then you
will be able to make plots with :py:class:`cftime.datetime` axes.

..
comment: @savefig causes blacken-docs to fail
.. blacken-docs:off
.. ipython:: python
:okwarning:
Expand All @@ -30,6 +35,8 @@ will be able to make plots with :py:class:`cftime.datetime` axes.
@savefig basic.png
fig.show()
.. blacken-docs:on
Setting the Axes Ticks and Tick Format
--------------------------------------

Expand All @@ -43,14 +50,22 @@ documentation
for acceptable format codes) and the calendar type of the axis (see
the :py:class:`cftime.datetime` documentation for valid calendar strings).

..
@savefig causes blacken-docs to fail
.. blacken-docs:off
.. ipython:: python
:okwarning:
fig, ax = plt.subplots(1, 1)
ax.plot(times, y);
ax.set_xticks([cftime.datetime(2000, 1, day, calendar="noleap") for day in range(2, 19, 4)]);
ax.plot(times, y)
ax.set_xticks(
[cftime.datetime(2000, 1, day, calendar="noleap") for day in range(2, 19, 4)]
)
formatter = nc_time_axis.CFTimeFormatter("%m-%d %H:%M", "noleap")
ax.xaxis.set_major_formatter(formatter)
@savefig set_ticks.png
fig.show()
.. blacken-docs:on
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nc-time-axis
============

``nc-time-axis`` is a package that enables making plots in `matplotlib`_ with axes made
up of :py:class:`cftime.datetime` dates with any calendar type.
up of :py:class:`cftime.datetime` dates with any calendar type.

.. toctree::
:caption: Getting started
Expand Down
6 changes: 3 additions & 3 deletions docs/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ v1.4.0 (October 23rd, 2021)
---------------------------

Deprecations
~~~~~~~~~~~~
~~~~~~~~~~~~

* The :py:class:`CalendarDateTime` class has been deprecated and will be removed
in ``nc-time-axis`` version 1.5.0. Please switch to plotting instances or
Expand Down Expand Up @@ -122,10 +122,10 @@ Bug Fixes
:py:meth:`matplotlib.axes.Axes.fill_between` to work properly with `cftime`_
values (:issue:`47`, :issue:`74`, :pull:`78`).
By `Pascal Bourgault`_.
* Fixed a bug that resulted in the resolution of tick labels being inconsistent
* Fixed a bug that resulted in the resolution of tick labels being inconsistent
with the resolution of tick values (:issue:`48`, :pull:`79`).
By `Spencer Clark`_.
* Fixed a bug that prevented users from being able to explicitly set the ticks
* Fixed a bug that prevented users from being able to explicitly set the ticks
along axes using :py:meth:`matplotlib.axes.Axes.set_xticks` or
:py:meth:`matplotlib.axes.Axes.set_yticks` (:issue:`41`, :pull:`84`).
By `Spencer Clark`_.
Expand Down
Loading

0 comments on commit bc581bf

Please sign in to comment.