Skip to content

Commit fac2762

Browse files
committed
migrated from flake8, isort and others to ruff
1 parent acccc45 commit fac2762

File tree

2 files changed

+86
-114
lines changed

2 files changed

+86
-114
lines changed

{{cookiecutter.project_slug}}/.pre-commit-config.yaml

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,83 +8,35 @@ default_stages:
88
- pre-push
99
minimum_pre_commit_version: 3.0.0
1010
repos:
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: v0.11.8 # Check for latest version
13+
hooks:
14+
- id: ruff
15+
args: [--fix, --show-fixes]
16+
- id: ruff-format
1117
- repo: https://github.com/deeenes/unexport
1218
rev: 0.4.0-patch0-8
1319
hooks:
1420
- id: unexport
1521
args: [--refactor, --single_quotes]
1622
exclude: __init__.py$
17-
- repo: https://github.com/google/yapf
18-
rev: v0.43.0
19-
hooks:
20-
- id: yapf
21-
additional_dependencies: [toml]
22-
stages: [manual]
23-
- repo: https://github.com/psf/black
24-
rev: 25.1.0
25-
hooks:
26-
- id: black
27-
additional_dependencies: [toml]
28-
stages: [manual]
29-
- repo: https://github.com/Instagram/Fixit
30-
rev: 9d59f968e84bd2773f34b0069eeeaad3ce783254
31-
hooks:
32-
- id: fixit-run-rules
33-
stages: [manual]
34-
- repo: https://github.com/PyCQA/isort
35-
rev: 6.0.1
36-
hooks:
37-
- id: isort
38-
additional_dependencies: [toml]
39-
# This is supposed to be replaced by pyupgrade:
40-
- repo: https://github.com/snok/pep585-upgrade
41-
rev: v1.0.1
42-
hooks:
43-
- id: upgrade-type-hints
44-
args: [--futures=true]
45-
- repo: https://github.com/asottile/add-trailing-comma
46-
rev: v3.1.0
47-
hooks:
48-
- id: add-trailing-comma
49-
# This is very old, it maybe even fails;
50-
# And maybe pre-commit/double-quote-string-fixer replaces it
51-
- repo: https://github.com/myint/unify
52-
rev: v0.5
53-
hooks:
54-
- id: unify
5523
- repo: https://github.com/pre-commit/pre-commit-hooks
5624
rev: v5.0.0
5725
hooks:
58-
- id: double-quote-string-fixer
5926
- id: detect-private-key
6027
- id: check-ast
61-
- id: check-docstring-first
6228
- id: end-of-file-fixer
6329
- id: check-added-large-files
6430
- id: mixed-line-ending
6531
args: [--fix=lf]
6632
exclude: ^docs/make.bat$
67-
- id: trailing-whitespace
68-
exclude: ^.bumpversion.cfg$
6933
- id: check-merge-conflict
7034
- id: check-case-conflict
7135
- id: check-symlinks
7236
- id: check-yaml
7337
args: [--unsafe]
7438
- id: check-ast
75-
- id: fix-encoding-pragma
76-
args: [--remove] # for Python3 codebase, it's not necessary
7739
- id: requirements-txt-fixer
78-
- repo: https://github.com/PyCQA/flake8
79-
rev: 7.2.0
80-
hooks:
81-
- id: flake8
82-
additional_dependencies:
83-
- Flake8-pyproject
84-
- flake8-docstrings
85-
- flake8-comprehensions
86-
- flake8-bugbear
87-
- git+https://github.com/saezlab/flake8-kwargs-spaces.git
8840
- repo: https://github.com/rstcheck/rstcheck
8941
rev: v6.2.4
9042
hooks:
@@ -94,11 +46,6 @@ repos:
9446
rev: 1.19.1
9547
hooks:
9648
- id: blacken-docs
97-
- repo: https://github.com/asottile/pyupgrade
98-
rev: v3.19.1
99-
hooks:
100-
- id: pyupgrade
101-
args: [--py3-plus, --py38-plus, --keep-runtime-typing]
10249
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
10350
rev: v2.14.0
10451
hooks:
@@ -109,9 +56,6 @@ repos:
10956
- repo: https://github.com/pre-commit/pygrep-hooks
11057
rev: v1.10.0
11158
hooks:
112-
- id: python-no-eval
113-
- id: python-use-type-annotations
114-
- id: python-check-blanket-noqa
11559
- id: rst-backticks
11660
- id: rst-directive-colons
11761
- id: rst-inline-touching-normal

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 80 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ tests = [
5252
"coverage>=6.0",
5353
"codecov-cli>=10.2.0",
5454
"diff_cover",
55+
"ruff",
5556
]
5657
docs = [
5758
"sphinx>=5.0.0",
@@ -79,64 +80,91 @@ Repository = "{{ cookiecutter.project_repo }}"
7980
Issues = "{{ cookiecutter.project_repo }}/issues"
8081
Documentation = "https://{{ cookiecutter.project_slug }}.readthedocs.io/"
8182

82-
[tool.black]
83+
[tool.ruff]
8384
line-length = 80
84-
target-version = ['py31*']
85-
include = '\.pyi?$'
86-
exclude = '''
87-
(
88-
/(
89-
\.eggs
90-
| \.git
91-
| \.hg
92-
| \.mypy_cache
93-
| \.tox
94-
| \.venv
95-
| _build
96-
| buck-out
97-
| build
98-
| dist
99-
)/
100-
)
101-
'''
85+
target-version = py312
86+
unfixable = [ "UP" ]
87+
extend-include = [ "*.ipynb" ]
88+
format = true
89+
format.docstring-code-format = true
90+
format.trailing-comma = "all"
91+
lint.isort.known-first-party =
92+
lint.select = [
93+
"B", # flake8-bugbear
94+
"BLE", # flake8-blind-except
95+
"C4", # flake8-comprehensions
96+
"D", # pydocstyle
97+
"E", # Error detected by Pycodestyle
98+
"F", # Errors detected by Pyflakes
99+
"I", # isort
100+
"RUF100", # Report unused noqa directives
101+
"TID", # flake8-tidy-imports
102+
"UP", # pyupgrade
103+
"W", # Warning detected by Pycodestyle
104+
"Q", # Consistent quotes
105+
"S307", # eval() detection
106+
"ANN", # flake8-annotations
107+
]
108+
lint.ignore = [
109+
"B008", # Errors from function calls in argument defaults. These are fine when the result is immutable.
110+
"B024",
111+
"D100", # Missing docstring in public module
112+
"D104", # Missing docstring in public package
113+
"D105", # __magic__ methods are often self-explanatory, allow missing docstrings
114+
"D107", # Missing docstring in __init__
115+
# Disable one in each pair of mutually incompatible rules
116+
"D200",
117+
"D202",
118+
"D203", # We don’t want a blank line before a class docstring
119+
"D213", # <> We want docstrings to start immediately after the opening triple quote
120+
"D400", # first line should end with a period [Bug: doesn’t work with single-line docstrings]
121+
"D401", # First line should be in imperative mood; try rephrasing
122+
"E131",
123+
"E251",
124+
"E303",
125+
"E501", # line too long -> we accept long comment lines; formatter gets rid of long code lines
126+
"E521",
127+
"E731", # Do not assign a lambda expression, use a def -> lambda expression assignments are convenient
128+
"E741", # allow I, O, l as variable names -> I is the identity matrix
129+
"W503",
130+
"W504",
131+
]
132+
lint.pydocstyle.convention = "numpy"
133+
lint.quotes.inline-quotes = "single"
102134

103-
[tool.isort]
104-
from_first = true
105-
line_length = 80
106-
multi_line_output = 3
107-
include_trailing_comma = true
108-
use_parentheses = true
109-
known_num="numpy,pandas"
110-
sections = "FUTURE,STDLIB,THIRDPARTY,NUM,FIRSTPARTY,LOCALFOLDER"
111-
no_lines_before="LOCALFOLDER"
112-
balanced_wrapping = true
113-
force_grid_wrap = 0
114-
length_sort = "1"
115-
indent = " "
116-
skip = []
135+
[tool.ruff.lint.per-file-ignores]
136+
"docs/*" = [ "I" ]
137+
"docs/src/conf.py" = [ "D100" ]
138+
"tests/*" = [ "D" ]
139+
"tests/conftest.py" = [ "D101", "D102", "D103", "E402" ]
140+
"*/__init__.py" = [ "D104", "F401" ]
117141

118-
[tool.flake8]
119-
extend-select = ["CE101"]
120-
ignore = [
121-
"D200", "D202", "D401", "D105",
122-
"W503", "W504",
123-
"E731", "E131", "E251", "E303",
124-
"B024"
142+
[tool.ruff.lint.isort]
143+
known-first-party = [ "{{ cookiecutter.package_name }}" ]
144+
known-third-party = [ "numpy", "pandas" ]
145+
sections = [
146+
"FUTURE",
147+
"STDLIB",
148+
"THIRDPARTY",
149+
"NUM",
150+
"FIRSTPARTY",
151+
"LOCALFOLDER",
125152
]
126-
per-file-ignores = [
127-
"docs/src/conf.py:D100",
128-
"tests/*:D100,D101,D102,D103,D104,D105",
129-
"tests/conftest.py:D101,D102,D103,E402",
130-
"*/__init__.py:D104,F401"
131-
]
132-
max-line-length = 80
133-
count = true
153+
no-lines-before = [ "LOCALFOLDER" ]
154+
lines-after-imports = 1
155+
combine-as-imports = true
156+
force-sort-within-sections = true
157+
case-sensitive = false
158+
order-by-type = true
159+
length-sort = true
160+
force-wrap-aliases = true
161+
use-parentheses = true
162+
indent = " "
163+
balanced-wrapping = true
164+
include-trailing-comma = true
165+
multi-line-output = 3
134166
exclude = [
135-
".git",
136-
"__pycache__",
137-
"build",
138167
"docs/_build",
139-
"dist"
140168
]
141169

142170
[tool.rstcheck]

0 commit comments

Comments
 (0)