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

New helper script to run fast lints and pre-push hook that runs it #3949

Merged
merged 22 commits into from
Oct 23, 2023

Conversation

jleibs
Copy link
Member

@jleibs jleibs commented Oct 21, 2023

What

Resolves:

Builds 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:

$ just fast-lint 
pixi run python scripts/fast_lint.py 
INFO:root:SKIP: lint-cpp-files (no modified files)
INFO:root:SKIP: lint-rs-files (no modified files)
INFO:root:PASS: lint-taplo in 0.27s
INFO:root:PASS: lint-py-ruff in 0.28s
INFO:root:PASS: lint-typos in 0.29s
INFO:root:PASS: lint-py-black in 0.38s
INFO:root:PASS: lint-rerun in 0.39s
INFO:root:PASS: lint-py-mypy in 0.48s
INFO:root:PASS: lint-py-blackdoc in 0.48s
INFO:root:PASS: lint-codegen in 3.53s
INFO:root:All lints passed in 3.54s

Optionally skip some lints:

pixi run python scripts/fast_lint.py --skip lint-codegen
INFO:root:SKIP: lint-codegen (skipped manually)
INFO:root:SKIP: lint-cpp-files (no modified files)
INFO:root:SKIP: lint-rs-files (no modified files)
INFO:root:PASS: lint-taplo in 0.27s
INFO:root:PASS: lint-py-ruff in 0.28s
INFO:root:PASS: lint-typos in 0.30s
INFO:root:PASS: lint-rerun in 0.42s
INFO:root:PASS: lint-py-black in 0.43s
INFO:root:PASS: lint-py-blackdoc in 0.44s
INFO:root:PASS: lint-py-mypy in 0.62s
INFO:root:All lints passed in 0.63s

Or force lints to run on the full tree without the change filters:

$ just fast-lint --no-change-filter
pixi run python scripts/fast_lint.py --no-change-filter
INFO:root:SKIP: lint-cpp-files (no-change-filter not supported)
INFO:root:PASS: lint-py-ruff in 0.29s
INFO:root:PASS: lint-py-blackdoc in 0.64s
INFO:root:PASS: lint-py-mypy in 0.75s
INFO:root:PASS: lint-typos in 1.44s
INFO:root:PASS: lint-taplo in 1.77s
INFO:root:PASS: lint-py-black in 2.13s
INFO:root:PASS: lint-rs-all in 3.89s
INFO:root:PASS: lint-codegen in 4.92s
INFO:root:PASS: lint-rerun in 5.43s
INFO:root:All lints passed in 5.43s

Checklist

  • I have read and agree to Contributor Guide and the Code of Conduct
  • I've included a screenshot or gif (if applicable)
  • I have tested demo.rerun.io (if applicable)
  • The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG

@jleibs jleibs added the 🧑‍💻 dev experience developer experience (excluding CI) label Oct 21, 2023
@jleibs jleibs marked this pull request as ready for review October 21, 2023 00:42
@jleibs jleibs added the exclude from changelog PRs with this won't show up in CHANGELOG.md label Oct 21, 2023
Copy link
Member

@abey79 abey79 left a 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 Show resolved Hide resolved
(["rustfmt", "--check"], filter_ext(files, [".rs"])),
(["python", "scripts/lint.py"], files),
(["typos"], files),
(["taplo", "fmt", "--check"], filter_ext(files, [".toml"])),
Copy link
Member

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.

logging.debug(f" {f}")

jobs = [
(["pixi", "run", "codegen", "--check"], True),
Copy link
Member

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.

Copy link
Member

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)

Copy link
Member Author

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.

Copy link
Member

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 👍🏻

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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? 🤷

Copy link
Member Author

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

scripts/fast_lint.py Outdated Show resolved Hide resolved
scripts/fast_lint.py Outdated Show resolved Hide resolved
(["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"])),
]
Copy link
Member

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...

Copy link
Member Author

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.

@jleibs jleibs changed the title New helper script to run lints based on changes local to the branch New helper script to run fast lints and github hooks directory. Oct 21, 2023
@jleibs jleibs changed the title New helper script to run fast lints and github hooks directory. New helper script to run fast lints and pre-push hook that runs it Oct 21, 2023
@jleibs jleibs added include in changelog and removed exclude from changelog PRs with this won't show up in CHANGELOG.md labels Oct 21, 2023
Comment on lines +13 to +16
or if you prefer you can configure git to use this directory as the hooks directory:
```
git config core.hooksPath hooks
```
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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.

@jleibs jleibs merged commit 8e57f41 into main Oct 23, 2023
32 checks passed
@jleibs jleibs deleted the jleibs/fast_lint branch October 23, 2023 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧑‍💻 dev experience developer experience (excluding CI) include in changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants