Skip to content

Commit b626d17

Browse files
authored
lintrunner: added black,isort,rustfmt (#22)
1 parent 63c82c1 commit b626d17

20 files changed

+95
-58
lines changed

.github/workflows/lint.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ jobs:
2323
2424
sudo apt-get install -y protobuf-compiler
2525
26+
pip install lintrunner lintrunner-adapters
27+
lintrunner init
28+
2629
pip install .[dev] -v
27-
- name: Run Python Lint
30+
- name: Run lintrunner
2831
run: |
2932
set -eux
3033
31-
black --check .
34+
lintrunner --force-color --all-files
3235
- name: Run Rust Lint
3336
run: |
3437
set -eux

.lintrunner.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[[linter]]
2+
code = 'BLACK-ISORT'
3+
include_patterns = [
4+
'**/*.py',
5+
]
6+
exclude_patterns = []
7+
command = [
8+
'python',
9+
'-m',
10+
'lintrunner_adapters',
11+
'run',
12+
'black_isort_linter',
13+
'--fast',
14+
'--',
15+
'@{{PATHSFILE}}',
16+
]
17+
init_command = [
18+
'python',
19+
'-m',
20+
'lintrunner_adapters',
21+
'run',
22+
'pip_init',
23+
'--dry-run={{DRYRUN}}',
24+
'black==24.10.0', # Use 24.x when ruff styles are updated
25+
'isort==5.13.2',
26+
]
27+
is_formatter = true
28+
29+
[[linter]]
30+
code = 'RUSTFMT'
31+
include_patterns = [
32+
'**/*.rs',
33+
]
34+
command = [
35+
'python',
36+
'-m',
37+
'lintrunner_adapters',
38+
'run',
39+
'rustfmt_linter',
40+
'--binary=rustfmt',
41+
'--config-path=.rustfmt.toml',
42+
'--',
43+
'@{{PATHSFILE}}',
44+
]

.rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edition = "2021"

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ We actively welcome your pull requests.
6060
`torchft` enforces a fairly strict code format with tools such as cargo fmt and black.
6161

6262
```shell
63-
scripts/lint.sh
63+
pip install lintrunner lintrunner-adapters
64+
lintrunner init
65+
lintrunner -a
6466
```
6567

6668
### Tests

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ features = ["pyo3/extension-module"]
2727

2828
[project.scripts]
2929
torchft_lighthouse = "torchft.torchft:lighthouse_main"
30+
31+
[tool.isort]
32+
multi_line_output = 3
33+
combine_as_imports = true

scripts/lint.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

torchft/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
from torchft.manager import Manager
8-
from torchft.process_group import ProcessGroupGloo, ProcessGroupBabyNCCL
7+
from torchft.data import DistributedSampler
98
from torchft.ddp import DistributedDataParallel
9+
from torchft.manager import Manager
1010
from torchft.optim import OptimizerWrapper as Optimizer
11-
from torchft.data import DistributedSampler
11+
from torchft.process_group import ProcessGroupBabyNCCL, ProcessGroupGloo
1212

1313
__all__ = (
1414
"DistributedDataParallel",

torchft/checkpointing_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
from torchft.checkpointing import CheckpointServer
8-
97
import urllib.error
10-
118
from unittest import TestCase
129
from unittest.mock import MagicMock
1310

11+
from torchft.checkpointing import CheckpointServer
12+
1413

1514
class TestCheckpointing(TestCase):
1615
def test_checkpoint_server(self) -> None:

torchft/data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from typing import Optional
1818

1919
import torch.distributed as dist
20-
2120
from torch.utils import data
2221

2322

torchft/data_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
from unittest import TestCase
88

9-
from torchft.data import DistributedSampler
109
from torch.utils.data import Dataset
1110

11+
from torchft.data import DistributedSampler
12+
1213

1314
class DummyDataset(Dataset):
1415
def __init__(self, length: int) -> None:

0 commit comments

Comments
 (0)