Repository navigation
Expand file tree
/
Copy pathpyproject.toml
More file actions
221 lines (187 loc) · 9.96 KB
/
Copy pathpyproject.toml
File metadata and controls
221 lines (187 loc) · 9.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
[tool.ruff]
target-version = "py312"
line-length = 120
exclude = [
# Python 2-era scripts with syntax errors that predate linting
"scripts/add_is_cited_field.py",
"scripts/bavli_word_count.py",
"scripts/lexicon/adjust_laaz_rashi_add_forms.py",
"scripts/split_commentaries.py",
]
[tool.ruff.lint]
select = [
"E", # pycodestyle errors — PEP 8 style violations (indentation, whitespace, line length)
"W", # pycodestyle warnings — softer PEP 8 issues (trailing whitespace, blank lines)
"F", # pyflakes — undefined names, unused imports, unused variables
"I", # isort — import order, grouping, and section formatting
"B", # flake8-bugbear — likely bugs and design issues (mutable defaults, bare excepts, loop variable misuse)
"UP", # pyupgrade — modernises syntax to target Python version (f-strings, new-style hints, etc.)
"N", # pep8-naming — enforces PEP 8 naming conventions for classes, functions, variables, and type args
"PTH", # flake8-use-pathlib — replaces os.path calls with pathlib equivalents
"T20", # flake8-print — flags print() and pprint() calls left in code
"PLE", # pylint errors — subset of Pylint covering only error-level issues (e.g. bad format strings, return outside function)
"SIM", # flake8-simplify — suggests simpler rewrites (collapsed ifs, ternaries, redundant open modes)
"RET", # flake8-return — enforces clean return patterns (no implicit None, no redundant elif after return)
"TD", # flake8-todos — enforces consistent TODO comment format (author, issue link, etc.)
"ASYNC", # flake8-async — detects blocking calls (time.sleep, open, HTTP) inside async functions
"A", # flake8-builtins — warns when variable or argument names shadow Python builtins (e.g. list, id, type)
"COM", # flake8-commas — enforces trailing commas in multi-line collections and function signatures
"C4", # flake8-comprehensions — rewrites unnecessary generators/comprehensions to simpler forms
"DJ", # flake8-django — Django-specific checks (null on string fields, ModelForm misuse, missing __str__)
"EM", # flake8-errmsg — disallows string literals directly in raise statements; assign to a variable first
"FIX", # flake8-fixme — flags FIXME, TODO, XXX, and HACK comments as unresolved issues
"PIE", # flake8-pie — misc improvements (unnecessary pass, duplicate class fields, non-unique enums)
"PT", # flake8-pytest-style — enforces consistent pytest patterns (fixture scope, raises usage, parametrize format)
"Q", # flake8-quotes — enforces consistent quote style (single vs double) across the codebase
"RSE", # flake8-raise — flags unnecessary parentheses in raise statements
"ARG", # flake8-unused-arguments — flags unused function, method, and lambda arguments
]
ignore = [
"PLR0913", # too many arguments
# ── Legacy codebase — deferred to incremental follow-up work ──────────────
# Import style: `from module import *` is pervasive in Django settings and legacy Sefaria modules
"F403", # undefined-local-with-import-star
"F405", # undefined-local-with-import-star-usage
# Unused imports: many are re-exported from __init__.py; unsafe to auto-remove
"F401", # unused-import
# Module-level imports not at top: Django conditional imports and settings inheritance
"E402", # module-import-not-at-top-of-file
# Line length: formatter handles what it can; remaining are strings/comments that can't be broken
"E501", # line-too-long
# Trailing commas: managed by ruff format; avoid duplicate enforcement
"COM812", # missing-trailing-comma
"COM819", # prohibited-trailing-comma
# Print statements: intentional in management commands, scripts, and debug helpers
"T201", # print
"T203", # pprint
# Pytest style: codebase uses unittest-style assertions (assertTrue etc.) in pytest; migrate incrementally
"PT009", # pytest-unittest-assertion
"PT027", # pytest-unittest-raises-assertion
"PT007", # pytest-parametrize-values-wrong-type
"PT006", # pytest-parametrize-names-wrong-type
"PT018", # pytest-composite-assertion
"PT011", # pytest-raises-too-broad
"PT012", # pytest-raises-with-multiple-statements
"PT019", # pytest-fixture-param-without-value
"PT017", # pytest-assert-in-except
"B017", # assert-raises-exception
# Unused arguments: Django views and callbacks require specific signatures
"ARG001", # unused-function-argument
"ARG002", # unused-method-argument
"ARG003", # unused-class-method-argument
"ARG004", # unused-static-method-argument
"ARG005", # unused-lambda-argument
# Naming conventions: existing code has established patterns (Rx, CamelCase vars, etc.)
"N802", # invalid-function-name
"N803", # invalid-argument-name
"N806", # non-lowercase-variable-in-function
"N801", # invalid-class-name
"N805", # invalid-first-argument-name-for-method
"N815", # mixed-case-variable-in-class-scope
"N816", # mixed-case-variable-in-global-scope
"N818", # error-suffix-on-exception-name
# pathlib migration: large-scale refactor, tracked separately
"PTH100", # os-path-abspath
"PTH103", # os-makedirs
"PTH107", # os-remove
"PTH110", # os-path-exists
"PTH111", # os-path-expanduser
"PTH112", # os-path-isdir
"PTH113", # os-path-isfile
"PTH116", # os-stat
"PTH118", # os-path-join
"PTH119", # os-path-basename
"PTH120", # os-path-dirname
"PTH122", # os-path-splitext
"PTH123", # builtin-open
"PTH202", # os-path-getsize
"PTH204", # os-path-getmtime
"PTH207", # glob
"PTH208", # os-listdir
# Exception message style: string literals in raise — refactor separately
"EM101", # raw-string-in-exception
"EM102", # f-string-in-exception
"EM103", # dot-format-in-exception
# TODO/FIXME comment format: enforce author and link in follow-up tooling
"TD002", # missing-todo-author
"TD003", # missing-todo-link
"TD004", # missing-todo-colon
"TD005", # missing-todo-description
"FIX002", # line-contains-todo
"FIX004", # line-contains-hack
# Return patterns: existing code style; refactor incrementally
"RET503", # implicit-return
"RET504", # unnecessary-assign
# Ambiguous variable names: conventional in math/algorithm code (l for length, etc.)
"E741", # ambiguous-variable-name
# Builtin shadowing: common in Django (type=, list=, id=)
"A001", # builtin-variable-shadowing
"A002", # builtin-argument-shadowing
"A006", # builtin-lambda-argument-shadowing
# zip() without strict: existing code; add strict incrementally
"B905", # zip-without-explicit-strict
# printf-style formatting: existing i18n strings; migrate to f-strings separately
"UP031", # printf-string-formatting
# Exception handling patterns: existing code style
"E722", # bare-except (refactor to specific exception types separately)
"B904", # raise-without-from-inside-except
# Simplification patterns: incrementally adopt
"SIM102", # collapsible-if
"SIM105", # suppressible-exception
"SIM108", # if-else-block-instead-of-if-exp
"SIM113", # enumerate-for-loop
"SIM115", # open-file-with-context-handler
"SIM401", # if-else-block-instead-of-dict-get
"SIM110", # reimplemented-builtin
"SIM101", # duplicate-isinstance-call
# Loop variable patterns
"B007", # unused-loop-control-variable
"B023", # function-uses-loop-variable
"B020", # loop-variable-overrides-iterator
# Comprehension / collection patterns
"C401", # unnecessary-generator-set
"C409", # unnecessary-literal-within-tuple-call
"C414", # unnecessary-double-cast-or-process
# Miscellaneous: refactor separately
"B015", # useless-comparison
"B018", # useless-expression
"B026", # star-arg-unpacking-after-keyword-arg
"E721", # type-comparison (use isinstance)
"DJ001", # django-nullable-model-string-field
"DJ012", # django-unordered-body-content-in-model
"UP028", # yield-in-for-loop
"UP040", # non-pep695-type-alias
"W291", # trailing-whitespace (formatter handles; remaining are in parse-error files)
"W293", # blank-line-with-whitespace
# Naming: less-common naming patterns (import aliases, module names) — ignore these less-common N-codes
"N807", # dunder-function-name
"N812", # lowercase-imported-as-non-lowercase
"N813", # camelcase-imported-as-lowercase
"N817", # camelcase-imported-as-acronym
"N999", # invalid-module-name
# Type annotations: Optional[X] vs X | None — migrate incrementally with TypeScript adoption
"UP007", # non-pep604-annotation-union
# Regex sub: positional args are fine for simple patterns
"B034", # re-sub-positional-args
# Django model conventions: enforce separately as part of model cleanup
"DJ007", # django-all-with-model-form
"DJ008", # django-model-without-dunder-str
# Ambiguous function names: established patterns (l, O, I are used in math code)
"E743", # ambiguous-function-name
# Simplification: minor, non-critical
"SIM103", # needless-bool
]
[tool.ruff.lint.isort]
# Import sections must not depend on which files exist on disk. `sefaria/local_settings.py` is gitignored: present on
# dev machines, absent in CI. Without this, Ruff classified `from sefaria.local_settings import ...` differently in
# the two environments, so I001 passed locally and failed in CI (scripts/bookworm_list.py).
known-first-party = ["sefaria"]
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
[tool.ruff.lint.per-file-ignores]
"*/migrations/*.py" = ["E501", "N", "I", "E711", "E712", "F601"]
"manage.py" = ["T20"]
"**/tests/**/*.py" = ["PT009", "PT027", "ARG", "F821"]
"scripts/**/*.py" = ["T20", "E402", "F401", "ARG", "F811", "F821", "B006", "F841"]
"**/conftest.py" = ["F401", "ARG"]