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

[NDSL] Add functionality to pre-commit #983

Open
wants to merge 8 commits into
base: dsl/develop
Choose a base branch
from

Conversation

twicki
Copy link

@twicki twicki commented Aug 16, 2024

Purpose

Enhance featuers used in the pre-commit hook.

This PR adds two new hooks to run in pre-commit: codespell and pydocstyle. codespell checks for spelling errors and pydocstyle ensures conventions in documentation are upheld.

Code changes:

Add new hooks

  • .pre-commit-config.yaml
    • add new hooks

IMPORTANT

I did not change all the files to match these hooks yet. This works should be done once we've consolidated this list and would be a PR into this branch before merging to dsl/develop

@twicki twicki requested a review from a team as a code owner August 16, 2024 08:37
@twicki twicki requested review from FlorianDeconinck and removed request for a team August 16, 2024 08:37
@FlorianDeconinck FlorianDeconinck added the 0 diff structural Structural changes to repository that are zero-diff label Aug 16, 2024
@FlorianDeconinck FlorianDeconinck changed the title add functionality to pre-commit [NDSL] Add functionality to pre-commit Aug 16, 2024
@twicki twicki requested a review from romanc August 16, 2024 12:11
Copy link

@romanc romanc left a comment

Choose a reason for hiding this comment

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

Love the codespell initiative. Not sure how well this will fly given all the cryptic abbreviations in the current code. It's probably a good thing though. Will force us to increase readability while we port. We probably want to have our own dictionary since the "--ignore-word-list" will be rather big.

If we gonna look at linting & formatting, we might want to look at the new ruff linter/formatter. According to the docs, it's a drop-in replacement for flake8, isort, and black. It comes with pre-commit integration and is orders of magnitudes faster than the traditional pipeline (its written in rust).

gt4py is also using it and if we decide to move, it would be nicer to work in the NDSL (not here) repo because that pulls in gt4py as a submodule and currently I have to deactivate "format on save" option because vscode is will try to format it with the black formatter (apparently there's no way in vscode to have different formatters for the same language depending on folder structure). ruff is mono-repo friendly and will use the closest ruff configuration allowing different config files per (submodule) folder.

@FlorianDeconinck
Copy link
Collaborator

Good point about codespell. We do want to make code more readable, but we have to be careful about doing that to early and losing people in the port. My heart is split on the subject. I think a more conservative approach would be to keep most variable names the same, change the function names, then go through the port with a few scientists for further explanation and refactor then? Maybe it's too complex of a strategy.

As much as I'd like to burn flak8 and dace on its grave, I am worried about how "drop-in" ruff is going to be. @twicki take an hour and see, this is a small codebase, easier to handle than NDSL

@twicki
Copy link
Author

twicki commented Aug 16, 2024

ok, tested ruff. Works pretty well. Easy to handle config file. Is added now

@twicki twicki requested a review from a team as a code owner August 16, 2024 13:45
@twicki
Copy link
Author

twicki commented Aug 16, 2024

Additionally I created a codespell ignore file if we want to get rid of the appreviations we have in here.

I still strongly believe that if we want to build a sustanable codebase our variables should not be named TE but at least temp or temperature. At last we no longer live in a world where long variable names kill us because of either punchcards or displays that are limited to 60 characters,

@twicki twicki removed the request for review from a team August 16, 2024 13:47
@romanc
Copy link

romanc commented Aug 16, 2024

ok, tested ruff. Works pretty well. Easy to handle config file. Is added now

nice, with that you should be able to remove not only black, but also flake8 and isort from the pre-commit config, or do you just want to use the formatter?

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.4.2
hooks:
- id: isort
description: Group and sort Python imports
Copy link

Choose a reason for hiding this comment

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

we should also be able to get rid of isort if we go with ruff

Tobias Wicky-Pfund added 2 commits August 16, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 diff structural Structural changes to repository that are zero-diff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants