Skip to content

Commit 473455d

Browse files
committed
Chore: Format and lint code using Ruff
1 parent 5e4368f commit 473455d

Some content is hidden

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

41 files changed

+1307
-1218
lines changed

docs/conf.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from crate.theme.rtd.conf.sqlalchemy_cratedb import *
1+
from crate.theme.rtd.conf.sqlalchemy_cratedb import * # noqa: F403
22

33
# Fallback guards, when parent theme does not introduce them.
44
if "html_theme_options" not in globals():
@@ -11,21 +11,27 @@
1111
sitemap_url_scheme = "{link}"
1212

1313
# Disable version chooser.
14-
html_context.update({
15-
"display_version": False,
16-
"current_version": None,
17-
"versions": [],
18-
})
14+
html_context.update( # noqa: F405
15+
{
16+
"display_version": False,
17+
"current_version": None,
18+
"versions": [],
19+
}
20+
)
1921

20-
intersphinx_mapping.update({
21-
'py': ('https://docs.python.org/3/', None),
22-
'sa': ('https://docs.sqlalchemy.org/en/20/', None),
23-
'dask': ('https://docs.dask.org/en/stable/', None),
24-
'pandas': ('https://pandas.pydata.org/docs/', None),
25-
})
22+
intersphinx_mapping.update(
23+
{
24+
"py": ("https://docs.python.org/3/", None),
25+
"sa": ("https://docs.sqlalchemy.org/en/20/", None),
26+
"dask": ("https://docs.dask.org/en/stable/", None),
27+
"pandas": ("https://pandas.pydata.org/docs/", None),
28+
}
29+
)
2630

2731
linkcheck_anchors = True
28-
linkcheck_ignore = [r"https://github.com/crate/cratedb-examples/blob/main/by-language/python-sqlalchemy/.*"]
32+
linkcheck_ignore = [
33+
r"https://github.com/crate/cratedb-examples/blob/main/by-language/python-sqlalchemy/.*"
34+
]
2935

3036
rst_prolog = """
3137
.. |nbsp| unicode:: 0xA0

pyproject.toml

Lines changed: 112 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ requires = [
55
"versioningit",
66
]
77

8-
[tool.versioningit.vcs]
9-
method = "git"
10-
default-tag = "0.0.0"
11-
128
[project]
139
name = "sqlalchemy-cratedb"
1410
description = "SQLAlchemy dialect for CrateDB."
@@ -84,34 +80,32 @@ dynamic = [
8480
"version",
8581
]
8682
dependencies = [
87-
'backports.zoneinfo<1; python_version < "3.9"',
88-
"crate==1.0.0dev0",
83+
"backports.zoneinfo<1; python_version<'3.9'",
84+
"crate==1.0.0.dev0",
8985
"geojson<4,>=2.5",
90-
'importlib-resources; python_version < "3.9"',
86+
"importlib-resources; python_version<'3.9'",
9187
"sqlalchemy<2.1,>=1",
9288
"verlib2==0.2",
9389
]
94-
[project.optional-dependencies]
95-
all = [
90+
optional-dependencies.all = [
9691
"sqlalchemy-cratedb[vector]",
9792
]
98-
develop = [
99-
"black<25",
93+
optional-dependencies.develop = [
10094
"mypy<1.12",
10195
"poethepoet<0.28",
10296
"pyproject-fmt<2.3",
10397
"ruff<0.7",
10498
"validate-pyproject<0.20",
10599
]
106-
doc = [
100+
optional-dependencies.doc = [
107101
"crate-docs-theme>=0.26.5",
108102
"sphinx>=3.5,<9",
109103
]
110-
release = [
104+
optional-dependencies.release = [
111105
"build<2",
112106
"twine<6",
113107
]
114-
test = [
108+
optional-dependencies.test = [
115109
"cratedb-toolkit[testing]",
116110
"dask[dataframe]",
117111
"pandas<2.3",
@@ -120,54 +114,81 @@ test = [
120114
"pytest-cov<6",
121115
"pytest-mock<4",
122116
]
123-
vector = [
117+
optional-dependencies.vector = [
124118
"numpy",
125119
]
126-
[project.urls]
127-
changelog = "https://github.com/crate/sqlalchemy-cratedb/blob/main/CHANGES.md"
128-
documentation = "https://cratedb.com/docs/sqlalchemy-cratedb/"
129-
homepage = "https://cratedb.com/docs/sqlalchemy-cratedb/"
130-
repository = "https://github.com/crate/sqlalchemy-cratedb"
131-
[project.entry-points."sqlalchemy.dialects"]
132-
crate = "sqlalchemy_cratedb:dialect"
120+
urls.changelog = "https://github.com/crate/sqlalchemy-cratedb/blob/main/CHANGES.md"
121+
urls.documentation = "https://cratedb.com/docs/sqlalchemy-cratedb/"
122+
urls.homepage = "https://cratedb.com/docs/sqlalchemy-cratedb/"
123+
urls.repository = "https://github.com/crate/sqlalchemy-cratedb"
124+
entry-points."sqlalchemy.dialects".crate = "sqlalchemy_cratedb:dialect"
133125

134126
[tool.black]
135127
line-length = 100
136128

137-
[tool.coverage.paths]
138-
source = [
139-
"src/",
129+
[tool.ruff]
130+
line-length = 100
131+
132+
extend-exclude = [
140133
]
141134

142-
[tool.coverage.run]
143-
branch = false
144-
omit = [
145-
"tests/*",
135+
lint.select = [
136+
# Builtins
137+
"A",
138+
# Bugbear
139+
"B",
140+
# comprehensions
141+
"C4",
142+
# Pycodestyle
143+
"E",
144+
# eradicate
145+
"ERA",
146+
# Pyflakes
147+
"F",
148+
# isort
149+
"I",
150+
# pandas-vet
151+
"PD",
152+
# return
153+
"RET",
154+
# Bandit
155+
"S",
156+
# print
157+
"T20",
158+
"W",
159+
# flake8-2020
160+
"YTT",
146161
]
147162

148-
[tool.coverage.report]
149-
fail_under = 0
150-
show_missing = true
151-
exclude_lines = [
152-
"# pragma: no cover",
153-
"raise NotImplemented"
163+
lint.extend-ignore = [
164+
# zip() without an explicit strict= parameter
165+
"B905",
166+
# Unnecessary generator (rewrite as a `dict` comprehension)
167+
"C402",
168+
# Unnecessary `map` usage (rewrite using a `set` comprehension)
169+
"C417",
170+
# df is a bad variable name. Be kinder to your future self.
171+
"PD901",
172+
# Unnecessary variable assignment before `return` statement
173+
"RET504",
174+
# Unnecessary `elif` after `return` statement
175+
"RET505",
176+
# Probable insecure usage of temporary file or directory
177+
"S108",
178+
# Possible SQL injection vector through string-based query construction
179+
"S608",
154180
]
155181

156-
[tool.mypy]
157-
mypy_path = "src"
158-
packages = ["sqlalchemy_cratedb"]
159-
exclude = [
182+
lint.per-file-ignores."examples/*" = [
183+
"T201", # Allow `print`
184+
]
185+
186+
lint.per-file-ignores."tests/*" = [
187+
"S101", # Allow use of `assert`, and `print`
188+
"S608", # Possible SQL injection vector through string-based query construction
189+
"W291", # Trailing whitespace
190+
"W293", # Blank line contains whitespace
160191
]
161-
check_untyped_defs = true
162-
explicit_package_bases = true
163-
ignore_missing_imports = true
164-
implicit_optional = true
165-
install_types = true
166-
namespace_packages = true
167-
non_interactive = true
168-
# Needed until `mypy-0.990` for `ConverterDefinition` in `converter.py`.
169-
# https://github.com/python/mypy/issues/731#issuecomment-1260976955
170-
# enable_recursive_aliases = true
171192

172193
[tool.pytest.ini_options]
173194
addopts = """
@@ -179,7 +200,7 @@ log_level = "DEBUG"
179200
log_cli_level = "DEBUG"
180201
log_format = "%(asctime)-15s [%(name)-36s] %(levelname)-8s: %(message)s"
181202
pythonpath = [
182-
"src"
203+
"src",
183204
]
184205
testpaths = [
185206
"examples",
@@ -194,60 +215,44 @@ xfail_strict = true
194215
markers = [
195216
]
196217

197-
[tool.ruff]
198-
line-length = 100
199-
200-
select = [
201-
# Bandit
202-
"S",
203-
# Bugbear
204-
"B",
205-
# Builtins
206-
"A",
207-
# comprehensions
208-
"C4",
209-
# eradicate
210-
"ERA",
211-
# flake8-2020
212-
"YTT",
213-
# isort
214-
"I",
215-
# pandas-vet
216-
"PD",
217-
# print
218-
"T20",
219-
# Pycodestyle
220-
"E",
221-
"W",
222-
# Pyflakes
223-
"F",
224-
# return
225-
"RET",
218+
[tool.coverage.paths]
219+
source = [
220+
"src/",
226221
]
227222

228-
extend-ignore = [
229-
# zip() without an explicit strict= parameter
230-
"B905",
231-
# df is a bad variable name. Be kinder to your future self.
232-
"PD901",
233-
# Unnecessary variable assignment before `return` statement
234-
"RET504",
235-
# Unnecessary `elif` after `return` statement
236-
"RET505",
237-
# Probable insecure usage of temporary file or directory
238-
"S108",
223+
[tool.coverage.run]
224+
branch = false
225+
omit = [
226+
"tests/*",
239227
]
240228

241-
extend-exclude = [
229+
[tool.coverage.report]
230+
fail_under = 0
231+
show_missing = true
232+
exclude_lines = [
233+
"# pragma: no cover",
234+
"raise NotImplemented",
242235
]
243236

244-
[tool.ruff.per-file-ignores]
245-
"*/tests/*" = [
246-
"S101", # Allow use of `assert`, and `print`.
247-
"S608", # Possible SQL injection vector through string-based query construction.
237+
[tool.mypy]
238+
mypy_path = "src"
239+
packages = [ "sqlalchemy_cratedb" ]
240+
exclude = [
248241
]
249-
"examples/*" = ["T201"] # Allow `print`
242+
check_untyped_defs = true
243+
explicit_package_bases = true
244+
ignore_missing_imports = true
245+
implicit_optional = true
246+
install_types = true
247+
namespace_packages = true
248+
non_interactive = true
249+
# Needed until `mypy-0.990` for `ConverterDefinition` in `converter.py`.
250+
# https://github.com/python/mypy/issues/731#issuecomment-1260976955
251+
# enable_recursive_aliases = true
250252

253+
[tool.versioningit.vcs]
254+
method = "git"
255+
default-tag = "0.0.0"
251256

252257
# ===================
253258
# Tasks configuration
@@ -256,23 +261,26 @@ extend-exclude = [
256261
[tool.poe.tasks]
257262

258263
check = [
259-
# "lint",
264+
"lint",
260265
"test",
261266
]
262267

263268
format = [
264-
{ cmd = "black ." },
265-
# Configure Ruff not to auto-fix (remove!):
266-
# unused imports (F401), unused variables (F841), `print` statements (T201), and commented-out code (ERA001).
267-
{ cmd = "ruff --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001 ." },
269+
# Format project metadata.
268270
{ cmd = "pyproject-fmt --keep-full-version pyproject.toml" },
271+
272+
# Format code.
273+
# Configure Ruff not to auto-fix a few items that are useful in workbench mode.
274+
# e.g.: unused imports (F401), unused variables (F841), `print` statements (T201), commented-out code (ERA001)
275+
{ cmd = "ruff format" },
276+
{ cmd = "ruff check --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001" },
269277
]
270278

271279
lint = [
272-
{ cmd = "ruff ." },
273-
{ cmd = "black --check ." },
280+
{ cmd = "ruff format --check" },
281+
{ cmd = "ruff check" },
274282
{ cmd = "validate-pyproject pyproject.toml" },
275-
{ cmd = "mypy" },
283+
# { cmd = "mypy" },
276284
]
277285

278286
release = [

src/sqlalchemy_cratedb/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .compat.api13 import monkeypatch_add_exec_driver_sql
2323
from .dialect import dialect
2424
from .predicate import match
25-
from .sa_version import SA_1_4, SA_2_0, SA_VERSION
25+
from .sa_version import SA_1_4, SA_VERSION
2626
from .support import insert_bulk
2727
from .type.array import ObjectArray
2828
from .type.geo import Geopoint, Geoshape
@@ -34,7 +34,8 @@
3434
import warnings
3535

3636
# SQLAlchemy 1.3 is effectively EOL.
37-
SA13_DEPRECATION_WARNING = textwrap.dedent("""
37+
SA13_DEPRECATION_WARNING = textwrap.dedent(
38+
"""
3839
WARNING: SQLAlchemy 1.3 is effectively EOL.
3940
4041
SQLAlchemy 1.3 is EOL since 2023-01-27.
@@ -43,8 +44,9 @@
4344
4445
- https://docs.sqlalchemy.org/en/14/changelog/migration_14.html
4546
- https://docs.sqlalchemy.org/en/20/changelog/migration_20.html
46-
""".lstrip("\n"))
47-
warnings.warn(message=SA13_DEPRECATION_WARNING, category=DeprecationWarning)
47+
""".lstrip("\n")
48+
)
49+
warnings.warn(message=SA13_DEPRECATION_WARNING, category=DeprecationWarning, stacklevel=2)
4850

4951
# SQLAlchemy 1.3 does not have the `exec_driver_sql` method, so add it.
5052
monkeypatch_add_exec_driver_sql()
@@ -59,4 +61,5 @@
5961
ObjectType,
6062
match,
6163
knn_match,
64+
insert_bulk,
6265
]

0 commit comments

Comments
 (0)