-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathpyproject.toml
More file actions
243 lines (229 loc) · 9.87 KB
/
pyproject.toml
File metadata and controls
243 lines (229 loc) · 9.87 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# NOTE: You have to use single-quoted strings in TOML for regular expressions.
# It's the equivalent of r-strings in Python. Multiline strings are treated as
# verbose regular expressions by Black. Use [ ] to denote a significant space
# character.
[project]
name = "openlibrary"
version = "1.0.0"
requires-python = ">=3.12.2,<3.12.3"
[tool.black]
skip-string-normalization = true
target-version = ["py311"]
[tool.codespell]
ignore-words-list = "beng,curren,datas,furst,nd,nin,ot,ser,spects,te,tha,ue,upto,thirdparty"
skip = "./.*,*/ocm00400866,*/read_toc.py,*.it,*.js,*.json,*.mrc,*.page,*.pg_dump,*.po,*.txt,*.xml,*.yml"
[tool.mypy]
ignore_missing_imports = true
pretty = true
scripts_are_modules = true
show_error_codes = true
show_error_context = true
exclude = ["vendor/"]
[[tool.mypy.overrides]]
module = [
"infogami.*",
"openlibrary.plugins.worksearch.code"
]
ignore_errors = true
[[tool.mypy.overrides]]
# In general, we want to have typed definitions so we are slowly turning it on for a few files.
module = ["openlibrary.core.wikidata", "openlibrary.core.yearly_reading_goals"]
disallow_untyped_defs = true
[tool.pytest.ini_options]
strict = true
asyncio_mode = "strict"
asyncio_default_fixture_loop_scope = "function"
filterwarnings = [
# Ignore warnings from webob, which doesn't have a fix.
# It comes from webtest, which we will remove when fastapi is done
'ignore::DeprecationWarning:webob',
# Ignore sqlite3 default timestamp converter warnings from web.py (Python 3.12 deprecation)
'ignore:The default timestamp converter is deprecated:DeprecationWarning:web',
]
addopts = "-m 'not integration'"
markers = [
"integration: marks tests as integration tests that require external services (deselect with '-m \"not integration\"')"
]
[tool.ruff]
target-version = "py312"
extend-exclude = [
"./.*",
"vendor",
]
lint.ignore = [
"B007", # unused-loop-control-variable - not a big deal for us
"B023", # function-uses-loop-variable - doesn't matter for our lambdas but it's a good rule
"B904", # raise-without-from-inside-except - not sure but it seems fine for now
"PERF401", # manual-list-comprehension - we prefer readability
"PIE790", # unnecessary-placeholder - could be removed but not much gain
"PLW0603", # global-statement - we use it a lot...
"PLW2901", # redefined-loop-name - would be a lot of work to fix
"RUF005", # collection-literal-concatenation - this works for us as is
"SIM108", # if-else-block-instead-of-if-exp - we prefer the readability instead of ternaries
"SLF001", # private-member-access - unfortunately we use these quite often for infogami
"UP031", # printf-string-formatting - a ton of work to fix to 224 errors
# TODO: these could be fixed one day
"TC003", # Move standard library import into a type-checking block. Should enable later
"TC006", # runtime-cast-value - we don't do this now but could in a future PR
"B905", # zip-without-explicit-strict - TODO: seems like we should fix this one
"E402", # module-import-not-at-top-of-file - TODO: we should probably enable this and and add exceptions
# openlibrary/plugins/admin/code.py - maybe it can be fixed
# openlibrary/plugins/openlibrary/code.py - unclear but has many
# openlibrary/plugins/openlibrary/filters.py - can fix
# openlibrary/plugins/upstream/jsdef.py - can remove
# openlibrary/plugins/upstream/utils.py - unclear but it's huge
# scripts/tests/test_affiliate_server.py - probably needed for side effects
# scripts/tests/test_solr_updater.p - probably needed for side effects
"PLC0415", # import-outside-top-level we really need to turn this on but it's a decently big change
]
line-length = 162
lint.select = [
"ASYNC", # flake8-async
"B", # flake8-bugbear
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"C90", # McCabe cyclomatic complexity
"E", # pycodestyle
"F", # Pyflakes
"FA", # flake8-future-annotations
"FAST", # FastAPI rules
"FLY", # flynt
"FURB", # refurb
"G010", # flake8-logging-format
"I", # isort
"ICN", # flake8-import-conventions
"INT", # flake8-gettext
"ISC", # flake8-implicit-str-concat
"PERF", # Perflint
"PIE", # flake8-pie
"PL", # Pylint
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"RSE", # flake8-raise
"RUF", # Ruff-specific rules
"SIM", # flake8-simplify
"SLF", # flake8-self
"SLOT", # flake8-slots
"T10", # flake8-debugger
"TC", # flake8-type-checking
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
# "A", # flake8-builtins
# "AIR", # Airflow
# "ANN", # flake8-annotations
# "ARG", # flake8-unused-arguments
# "COM", # flake8-commas
# "CPY", # Copyright-related rules
# "D", # pydocstyle
# "DJ", # flake8-django
# "DTZ", # flake8-datetimez
# "EM", # flake8-errmsg
# "ERA", # eradicate
# "EXE", # flake8-executable
# "FBT", # flake8-boolean-trap
# "FIX", # flake8-fixme
# "G", # flake8-logging-format
# "INP", # flake8-no-pep420
# "N", # pep8-naming
# "NPY", # NumPy-specific rules
# "PD", # pandas-vet
# "PGH", # pygrep-hooks
# "PTH", # flake8-use-pathlib
# "Q", # flake8-quotes
# "RET", # flake8-return
# "S", # flake8-bandit
# "T20", # flake8-print
# "TD", # flake8-todos
# "TID", # flake8-tidy-imports
# "TRY", # tryceratops
]
[tool.ruff.lint.mccabe]
max-complexity = 28
[tool.ruff.lint.pylint]
allow-magic-value-types = ["bytes", "float", "int", "str"]
max-args = 15
max-branches = 23
max-returns = 14
max-statements = 70
[tool.ruff.lint.per-file-ignores]
"openlibrary/admin/stats.py" = ["BLE001"]
"openlibrary/catalog/add_book/tests/test_add_book.py" = ["PT007"]
"openlibrary/catalog/get_ia.py" = ["BLE001", "E722"]
"openlibrary/catalog/utils/edit.py" = ["E722"]
"openlibrary/catalog/utils/query.py" = ["E722"]
"openlibrary/core/booknotes.py" = ["E722"]
"openlibrary/core/bookshelves.py" = ["BLE001"]
"openlibrary/core/db.py" = ["SIM105"]
"openlibrary/core/helpers.py" = ["BLE001"]
"openlibrary/core/observations.py" = ["PYI024"]
"openlibrary/core/processors/invalidation.py" = ["BLE001"]
"openlibrary/core/ratings.py" = ["E722"]
"openlibrary/core/sponsorships.py" = ["E722"]
"openlibrary/core/stats.py" = ["BLE001"]
"openlibrary/core/vendors.py" = ["B009"]
"openlibrary/coverstore/code.py" = ["E722"]
"openlibrary/i18n/__init__.py" = ["BLE001"]
"openlibrary/plugins/admin/code.py" = ["E722"]
"openlibrary/plugins/admin/mem.py" = ["E722"]
"openlibrary/plugins/admin/memory.py" = ["E722"]
"openlibrary/plugins/admin/services.py" = ["BLE001"]
"openlibrary/plugins/books/dynlinks.py" = ["E722"]
"openlibrary/plugins/books/readlinks.py" = ["E722"]
"openlibrary/plugins/importapi/code.py" = ["BLE001"]
"openlibrary/plugins/ol_infobase.py" = ["BLE001"]
"openlibrary/plugins/openlibrary/code.py" = ["BLE001", "E722"]
"openlibrary/plugins/openlibrary/connection.py" = ["E722"]
"openlibrary/plugins/openlibrary/stats.py" = ["BLE001"]
"openlibrary/plugins/upstream/account.py" = ["BLE001"]
"openlibrary/plugins/upstream/borrow.py" = ["BLE001", "E722"]
"openlibrary/plugins/upstream/models.py" = ["BLE001"]
"openlibrary/plugins/upstream/utils.py" = ["BLE001"]
"openlibrary/solr/solr_types.py" = ["UP007"]
"openlibrary/utils/retry.py" = ["BLE001"]
"openlibrary/utils/open_syllabus_project.py" = ["BLE001"]
"openlibrary/utils/schema.py" = ["PERF402"]
"openlibrary/utils/tests/test_retry.py" = ["PT012", "PT017"]
"scripts/affiliate_server*.py" = ["SIM105"]
"scripts/copydocs.py" = ["BLE001", "PYI024"]
"scripts/delete_import_items.py" = ["BLE001"]
"scripts/import_book_covers.py" = ["BLE001"]
"scripts/lc_marc_update.py" = ["E722"]
"scripts/manage-imports.py" = ["BLE001"]
"scripts/sitemaps/sitemap.py" = ["BLE001"]
"scripts/solr_builder/solr_builder/solr_builder.py" = ["PYI024", "PLR0913"]
"scripts/tests/test_obfi.py" = ["E501"]
"tests/*" = ["S101"]
[tool.sqlfluff.core]
dialect = "postgres"
# ── Rule Exclusions ──────────────────────────────────────────────────
# Only rules that conflict with the existing codebase style are excluded.
# Each exclusion includes a rationale so reviewers can evaluate them.
#
# Layout:
# LT01 - trailing whitespace: already enforced by pre-commit trailing-whitespace hook
# LT02 - newline at end of file: already enforced by pre-commit end-of-file-fixer hook
# LT05 - line length (80 chars): existing SQL files (schema, dump scripts) have many lines
# exceeding 80 chars; enforcing would require major reformatting of stable schema files
# Capitalisation:
# CP01-CP05 - keyword/function/datatype casing: codebase consistently uses lowercase
# keywords throughout; enforcing upper-case would touch every SQL file
# Aliasing:
# AL01 - implicit aliasing: codebase omits explicit "AS" for table aliases, valid Postgres style
# AL02 - implicit column aliasing: same as AL01 but for columns
# AL03 - self-alias (e.g. "x AS x"): existing dump scripts use self-aliases for clarity
# AL09 - self-aliased columns: same pattern as AL03, catches additional self-alias variants
# References:
# RF04 - keywords as identifiers: columns named "key", "type", "action", "created" are
# deeply embedded in the schema and cannot be renamed
# Structure:
# ST06 - SELECT column ordering: dump scripts' column order matches the public dump API
# documented at openlibrary.org/developers/dumps
# Ambiguous:
# AM05 - fully qualified joins: some dump scripts use implicit join conditions; these are
# stable scripts where changing join syntax risks introducing bugs
# Joins:
# JJ01 - explicit join type: bare JOIN (implicit INNER) is the codebase convention
exclude_rules = "LT01,LT02,LT05,CP01,CP02,CP03,CP04,CP05,AL01,AL02,AL03,AL09,RF04,ST06,AM05,JJ01"
[tool.sqlfluff.indentation]
tab_space_size = 4