Skip to content

Commit ded60a4

Browse files
authored
Add Ruff for formatting and linting (#877)
* Reformat with ruff * Add ruff * Check lint error * Fix * Fix test
1 parent 8fcc1a3 commit ded60a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+956
-493
lines changed

.flake8

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

.github/workflows/tests.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,27 @@ on:
1212

1313
jobs:
1414

15+
style:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Install Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.11"
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install ruff==0.4.6
27+
# Update output format to enable automatic inline annotations.
28+
- name: Run Ruff Linter
29+
run: ruff check --output-format=github
30+
- name: Run Ruff Formatter
31+
run: ruff format --check
32+
1533
test:
1634
runs-on: ubuntu-latest
35+
needs: [style]
1736
steps:
1837
- uses: actions/checkout@v2
1938
- name: Set up Python ${{ matrix.python-version }}
@@ -25,3 +44,6 @@ jobs:
2544
python -m pip install --upgrade pip
2645
pip install torch==1.9.0+cpu torchvision==0.10.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
2746
make install_dev
47+
- name: Test with pytest
48+
run: make test
49+

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,7 @@ venv.bak/
105105
/site
106106

107107
# mypy
108-
.mypy_cache/
108+
.mypy_cache/
109+
110+
# ruff
111+
.ruff_cache/

.pre-commit-config.yaml

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

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
python3 -m venv .venv
55

66
install_dev: .venv
7-
.venv/bin/pip install -e .[test]
8-
.venv/bin/pre-commit install
7+
.venv/bin/pip install -e ".[test]"
98

109
test: .venv
1110
.venv/bin/pytest -p no:cacheprovider tests/
@@ -16,7 +15,9 @@ table:
1615
table_timm:
1716
.venv/bin/python misc/generate_table_timm.py
1817

19-
precommit: install_dev
20-
.venv/bin/pre-commit run --all-files
18+
fixup:
19+
.venv/bin/ruff check --fix
20+
.venv/bin/ruff format
21+
22+
all: fixup test
2123

22-
all: precommit test

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ make install_dev # create .venv, install SMP in dev mode
478478
#### Run tests and code checks
479479

480480
```bash
481-
make all # run precommit, tests
481+
make fixup # Ruff for formatting and lint checks
482482
```
483483

484484
#### Update table with encoders

docs/conf.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
# import sys
1515
# sys.path.insert(0, os.path.abspath('.'))
1616

17-
import os
18-
import re
1917
import sys
2018
import datetime
19+
import sphinx_rtd_theme
2120

2221
sys.path.append("..")
2322

@@ -68,14 +67,11 @@ def get_version():
6867
# a list of builtin themes.
6968
#
7069

71-
import sphinx_rtd_theme
72-
7370
html_theme = "sphinx_rtd_theme"
7471
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
7572

7673
# import karma_sphinx_theme
7774
# html_theme = "karma_sphinx_theme"
78-
import faculty_sphinx_theme
7975

8076
html_theme = "faculty_sphinx_theme"
8177

misc/generate_table.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44

55

66
WIDTH = 32
7-
COLUMNS = [
8-
"Encoder",
9-
"Weights",
10-
"Params, M",
11-
]
7+
COLUMNS = ["Encoder", "Weights", "Params, M"]
128

139

1410
def wrap_row(r):
1511
return "|{}|".format(r)
1612

1713

1814
header = "|".join([column.ljust(WIDTH, " ") for column in COLUMNS])
19-
separator = "|".join(["-" * WIDTH] + [":" + "-" * (WIDTH - 2) + ":"] * (len(COLUMNS) - 1))
15+
separator = "|".join(
16+
["-" * WIDTH] + [":" + "-" * (WIDTH - 2) + ":"] * (len(COLUMNS) - 1)
17+
)
2018

2119
print(wrap_row(header))
2220
print(wrap_row(separator))

misc/generate_table_timm.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,29 @@ def make_table(data):
2424

2525
l1 = "+" + "-" * max_len1 + "+" + "-" * max_len2 + "+\n"
2626
l2 = "+" + "=" * max_len1 + "+" + "=" * max_len2 + "+\n"
27-
top = "| " + "Encoder name".ljust(max_len1 - 2) + " | " + "Support dilation".center(max_len2 - 2) + " |\n"
27+
top = (
28+
"| "
29+
+ "Encoder name".ljust(max_len1 - 2)
30+
+ " | "
31+
+ "Support dilation".center(max_len2 - 2)
32+
+ " |\n"
33+
)
2834

2935
table = l1 + top + l2
3036

3137
for k in sorted(data.keys()):
32-
support = "✅".center(max_len2 - 3) if data[k]["has_dilation"] else " ".center(max_len2 - 2)
38+
support = (
39+
"✅".center(max_len2 - 3)
40+
if data[k]["has_dilation"]
41+
else " ".center(max_len2 - 2)
42+
)
3343
table += "| " + k.ljust(max_len1 - 2) + " | " + support + " |\n"
3444
table += l1
3545

3646
return table
3747

3848

3949
if __name__ == "__main__":
40-
4150
supported_models = {}
4251

4352
with tqdm(timm.list_models()) as names:

pyproject.toml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +0,0 @@
1-
[tool.black]
2-
line-length = 119
3-
target-version = ['py37', 'py38']
4-
include = '\.pyi?$'
5-
exclude = '''
6-
/(
7-
\.eggs
8-
| \.git
9-
| \.hg
10-
| \.mypy_cache
11-
| \.tox
12-
| \.venv
13-
| docs
14-
| _build
15-
| buck-out
16-
| build
17-
| dist
18-
)/
19-
'''

0 commit comments

Comments
 (0)