Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nc-time-axis] QA refresh linter hooks #293

Merged

Conversation

ukmo-ccbunney
Copy link
Contributor

@ukmo-ccbunney ukmo-ccbunney commented Nov 20, 2024

🚀 Pull Request

Description

Adds/updates linter hooks to pre-commit.

Excluded/ignored tests documented in following issues for follow up:

Noteworthy changes due to addition of QA hooks:

  • docs/example.rst - had to add .. blacken-doc: off directive to stop blacken-docs parsing two code blocks as there is a @savefig statement (used for generating plots for the docs) that causes blacken-docs to fail.
  • Added extra opts to pytest and enabled xfail_strict. Left filterwarnings = ["error"] commented out until warnings in code are addressed. Tested with pytest.
  • Several *.py files updated with auto-fixes from Ruff (mainly docstrings) and whitespace removal.

One of the commits (de7d178) alphabetises the order of sections in pyproject.toml. In hindsight this might make comparison of the changes in the file a bit tricky, so it might be worth checking the changes by commit (I tried to add each QA tool and its affected files in one commit)

  - trailing-whitespace hook
  - CI chore
  - global file list
  - Required manually disabling on @savefig lines in docs/examples.rst
  - Update files list to include doc/*.rst in filespre-commit-config.yaml
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
@ukmo-ccbunney ukmo-ccbunney self-assigned this Nov 20, 2024
@ukmo-ccbunney ukmo-ccbunney marked this pull request as ready for review November 21, 2024 14:54
Copy link

@stephenworsley stephenworsley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just a bit more annotations and I think we can merge this in. It's worth noting that some of the errors we were getting were due to a planned outage of mambaforge https://conda-forge.org/news/2024/07/29/sunsetting-mambaforge/. This problem fixed itself since today is not a planned outage day but this issue will still need to be resolved (probably in its own PR though).

]
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
strict = true
warn_unreachable = true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that the idea here is to signal that this is the intention while functionally turning this off with "unreachable" in the disabled error codes. I guess the alternative would be to have this be false but with a comment saying that's temporary. On reflection I think the approach here is probably best since it keeps all the TODOs in one place.

Copy link
Contributor Author

@ukmo-ccbunney ukmo-ccbunney Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could comment it out and add a TODO, like I did with the redundant-expr rule (in the cf-units repo):

enable_error_code = [
	"ignore-without-code",
#	"redundant-expr",		# TODO: Add back in when above ignores fixed
	"truthy-bool"
]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think it would be neater that way, to be honest I could see an argument for doing it either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented it out for the moment and added a comment to say it needs putting in when the error code is fixed; see bf0774f

This also required me to add an exception to repo-review (MY103)

It's probably better this way as previously I was sort of tricking repo-review that I had it set (then was sneakily putting in an ignore for it in mypy!)

pyproject.toml Outdated Show resolved Hide resolved
@stephenworsley stephenworsley merged commit bc581bf into SciTools:main Nov 21, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants