-
Notifications
You must be signed in to change notification settings - Fork 801
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
Run linters and formatters via pre-commit
#797
Conversation
Signed-off-by: Josh Karpel <[email protected]>
… tests Signed-off-by: Josh Karpel <[email protected]>
tests/openmetrics/test_parser.py
Outdated
families = text_string_to_metric_families("# HELP a \n" | ||
"# UNIT a \n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the parser requires the trailing space on these lines, which the end-of-line fixer I added in the pre-commit
config wanted to remove from the multiline string. Possibly a separate bug in the parser? I don't know enough about the openmetrics format to say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parser is correct, also changing things like this makes it harder to manually run these tests via copy&page. They're written this way for a reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know - lemme revert this part and remove the end-of-line fixer as a quick fix. There are ways to ignore particular files, but I don't love doing that, so it seems like that particular formatter needs some more thought.
tests/openmetrics/test_parser.py
Outdated
families = text_string_to_metric_families("# HELP a \n" | ||
"# UNIT a \n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parser is correct, also changing things like this makes it harder to manually run these tests via copy&page. They're written this way for a reason.
tests/test_parser.py
Outdated
@@ -272,7 +272,7 @@ def test_timestamps(self): | |||
# TYPE b counter | |||
# HELP b help | |||
b 2 1234567890 | |||
b 88 1234566000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are changing this test, this trailing space is meant to be here.
Signed-off-by: Josh Karpel <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Personally, I am not a huge fan of pre-commit hooks as they add more overhead than I would like for some changes, or when I just want to push my progress somewhere. Yes --no-verify
is an option, but I have still found them a bit jarring.
I would like to leave this open for a bit though, if other devs think it is helpful I am not opposed to merging it.
Fair point! However, this set of checks is pretty fast. At least on my computer, running these
I'm running through WSL so I suspect this is longer than average due to how slow WSL is with filesystem operations. In my experience, those few seconds are worth it to not have to wait for CI to fail and do a whole extra commit + push to fix the typos. |
Hi again!
While working on #794 I had a few
flake8
linting errors locally that I didn't catch before pushing and had to push again to fix. On other projects I've foundpre-commit
very helpful for preventing these errors by forcing linters and formatters to run before committing. This PR adds apre-commit
configuration which includes the existingflake8
andisort
checks, plus some basic formatters and linters suggested bypre-commit
. I've updatedCONTRIBUTING.md
to include instructions for setting uppre-commit
locally and installing the hooks.In this initial take on the PR I've left
flake8
andisort
running throughtox
as well, but there's a CI service associated withpre-commit
at https://pre-commit.ci/ that I like (free for open source projects). It runspre-commit
checks on PRs and sends a PR every week to update the pre-commit check dependencies. It's also possible to run thepre-commit
checks in CircleCI, example config here. I'd recommend removing thetox
configuration for runningflake8
andisort
and running them throughpre-commit
instead, either throughpre-commit.ci
or CircleCI - your preference, assuming you're interested in this :)