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 pre-commit plus a GItHub Action to run it #776

Merged
merged 4 commits into from
Dec 23, 2023

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Dec 23, 2023

As discussed at #718 (comment)

@akx Your review, please.

Using https://pre-commit.ci is even better than using GitHub Actions for pre-commit.

% pre-commit run --all-files

[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/charliermarsh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/abravalheri/validate-pyproject.
[INFO] Initializing environment for https://github.com/abravalheri/validate-pyproject:.[all].
[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...
[INFO] Installing environment for https://github.com/charliermarsh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/abravalheri/validate-pyproject.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check builtin type constructor use.......................................Passed
check toml...............................................................Passed
check xml............................................(no files to check)Skipped
check yaml...............................................................Passed
ruff.....................................................................Passed
Validate pyproject.toml..................................................Passed

Signed-off-by: Christian Clauss <[email protected]>
Copy link
Contributor

@akx akx left a comment

Choose a reason for hiding this comment

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

This really boils down to maintainer (@PierreF) preference. #770 already set up running Ruff with tox, which is also fine. Left a comment about https://github.com/pre-commit/action in case you weren't aware of it.

Comment on lines 15 to 21
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: pip install pre-commit
- run: pre-commit --version
- run: pre-commit install
- run: pre-commit run --all-files
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: pip install pre-commit
- run: pre-commit --version
- run: pre-commit install
- run: pre-commit run --all-files
- uses: actions/setup-python@v5
with:
python-version: 3
- uses: pre-commit/[email protected]

Copy link
Contributor Author

@cclauss cclauss Dec 23, 2023

Choose a reason for hiding this comment

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

https://github.com/pre-commit/action is in maintenance-only mode and will not be accepting new features so I tend not to use it. pre-commit.ci is awesome.

Copy link
Contributor

@akx akx Dec 23, 2023

Choose a reason for hiding this comment

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

I know it's in maintenance-only mode, but it works – it's also just, well, 20 lines.

I don't prefer pre-commit.ci because it's a third-party dependency and (AFAIU) an one-man project (and for projects where "auto-fix PRs" is enabled, they tend to mess with my workflow).

Copy link
Contributor Author

@cclauss cclauss Dec 23, 2023

Choose a reason for hiding this comment

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

pre-commit.ci is run by the same person who led the development of pre-commit.

If auto-fix PRs are messing up your workflow then you do not have pre-commit properly installed locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cclauss Well, for a repo like this where every commit should have a --signoff to adhere to a CLA, the pre-commit commit wouldn't be appropriate, etc. 😁

.github/workflows/precommit.yml Outdated Show resolved Hide resolved
@cclauss cclauss requested a review from akx December 23, 2023 18:21
Copy link
Contributor

@PierreF PierreF left a comment

Choose a reason for hiding this comment

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

This add another tools for checking code, but I think it's okay:

  • tox -e py (or just tox / tox -e py38): is here to run Python tests. And might took some time
  • tox -e lint will be kept for slow linter
  • pre-commit will be used for faster linter

Those linters/tests could still run locally and in Github actions. Which fit the needs of everyone:

  • the one that want to run it locally (like me) before pushing to Github
  • all PRs and master is also automatically checked by Github

.github/workflows/precommit.yml Outdated Show resolved Hide resolved
@PierreF
Copy link
Contributor

PierreF commented Dec 23, 2023

The error isn't added by the PR but already present on master. I will fix it once merged.

Copy link
Contributor

@akx akx left a comment

Choose a reason for hiding this comment

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

Weak review comment, can be addressed later as well: If this is adopted (and I'm for it, in general), tox -e lint should just run pre-commit run --all-files to avoid drift between multiple lint styles.

@PierreF PierreF merged commit 705930a into eclipse-paho:master Dec 23, 2023
9 of 10 checks passed
@cclauss cclauss deleted the pre-commit branch December 23, 2023 21:45
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.

3 participants