forked from pytorch/torchtitan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add linter setup copied from torchtune (pytorch#34)
note that you should install the pre-commit tool from `dev-requirements.txt` and then you can invoke `pre-commit` from the CLI to get the same linters/formatters applied locally as would be run under CI.
- Loading branch information
Showing
5 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[flake8] | ||
# Suggested config from pytorch that we can adapt | ||
select = B,C,E,F,N,P,T4,W,B9,TOR0,TOR1,TOR2 | ||
max-line-length = 120 | ||
# C408 ignored because we like the dict keyword argument syntax | ||
# E501 is not flexible enough, we're using B950 instead | ||
# N812 ignored because import torch.nn.functional as F is PyTorch convention | ||
# N817 ignored because importing using acronyms is convention (DistributedDataParallel as DDP) | ||
# E731 allow usage of assigning lambda expressions | ||
ignore = | ||
E203,E305,E402,E501,E721,E741,F405,F821,F841,F999,W503,W504,C408,E302,W291,E303,N812,N817,E731 | ||
# shebang has extra meaning in fbcode lints, so I think it's not worth trying | ||
# to line this up with executable bit | ||
EXE001, | ||
# these ignores are from flake8-bugbear; please fix! | ||
B007,B008, | ||
optional-ascii-coding = True | ||
exclude = | ||
./.git, | ||
./docs | ||
./build | ||
./scripts, | ||
./venv, | ||
*.pyi | ||
.pre-commit-config.yaml | ||
*.md | ||
.flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Lint | ||
|
||
on: | ||
pull_request: | ||
|
||
concurrency: | ||
group: lint-${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
defaults: | ||
run: | ||
shell: bash -l -eo pipefail {0} | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.11'] | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v3 | ||
- name: Setup python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Update pip | ||
run: python -m pip install --upgrade pip | ||
- name: Install lint utilities | ||
run: | | ||
python -m pip install pre-commit | ||
pre-commit install-hooks | ||
- id: file_changes | ||
uses: trilom/[email protected] | ||
with: | ||
prNumber: ${{ github.event.number }} | ||
output: ' ' | ||
- name: Lint modified files | ||
run: pre-commit run --files ${{ steps.file_changes.outputs.files }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
exclude: 'build' | ||
|
||
default_language_version: | ||
python: python3 | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: 6306a48f7dae5861702d573c9c247e4e9498e867 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: check-ast | ||
- id: check-merge-conflict | ||
- id: no-commit-to-branch | ||
args: ['--branch=main'] | ||
- id: check-added-large-files | ||
args: ['--maxkb=500'] | ||
- id: end-of-file-fixer | ||
exclude: '^(.*\.svg)$' | ||
|
||
- repo: https://github.com/Lucas-C/pre-commit-hooks | ||
rev: v1.5.4 | ||
hooks: | ||
- id: insert-license | ||
files: \.py$ | ||
args: | ||
- --license-filepath | ||
- docs/license_header.txt | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: 34cbf8ef3950f43d09b85e2e45c15ae5717dc37b | ||
hooks: | ||
- id: flake8 | ||
additional_dependencies: | ||
- flake8-bugbear == 22.4.25 | ||
- pep8-naming == 0.12.1 | ||
- torchfix | ||
args: ['--config=.flake8'] | ||
|
||
- repo: https://github.com/omnilib/ufmt | ||
rev: v2.3.0 | ||
hooks: | ||
- id: ufmt | ||
additional_dependencies: | ||
- black == 22.12.0 | ||
- usort == 1.0.5 | ||
|
||
- repo: https://github.com/jsh9/pydoclint | ||
rev: d88180a8632bb1602a4d81344085cf320f288c5a | ||
hooks: | ||
- id: pydoclint | ||
args: [--config=pyproject.toml] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pytest | ||
pytest-cov | ||
pre-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[tool.pydoclint] | ||
style = 'google' | ||
check-return-types = 'False' | ||
|
||
[tool.pytest.ini_options] | ||
addopts = ["--showlocals"] # show local variables in tracebacks |