Skip to content

Commit 2bd20f0

Browse files
committed
[chore] format code using ruff instead of black
closes #32 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent dbb876a commit 2bd20f0

19 files changed

+75
-177
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ repos:
1717
- id: ruff
1818
name: Check code with Ruff, apply automatic fixes
1919
args: [ --fix, --show-fixes, --show-source, --exit-non-zero-on-fix ]
20-
- repo: https://github.com/psf/black-pre-commit-mirror
21-
rev: 23.12.1
22-
hooks:
23-
- id: black
24-
name: Format code with Black automatically
20+
- id: ruff-format
21+
name: Format code with Ruff
2522
- repo: https://github.com/pre-commit/pre-commit-hooks
2623
rev: v4.5.0
2724
hooks:

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ raw-options.version_scheme = "calver-by-date"
2323
[tool.hatch.build.hooks.vcs]
2424
version-file = "src/_version.py"
2525

26-
[tool.black]
27-
line-length = 120
28-
2926
[tool.ruff]
3027
fix = true
3128
show-fixes = true
3229
ignore = [
3330
"B904", # raise-without-from-inside-except; not python2 compatible
3431
"B905", # zip-without-explicit-strict; not python2 compatible
35-
"E501", # line-too-long; handled by `black` formatting
32+
"E501", # line-too-long; handled by auto-formatting
3633
"E731", # lambda-assignment
3734
"PERF203", # try-except-in-loop
3835
"PLR09", # too-many-*; unwanted code complexity checks
@@ -42,6 +39,8 @@ ignore = [
4239
"TRY003", # raise-vanilla-args; we can live without it
4340
"TRY200", # reraise-no-cause; not python2 compatible
4441
"RET505", # only true for simple if/elif branches (like in the ruff doc example). if/elif blocks are easier to read in most cases
42+
43+
"ISC001", # avoid incompatibility with the ruff formatter
4544
# not (yet) supported rules
4645
# "E301",
4746
# "E302",

src/base/0.0.0/post-commercial_partner_id.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def migrate(cr, version):
77
# Fight the Murphy's Law, and recompute the value on partners with a NULL value.
88
cr.execute("SELECT id FROM res_partner WHERE commercial_partner_id IS NULL")
99
if cr.rowcount:
10-
util.recompute_fields(cr, "res.partner", ["commercial_partner_id"], ids=[id_ for id_, in cr.fetchall()])
10+
util.recompute_fields(cr, "res.partner", ["commercial_partner_id"], ids=[id_ for (id_,) in cr.fetchall()])

src/base/0.0.0/pre-models-ir_model_relation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ def _register_hook(self):
4343
WHERE table_name IN %s
4444
"""
4545
self.env.cr.execute(query, [tuple(gone_m2m)])
46-
back_m2m = "\n".join(" - %s via %s" % (tn, gone_m2m[tn]) for tn, in self.env.cr.fetchall())
46+
back_m2m = "\n".join(" - %s via %s" % (tn, gone_m2m[tn]) for (tn,) in self.env.cr.fetchall())
4747
if back_m2m:
4848
raise util.MigrationError("The following m2m relations have respawn:\n%s" % back_m2m)

src/base/tests/test_ensure_has_pk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def invariant(self):
2727

2828
cr.execute(query)
2929
if cr.rowcount:
30-
tables = "\n".join(" - %s" % t for t, in cr.fetchall())
30+
tables = "\n".join(" - %s" % t for (t,) in cr.fetchall())
3131
msg = "Some tables doesn't have any primary key:\n{}".format(tables)
3232
_logger.critical(msg)
3333
if util.on_CI():

src/base/tests/test_util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class TestIterBrowse(UnitTestCase):
340340
def test_iter_browse_iter(self):
341341
cr = self.env.cr
342342
cr.execute("SELECT id FROM res_country")
343-
ids = [c for c, in cr.fetchall()]
343+
ids = [c for (c,) in cr.fetchall()]
344344
chunk_size = 10
345345

346346
Country = type(self.env["res.country"])
@@ -354,7 +354,7 @@ def test_iter_browse_iter(self):
354354
def test_iter_browse_call(self):
355355
cr = self.env.cr
356356
cr.execute("SELECT id FROM res_country")
357-
ids = [c for c, in cr.fetchall()]
357+
ids = [c for (c,) in cr.fetchall()]
358358
chunk_size = 10
359359

360360
Country = type(self.env["res.country"])
@@ -383,7 +383,7 @@ def test_iter_browse_create(self, multi):
383383
def test_iter_browse_iter_twice(self):
384384
cr = self.env.cr
385385
cr.execute("SELECT id FROM res_country")
386-
ids = [c for c, in cr.fetchall()]
386+
ids = [c for (c,) in cr.fetchall()]
387387
chunk_size = 10
388388

389389
ib = util.iter_browse(self.env["res.country"], ids, logger=None, chunk_size=chunk_size)
@@ -397,7 +397,7 @@ def test_iter_browse_iter_twice(self):
397397
def test_iter_browse_call_twice(self):
398398
cr = self.env.cr
399399
cr.execute("SELECT id FROM res_country")
400-
ids = [c for c, in cr.fetchall()]
400+
ids = [c for (c,) in cr.fetchall()]
401401
chunk_size = 10
402402

403403
ib = util.iter_browse(self.env["res.country"], ids, logger=None, chunk_size=chunk_size)

src/testing.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ def _set_value(self, key, value):
106106
query = """
107107
INSERT INTO {} (key, value) VALUES (%s, %s)
108108
ON CONFLICT (key) DO UPDATE SET value=EXCLUDED.value
109-
""".format(
110-
DATA_TABLE
111-
)
109+
""".format(DATA_TABLE)
112110
self._data_table_cr.execute(query, (key, value))
113111
self._data_table_cr._cnx.commit()
114112

@@ -135,9 +133,7 @@ def _init_db(self):
135133
query = """ CREATE TABLE {} (
136134
key VARCHAR(255) PRIMARY KEY,
137135
value JSONB NOT NULL
138-
)""".format(
139-
DATA_TABLE
140-
)
136+
)""".format(DATA_TABLE)
141137
self._data_table_cr.execute(query)
142138
self._data_table_cr._cnx.commit()
143139
UpgradeCommon.__initialized = True

src/util/accounting.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def no_deprecated_accounts(cr):
2121
RETURNING id
2222
"""
2323
)
24-
ids = tuple(r for r, in cr.fetchall())
24+
ids = tuple(r for (r,) in cr.fetchall())
2525
yield
2626
if ids:
2727
cr.execute(
@@ -48,9 +48,7 @@ def no_fiscal_lock(cr):
4848
FROM res_company old
4949
WHERE old.id = c.id
5050
RETURNING {}, old.id
51-
""".format(
52-
set_val, returns
53-
)
51+
""".format(set_val, returns)
5452
)
5553
data = cr.fetchall()
5654
yield
@@ -60,9 +58,7 @@ def no_fiscal_lock(cr):
6058
UPDATE res_company
6159
SET {}
6260
WHERE id = %s
63-
""".format(
64-
set_val
65-
),
61+
""".format(set_val),
6662
data,
6763
)
6864

src/util/data.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def uniq_tags(cr, model, uniq_column="name", order="id"):
4646
[f_model, fc],
4747
)
4848
[is_many2one] = cr.fetchone()
49-
assert (
50-
is_many2many or is_many2one
51-
), "Can't determine if column `%s` of table `%s` is a many2one or many2many" % (fc, ft)
49+
assert is_many2many or is_many2one, (
50+
"Can't determine if column `%s` of table `%s` is a many2one or many2many" % (fc, ft)
51+
)
5252
if is_many2many:
5353
upds.append(
5454
"""
@@ -60,9 +60,7 @@ def uniq_tags(cr, model, uniq_column="name", order="id"):
6060
SELECT r.{c1}, r.{c2}
6161
FROM {rel} r
6262
JOIN dups d ON (r.{c2} = d.id)
63-
""".format(
64-
rel=ft, c1=cols[0], c2=fc
65-
)
63+
""".format(rel=ft, c1=cols[0], c2=fc)
6664
)
6765
else:
6866
upds.append(
@@ -71,9 +69,7 @@ def uniq_tags(cr, model, uniq_column="name", order="id"):
7169
SET {c} = d.id
7270
FROM dups d
7371
WHERE r.{c} = ANY(d.others)
74-
""".format(
75-
rel=ft, c=fc
76-
)
72+
""".format(rel=ft, c=fc)
7773
)
7874

7975
assert upds # if not m2m found, there is something wrong...
@@ -96,9 +92,7 @@ def uniq_tags(cr, model, uniq_column="name", order="id"):
9692
),
9793
{updates}
9894
DELETE FROM {table} WHERE id IN (SELECT unnest(others) FROM dups)
99-
""".format(
100-
**locals()
101-
)
95+
""".format(**locals())
10296

10397
cr.execute(query, [model])
10498

src/util/domains.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,7 @@ def adapt_domains(cr, model, old, new, adapter=None, skip_inherit=(), force_adap
293293
SELECT id, {df.model_select}, {df.domain_column}
294294
FROM {df.table} t
295295
WHERE {df.domain_column} ~ %s
296-
""".format(
297-
df=df
298-
),
296+
""".format(df=df),
299297
[match_old],
300298
)
301299
for id_, model, domain in cr.fetchall():

0 commit comments

Comments
 (0)