Skip to content

Enable running lints (that we run in CI) locally #55847

@janeyx99

Description

@janeyx99

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

  1. 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.
  2. 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, mypy or clang-tidy to report different results.
    • This may be accomplished by accomplishing bullet 3.
  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.
  4. 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

  1. 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 for mypy, clang-tidy...). We could have a target called lint that depends on all of them, so that one could run make lint and have all their code checked.
  2. We use a pre-commit hook that would run the code we have in our lint workflows on CI.
  3. 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

Metadata

Metadata

Assignees

Labels

module: buildBuild system issuesmodule: ciRelated to continuous integrationtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions