Skip to content

Commit 7d08002

Browse files
committed
chore: switch linter and formatter to ruff
1 parent 406509c commit 7d08002

File tree

3 files changed

+148
-68
lines changed

3 files changed

+148
-68
lines changed

.flake8

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

.pre-commit-config.yaml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,12 @@ repos:
55
hooks:
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
8-
- repo: https://github.com/psf/black
9-
rev: 22.3.0
8+
- repo: https://github.com/astral-sh/ruff-pre-commit
9+
# Ruff version.
10+
rev: v0.1.11
1011
hooks:
11-
- id: black
12-
args: [--config=pyproject.toml]
13-
language_version: python3
14-
15-
- repo: https://github.com/PyCQA/isort
16-
rev: 5.10.1
17-
hooks:
18-
- id: isort
19-
args: [--multi-line=3, "--profile", "black", "--filter-files"]
20-
name: imports
21-
- repo: https://github.com/PyCQA/flake8
22-
rev: 4.0.1
23-
hooks:
24-
- id: flake8
25-
args: [--config=.flake8]
26-
additional_dependencies: [flake8-docstrings==1.6.0, flake8-black>=0.2.3]
27-
language_version: python3
28-
name: PEP8
12+
# Run the linter.
13+
- id: ruff
14+
args: [ --fix ]
15+
# Run the formatter.
16+
- id: ruff-format

pyproject.toml

Lines changed: 140 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@ minversion = "6.0"
5959
addopts = "-ra -v"
6060
markers = ["cuda (deselect with '-m \"nocuda\"')"]
6161

62-
[tool.isort]
63-
profile = "black"
64-
skip = [".gitignore", ".dockerignore", ".md", ".json"]
65-
multi_line_output = 3
66-
67-
[tool.black]
68-
line-length = 88
69-
70-
[tool.flake8]
71-
max-line-length = 88
72-
extend-ignore = "E203,D103,D104,D401"
73-
max-complexity = 10
74-
exclude = ".git,__pycache__,docs/source/conftest.py,old,build,dist,test,tests"
75-
7662
[tool.coverage.run]
7763
source = ["cellseg_models_pytorch"]
7864

@@ -91,11 +77,146 @@ exclude_lines = [
9177
"def extra_repr",
9278
]
9379

94-
[tool.mypy]
95-
warn_return_any = false
96-
warn_unused_configs = true
97-
ignore_missing_imports = true
98-
plugins = "numpy.typing.mypy_plugin"
80+
[tool.ruff]
81+
select = [
82+
"A", # flake8-builtins
83+
"B", # flake8-bugbear
84+
"D", # pydocstyle, need to enable for docstrings check.
85+
"E", # pycodestyle - Error
86+
"F", # pyflakes
87+
"G", # flake8-logging-format
88+
"I", # Isort
89+
"N", # pep8-naming
90+
"S", # flake8-bandit
91+
"W", # pycodestyle - Warning
92+
"Q", # flake8-quotes
93+
"C4", # flake8-comprehensions
94+
"FA", # flake8-future-annotations
95+
"EM", # flake8-errmsg
96+
"PD", # pandas-vet
97+
"PL", # Pylint
98+
"PT", # flake8-pytest-style
99+
"TD", # flake8-todos
100+
"UP", # pyupgrade
101+
"C90", # mccabe
102+
"T10", # flake8-debugger
103+
"T20", # flake8-print
104+
"ANN", # flake8-annotations
105+
"ARG", # flake8-unused-arguments
106+
"BLE", # flake8-blind-except
107+
"COM", # flake8-commas
108+
"DTZ", # flake8-datetimez
109+
"ERA", # eradicate
110+
"FBT", # flake8-boolean-trap
111+
"FIX", # flake8-fixme
112+
"FLY", # flynt
113+
"ICN", # flake8-import-conventions
114+
"INP", # flake8-no-pep420
115+
"INT", # flake8-gettext
116+
"ISC", # flake8-implicit-str-concat
117+
"NPY", # NumPy-specific rules
118+
"PGH", # pygrep-hooks
119+
"PIE", # flake8-pie
120+
"PTH", # flake8-use-pathlib
121+
"PYI", # flake8-pyi
122+
"RET", # flake8-return
123+
"RSE", # flake8-raise
124+
"RUF", # Ruff-specific rules
125+
"SLF", # flake8-self
126+
"SIM", # flake8-simplify
127+
"TID", # flake8-tidy-imports
128+
"TCH", # flake8-type-checking
129+
"TRY", # tryceratops
130+
"YTT", # flake8-2020
131+
"PERF", # Perflint
132+
"SLOT", # flake8-slots
133+
"ASYNC", # flake8-async
134+
]
135+
136+
include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"]
137+
extend-include = ["*.ipynb"]
138+
# Exclude a variety of commonly ignored directories.
139+
exclude = [
140+
".bzr",
141+
".direnv",
142+
".eggs",
143+
".git",
144+
".git-rewrite",
145+
".hg",
146+
".ipynb_checkpoints",
147+
".mypy_cache",
148+
".nox",
149+
".pants.d",
150+
".pyenv",
151+
".pytest_cache",
152+
".pytype",
153+
".ruff_cache",
154+
".svn",
155+
".tox",
156+
".venv",
157+
".vscode",
158+
"conftest.py",
159+
"old",
160+
"test",
161+
"tests",
162+
"__pypackages__",
163+
"__pycache__",
164+
"_build",
165+
"docs",
166+
"source",
167+
"buck-out",
168+
"build",
169+
"dist",
170+
"node_modules",
171+
"site-packages",
172+
"venv",
173+
]
174+
175+
# Same as Black.
176+
line-length = 88
177+
indent-width = 4
178+
179+
# Assume Python 3.10
180+
target-version = "py310"
181+
182+
[tool.ruff.pydocstyle]
183+
# Use numpy-style docstrings.
184+
convention = "google"
185+
186+
[tool.ruff.lint]
187+
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
188+
select = ["E4", "E7", "E9", "F"]
189+
ignore = ["E203", "D103", "D104", "E501"]
190+
191+
# Allow fix for all enabled rules (when `--fix`) is provided.
192+
fixable = ["ALL"]
193+
unfixable = ["B"]
194+
195+
# Allow unused variables when underscore-prefixed.
196+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
197+
198+
[tool.ruff.format]
199+
# Like Black, use double quotes for strings.
200+
quote-style = "double"
201+
202+
# Like Black, indent with spaces, rather than tabs.
203+
indent-style = "space"
204+
205+
# Like Black, respect magic trailing commas.
206+
skip-magic-trailing-comma = false
207+
208+
# Like Black, automatically detect the appropriate line ending.
209+
line-ending = "auto"
210+
211+
# format docs
212+
docstring-code-format = true
213+
214+
# docstr code line length
215+
# docstring-code-line-length = "dynamic"
216+
217+
[tool.ruff.lint.per-file-ignores]
218+
"__init__.py" = ["E402"]
219+
"**/{tests,docs,tools}/*" = ["E402"]
99220

100221
[build-system]
101222
requires = ["poetry-core>=1.0.0"]

0 commit comments

Comments
 (0)