-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Enable running lints (that we run in CI) locally #55847
Description
🚀 Feature
We currently run a bunch of lints on our codebase in CI to keep PyTorch clean (e.g., check out this file). It would be wonderful if we had an easy way to run those same lints locally in our own local PyTorch.
Motivation
Imagine yourself as a contributor. You've just poured your heart out into the next big thing for PyTorch and you're super excited to see all the CI pass and be green for your new PR. You decide to take a well-deserved break as you wait for CI to all run, so you go do your favorite break activity and come back in 2 hours. You see a red X. Your heart skips a beat--what could have gone wrong?!?!
Oh. It's just flake8. You quickly fix your badly indented code and repush, triggering another full run of CI before you finally land your change.
Now imagine how this situation would be different if you were able to quickly verify locally that your code wouldn't break any lints before you open the PR. Not only would you have landed your change faster with more satisfaction, you would have reduced the cost of an entire CI workflow.
Requirements + Their Difficulties
We would like the solution to...
- Include as many quick and common lints. It is critical to include commonly broken lints while less critical to include lints that are less likely to be violated.
- Verify that the versions of tools used in CI are the same as on a local server. It is possible for different versions of, say,
mypyorclang-tidyto report different results.- This may be accomplished by accomplishing bullet 3.
- Verify that the code/lint commands in CI are semantically the same as the local version.
- Some commands on CI are a lot more complicated than they have to be (see flake8).
- Some lints on CI require the codebase to be a certain way before being run. This may mess with local configurations.
- Be platform-independent. This solution should work on most machines and possible local box configurations.
- Some machines need proxy forwarding to download binaries.
- Currently, all the code run in CI is fit for Ubuntu only.
Possible (Barebone) Approaches
- We update our Makefile to contain more targets that would each verify a part of our lint workflows on CI (e.g., one for
flake8, one formypy,clang-tidy...). We could have a target calledlintthat depends on all of them, so that one could runmake lintand have all their code checked. - We use a pre-commit hook that would run the code we have in our lint workflows on CI.
- Feel free to suggest others
Additional context
I believe the way to fully resolve this issue is to tackle it step by step. The preliminary method may not cover all the requirements just yet, but that's probably fine as long as there is progress.
cc @malfet @seemethere @walterddr @ezyang @pytorch/pytorch-dev-infra