-
Notifications
You must be signed in to change notification settings - Fork 373
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
New helper script to run fast lints and pre-push hook that runs it #3949
Conversation
ba6eef8
to
2edc548
Compare
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.
This is such a great addition, I love it!
Two things:
- codegen check is on the slow side for a pre-commit hook
- there should be a note about this in CONTRIBUTING.md (and elsewhere?), ideally along with a short reminder on how to add it as pre-commit
scripts/fast_lint.py
Outdated
(["rustfmt", "--check"], filter_ext(files, [".rs"])), | ||
(["python", "scripts/lint.py"], files), | ||
(["typos"], files), | ||
(["taplo", "fmt", "--check"], filter_ext(files, [".toml"])), |
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.
Love this so much! Taplo is way to slow when running `just toml-lint.
scripts/fast_lint.py
Outdated
logging.debug(f" {f}") | ||
|
||
jobs = [ | ||
(["pixi", "run", "codegen", "--check"], True), |
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.
This one takes 5-7s for me, which is dangerously close to some threshold as far as pre-commit hook are concerned.
❯ python scripts/fast_lint.py
INFO:root:SKIP: `rustfmt --check`
INFO:root:SKIP: `taplo fmt --check`
INFO:root:SKIP: `pixi run clang-format --dry-run`
INFO:root:PASS: `ruff check --config rerun_py/pyproject.toml <FILES>` in 0.01s
INFO:root:PASS: `typos <FILES>` in 0.04s
INFO:root:PASS: `python scripts/lint.py <FILES>` in 0.10s
INFO:root:PASS: `blackdoc --check <FILES>` in 0.51s
INFO:root:PASS: `black --check --config rerun_py/pyproject.toml <FILES>` in 0.54s
INFO:root:FAIL: `mypy --no-warn-unused-ignore <FILES>` in 0.99s
INFO:root:stdout: scripts/screenshot_compare/build_screenshot_compare.py:84: error: Incompatible types in assignment (expression has type "str", variable has type "Path") [assignment]
Found 1 error in 1 file (checked 2 source files)
INFO:root:PASS: `pixi run codegen --check ` in 5.70s
INFO:root:Lints failed in 5.73s
That's after a few runs to warm things up.
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.
(running on my antoine/screenshot_compare
branch)
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.
as far as pre-commi
Ahh yeah, agreed it's slow for a pre-commit. I have been primarily thinking of this as a pre-push, which I think strikes the right balance. I've now added option to skip arbitrary jobs if you wanted to use for a pre-commit as well.
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.
pre-push makes sense, yeah 👍🏻
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.
Still sounds too slow for a pre-push for my taste. It's also not something that I usually forget to do (running codegen), while things like typos fail my CI very often.
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.
How often are you git pushing?
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.
I dunno. 5-20 times a day? 🤷
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.
Alright -- if you want to save those 25 - 100 seconds you can now:
export RERUN_LINT_SKIP=lint-codegen
(["black", "--check", "--config", "rerun_py/pyproject.toml"], filter_ext(files, [".py"])), | ||
(["blackdoc", "--check"], filter_ext(files, [".py"])), | ||
(["mypy", "--no-warn-unused-ignore"], filter_ext(files, [".py"])), | ||
] |
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.
Out of this PR scope, but it would be nice if all of these would actually be (just_command, file_list) tuple. justfile
as single source of truth on how to run things...
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.
I'm not totally sold on making these all dispatch through just since I'm not sure running them individually always makes sense. However, I've added them all to pixi and updated the pixi deps so they should now run deterministically from the pixi environment.
2ceb454
to
5669a09
Compare
d421791
to
664702b
Compare
672001c
to
e1b2bd7
Compare
eea25dd
to
7fbed6f
Compare
or if you prefer you can configure git to use this directory as the hooks directory: | ||
``` | ||
git config core.hooksPath hooks | ||
``` |
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.
Nice. TIL.
To install the hooks, simply copy them into the `.git/hooks` directory of your local checkout. | ||
``` | ||
cp hooks/pre-push .git/hooks/pre-push | ||
chmod +x .git/hooks/pre-push |
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.
why not chmod +x hooks/pre-push
already?
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.
It generally should be, though I've definitely seen edge-cases across OS's and git configurations where that isn't guaranteed.
What
Resolves:
lint.py
#3738Builds out a micro-framework for running a bunch of lint-jobs in parallel as part of a local development cycle. Anything that we can run in a few seconds that would otherwise trip up CI should be a good contender for adding to this list.
Takes advantage of the diff relative to the common ancestor to only check modified files.
Also introduces a hooks directory for running as part of a pre-push hook.
Examples:
Optionally skip some lints:
Or force lints to run on the full tree without the change filters:
Checklist