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

Add simple pre-commit hook #1065

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

SqAtx
Copy link
Contributor

@SqAtx SqAtx commented Mar 17, 2024

Relates to #237

This adds a simple configuration for pre-commit and runs it on GHA. It doesn't do very much; mostly removing trailing whitespaces.

My next step would be to add pylint or pyflakes to this, and tell it to ignore every warning that GTG currently breaks. This would:

  • prevent us from breaking any more
  • allow us to fix the warnings one at a time, when we can

I tested the GHA on a fork.

This commit doesn't contain the changes that fix the pre-commit check, so GHA will fail. To fix it, we'll just need to run pre-commit run --all-files and commit the result.

@@ -12,17 +12,27 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are things we can improve in this file, like updating the version of the Actions we use. I noticed that #1036 touches that, so I didn't do anything in order to avoid conflicts.

- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies

# Note: we could try and cache the pre-commit environment
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 tried doing it, but my first attempt didn't work. I still had the

[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...

but the entire pre-commit step only takes 12 seconds at the moment. So it seems okay to leave it as is for now.

run: |
python -m pip install --upgrade pip
pip install pre-commit
pre-commit run --all-files
Copy link
Contributor Author

@SqAtx SqAtx Mar 17, 2024

Choose a reason for hiding this comment

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

This does modify the files, but we don't commit them. The important thing is that the command's exit code is set to 1 if it made changes, which makes the workflow fail.

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I mentioned in #237, this trailing-whitespace is the one that I find important.

This file is just the output of pre-commit sample-config, and the default seemed reasonable. I'm okay removing the others if anyone insists.

@@ -160,6 +160,21 @@ No data should be lost since it is just re-generateable build files.
[pythondevmode]: https://docs.python.org/3/library/devmode.html
[pudb]: https://pypi.org/project/pudb/

## Setting up a development environment
Copy link
Contributor Author

@SqAtx SqAtx Mar 17, 2024

Choose a reason for hiding this comment

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

This could eventually move into its own file within https://github.com/getting-things-gnome/gtg/tree/master/docs/contributors. I think it's OK to have it here for now.

I will create a task for modernizing https://github.com/getting-things-gnome/gtg/blob/master/docs/contributors/coding%20best%20practices.md, which still mentions Python 2 and tox. It's a good place to also mention the automated code quality checks that we're adding.

@nekohayo nekohayo added the maintainability Automated tests suite, tooling, refactoring, or anything that makes it easier for developers label Mar 18, 2024
@SqAtx SqAtx force-pushed the add_pre_commit branch 2 times, most recently from d8a0051 to ce8184c Compare March 23, 2024 20:48
@SqAtx SqAtx marked this pull request as ready for review March 23, 2024 20:52
@SqAtx SqAtx force-pushed the add_pre_commit branch 2 times, most recently from cb92fb3 to 74acdad Compare April 7, 2024 15:06
@SqAtx
Copy link
Contributor Author

SqAtx commented Apr 7, 2024

@diegogangl @nekohayo what do you guys think of this one?

@diegogangl
Copy link
Contributor

Hey, thanks for working on this! LGTM, though I'd split it at least the whitespace changes from the yaml changes in two different commits. Also, looks like I caused some conflict here (hopefully just whitespace stuff)

@SqAtx
Copy link
Contributor Author

SqAtx commented Apr 20, 2024

Yep that' s a good point. I'll rebase this with just my changes. After you merge it, you can just run pre-commit and make a new commit that will fix the build.

I also just noticed that https://github.com/getting-things-gnome/gtg/blob/master/Makefile is a thing, and we probably want to eventually move pep8/pyflakes out of it and into pre-commit. I think between meson and pre-commit, that makefile will be pretty much redundant?

Relates to getting-things-gnome#237

This adds a simple configuration for pre-commit and runs it on GHA. It doesn't do very much; mostly removing trailing whitespaces.

My next step would be to add pylint or pyflakes to this, and tell it to ignore every warning that GTG currently breaks. This would:
* prevent us from breaking any more
* allow us to fix the warnings one at a time, when we can

I tested the GHA on a fork.

This commit doesn't contain the changes that fix the pre-commit check, so GHA will fail. To fix it, we'll just need to run `pre-commit run --all-files` and commit the result.
@SqAtx SqAtx changed the title Add simple pre-commit hook and run it Add simple pre-commit hook Apr 20, 2024
@SqAtx SqAtx mentioned this pull request Apr 20, 2024
@diegogangl diegogangl merged commit c59b72c into getting-things-gnome:master Apr 22, 2024
1 check failed
@azmeuk
Copy link

azmeuk commented Apr 25, 2024

Hi @SqAtx
For your future step, a python linter that gathers attention lately is ruff. It can serve as a replacement for pylint and pyflakes, and boast to be faster than both.

@SqAtx SqAtx deleted the add_pre_commit branch April 26, 2024 04:06
@SqAtx
Copy link
Contributor Author

SqAtx commented Apr 26, 2024

I've never used it but I don't mind trying it! It seems pretty young but has quite a few developers behind it. And it integrates with pre-commit, so why not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainability Automated tests suite, tooling, refactoring, or anything that makes it easier for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants