Skip to content

Commit 742c327

Browse files
committed
Chore: Improve linting. Remove Black and isort, use Ruff. Format code.
1 parent 585a01a commit 742c327

File tree

5 files changed

+75
-89
lines changed

5 files changed

+75
-89
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.cache
22
/.idea
3+
/.mypy_cache
34
/.pytest_cache
45
/.ruff_cache
56
/.vagrant

examples/tracking_merlion.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def import_data(data_table_name: str, anomalies_table_name: str):
108108
("2014-02-07 14:55:00.000000", "2014-02-09 14:05:00.000000"),
109109
]
110110
cursor.executemany(
111-
f"INSERT INTO {anomalies_table_name} (ts_start, ts_end) VALUES (?, ?)", known_anomalies # noqa: S608
111+
f"INSERT INTO {anomalies_table_name} (ts_start, ts_end) VALUES (?, ?)", # noqa: S608
112+
known_anomalies, # noqa: S608
112113
)
113114

114115

@@ -222,7 +223,7 @@ def run_experiment(time_series: pd.DataFrame, anomalies_table_name: str):
222223
r = TSADMetric.Recall.value(ground_truth=test_labels, predict=test_pred)
223224
f1 = TSADMetric.F1.value(ground_truth=test_labels, predict=test_pred)
224225
mttd = TSADMetric.MeanTimeToDetect.value(ground_truth=test_labels, predict=test_pred)
225-
print(f"Precision: {p:.4f}, Recall: {r:.4f}, F1: {f1:.4f}\n" f"Mean Time To Detect: {mttd}") # noqa: T201
226+
print(f"Precision: {p:.4f}, Recall: {r:.4f}, F1: {f1:.4f}\nMean Time To Detect: {mttd}") # noqa: T201
226227

227228
mlflow.log_input(mlflow.data.from_pandas(input_test_data), context="training")
228229
mlflow.log_metric("precision", p)

examples/tracking_pycaret.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def read_data(table_name: str) -> pd.DataFrame:
147147
FROM {table_name}
148148
GROUP BY month
149149
ORDER BY month
150-
"""
150+
""" # noqa: S608
151151
with connect_database() as conn:
152152
data = pd.read_sql(query, conn)
153153

pyproject.toml

+64-80
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,10 @@ requires = [
1111
"versioningit",
1212
]
1313

14-
[tool.versioningit.vcs]
15-
method = "git"
16-
default-tag = "0.0.0"
17-
1814
[project]
1915
name = "mlflow-cratedb"
2016
description = "MLflow adapter for CrateDB"
2117
readme = "README.md"
22-
requires-python = ">=3.8,<3.12"
23-
license = {text = "Apache License 2.0"}
2418
keywords = [
2519
"ai",
2620
"cratedb",
@@ -32,9 +26,11 @@ keywords = [
3226
"mlflow-tracking",
3327
"mlops",
3428
]
29+
license = { text = "Apache License 2.0" }
3530
authors = [
36-
{name = "Andreas Motl", email = "[email protected]"},
31+
{ name = "Andreas Motl", email = "[email protected]" },
3732
]
33+
requires-python = ">=3.8,<3.12"
3834
classifiers = [
3935
"Development Status :: 4 - Beta",
4036
"Environment :: Console",
@@ -84,51 +80,75 @@ dependencies = [
8480
"sqlparse<0.6",
8581
]
8682

87-
[project.optional-dependencies]
88-
develop = [
89-
"black<25",
83+
optional-dependencies.develop = [
9084
"mypy<1.15",
9185
"poethepoet<1",
9286
"pyproject-fmt<2.6",
93-
"ruff<0.9",
87+
"ruff<0.10",
9488
"validate-pyproject<0.24",
9589
]
96-
examples = [
97-
'pycaret[analysis,models,parallel,test,tuner]==3.3.2; platform_machine != "aarch64"',
90+
optional-dependencies.examples = [
91+
"pycaret[analysis,models,parallel,test,tuner]==3.3.2; platform_machine!='aarch64'",
9892
"salesforce-merlion<2.1",
9993
"werkzeug==2.2.3",
10094
]
101-
release = [
95+
optional-dependencies.release = [
10296
"build<2",
10397
"twine<7",
10498
]
105-
test = [
99+
optional-dependencies.test = [
106100
"psutil==5.9.8",
107101
"pytest<9",
108102
"pytest-cov<7",
109103
]
110-
[project.scripts]
111-
mlflow-cratedb = "mlflow_cratedb.cli:cli"
112-
[project.entry-points."mlflow.app"]
113-
mlflow-cratedb = "mlflow_cratedb.server:app"
104+
urls.changelog = "https://github.com/crate/mlflow-cratedb/blob/main/CHANGES.md"
105+
urls.documentation = "https://github.com/crate/mlflow-cratedb"
106+
urls.homepage = "https://github.com/crate/mlflow-cratedb"
107+
urls.repository = "https://github.com/crate/mlflow-cratedb"
108+
scripts.mlflow-cratedb = "mlflow_cratedb.cli:cli"
109+
entry-points."mlflow.app".mlflow-cratedb = "mlflow_cratedb.server:app"
110+
114111
[tool.setuptools]
115112
# https://setuptools.pypa.io/en/latest/userguide/package_discovery.html
116-
packages = ["mlflow_cratedb"]
117-
118-
[project.urls]
119-
changelog = "https://github.com/crate/mlflow-cratedb/blob/main/CHANGES.md"
120-
documentation = "https://github.com/crate/mlflow-cratedb"
121-
homepage = "https://github.com/crate/mlflow-cratedb"
122-
repository = "https://github.com/crate/mlflow-cratedb"
123-
[tool.black]
113+
packages = [ "mlflow_cratedb" ]
114+
115+
[tool.ruff]
124116
line-length = 120
125117

126-
extend-exclude = "tests/test_tracking.py"
118+
extend-exclude = [
119+
"tests/test_tracking.py",
120+
]
121+
122+
lint.select = [
123+
# Builtins
124+
"A",
125+
# Bugbear
126+
"B",
127+
# comprehensions
128+
"C4",
129+
# Pycodestyle
130+
"E",
131+
# eradicate
132+
"ERA",
133+
# Pyflakes
134+
"F",
135+
# isort
136+
"I",
137+
# pandas-vet
138+
"PD",
139+
# return
140+
"RET",
141+
# Bandit
142+
"S",
143+
# print
144+
"T20",
145+
"W",
146+
# flake8-2020
147+
"YTT",
148+
]
127149

128-
[tool.isort]
129-
profile = "black"
130-
skip_glob = "**/site-packages/**"
131-
skip_gitignore = false
150+
lint.per-file-ignores."tests/*" = [ "S101" ] # Use of `assert` detected
151+
lint.per-file-ignores."tests/conftest.py" = [ "E402" ] # Module level import not at top of file
132152

133153
[tool.pytest.ini_options]
134154
minversion = "2.0"
@@ -139,7 +159,7 @@ addopts = """
139159
"""
140160
log_level = "DEBUG"
141161
log_cli_level = "DEBUG"
142-
testpaths = ["tests"]
162+
testpaths = [ "tests" ]
143163
xfail_strict = true
144164
markers = [
145165
"examples",
@@ -149,17 +169,17 @@ markers = [
149169

150170
[tool.coverage.run]
151171
branch = false
152-
source = ["mlflow_cratedb"]
172+
source = [ "mlflow_cratedb" ]
153173
omit = [
154-
"tests/*",
174+
"tests/*",
155175
]
156176

157177
[tool.coverage.report]
158178
fail_under = 0
159179
show_missing = true
160180

161181
[tool.mypy]
162-
packages = ["mlflow_cratedb"]
182+
packages = [ "mlflow_cratedb" ]
163183
exclude = [
164184
]
165185
check_untyped_defs = true
@@ -173,62 +193,26 @@ strict_equality = true
173193
warn_unused_ignores = true
174194
warn_redundant_casts = true
175195

176-
[tool.ruff]
177-
line-length = 120
178-
179-
lint.select = [
180-
# Bandit
181-
"S",
182-
# Bugbear
183-
"B",
184-
# Builtins
185-
"A",
186-
# comprehensions
187-
"C4",
188-
# eradicate
189-
"ERA",
190-
# flake8-2020
191-
"YTT",
192-
# isort
193-
"I",
194-
# pandas-vet
195-
"PD",
196-
# print
197-
"T20",
198-
# Pycodestyle
199-
"E",
200-
"W",
201-
# Pyflakes
202-
"F",
203-
# return
204-
"RET",
205-
]
206-
207-
extend-exclude = [
208-
]
209-
210-
211-
[tool.ruff.lint.per-file-ignores]
212-
"tests/*" = ["S101"] # Use of `assert` detected
213-
"tests/conftest.py" = ["E402"] # Module level import not at top of file
214-
196+
[tool.versioningit.vcs]
197+
method = "git"
198+
default-tag = "0.0.0"
215199

216200
# ===================
217201
# Tasks configuration
218202
# ===================
219203

220204
[tool.poe.tasks]
221205
format = [
222-
{ cmd = "black ." },
206+
{ cmd = "ruff format ." },
223207
# Configure Ruff not to auto-fix (remove!):
224208
# Ignore unused imports (F401), unused variables (F841), `print` statements (T201), and commented-out code (ERA001).
225-
{ cmd = "ruff --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001 ." },
209+
{ cmd = "ruff check --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001 ." },
226210
{ cmd = "pyproject-fmt --keep-full-version pyproject.toml" },
227211
]
228212

229213
lint = [
214+
{ cmd = "ruff format --check ." },
230215
{ cmd = "ruff check ." },
231-
{ cmd = "black --check ." },
232216
{ cmd = "validate-pyproject pyproject.toml" },
233217
{ cmd = "mypy" },
234218
]
@@ -239,8 +223,8 @@ test-fast = [
239223
{ cmd = "pytest -m 'not slow'" },
240224
]
241225
build = { cmd = "python -m build" }
242-
check = ["lint", "test"]
243-
check-fast = ["lint", "test-fast"]
226+
check = [ "lint", "test" ]
227+
check-fast = [ "lint", "test-fast" ]
244228

245229
release = [
246230
{ cmd = "python -m build" },

tests/test_examples.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ def test_tracking_pycaret(reset_database, engine: sa.Engine, tracking_store: Sql
183183
# We have 2 experiments - one for "Default" experiment and one for the example
184184
assert session.query(SqlExperiment).count() == 2, "experiments should have 2 rows"
185185
# We have 32 distinct runs in the experiment which produced metrics
186-
assert (
187-
session.query(sa.func.count(sa.distinct(SqlMetric.run_uuid))).scalar() == 32
188-
), "metrics should have 32 distinct run_uuid"
186+
assert session.query(sa.func.count(sa.distinct(SqlMetric.run_uuid))).scalar() == 32, (
187+
"metrics should have 32 distinct run_uuid"
188+
)
189189
# We have 33 runs in total (1 parent + 32 child runs)
190190
assert session.query(SqlRun).count() == 33, "runs should have 33 rows"
191191
# We have 33 distinct runs which have parameters (1 parent + 32 child runs)
192-
assert (
193-
session.query(sa.func.count(sa.distinct(SqlParam.run_uuid))).scalar() == 33
194-
), "params should have 33 distinct run_uuid"
192+
assert session.query(sa.func.count(sa.distinct(SqlParam.run_uuid))).scalar() == 33, (
193+
"params should have 33 distinct run_uuid"
194+
)
195195
# We have one model registered
196196
assert session.query(SqlRegisteredModel).count() == 1, "registered_models should have 1 row"
197197

0 commit comments

Comments
 (0)