Skip to content

Commit 9a9bc0b

Browse files
committed
Update Black to latest + reformatting
There was a security issue with the Black we were using.
1 parent 7194636 commit 9a9bc0b

64 files changed

Lines changed: 130 additions & 142 deletions

Some content is hidden

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

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
repos:
22
- repo: https://github.com/pycqa/isort
3-
rev: 7.0.0
3+
rev: 8.0.1
44
hooks:
55
- id: isort
66
- repo: https://github.com/python/black
7-
rev: 25.11.0
7+
rev: 26.3.1
88
hooks:
99
- id: black

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
coverage[toml]
2-
black == 24.4.2
2+
black == 26.3.1
33
pre-commit
44
pyperf
55
sphinx

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ classifiers = [
1111
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
1212
"Operating System :: OS Independent",
1313
]
14-
requires-python = ">=3.10"
14+
requires-python = ">=3.10" # Remember to bump Black's target-version below when updating this.
1515
dependencies = [
1616
"SQLAlchemy >=2.0, <2.1",
1717
"alembic >=1.7",
@@ -60,6 +60,7 @@ branch = true
6060
ignore_errors = true
6161

6262
[tool.black]
63+
target-version = ["py310"]
6364
line-length = 120
6465
force-exclude = '\.git|version.py'
6566

spinedb_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# this program. If not, see <http://www.gnu.org/licenses/>.
1111
######################################################################################################################
1212

13-
""" A package to interact with Spine DBs. """
13+
"""A package to interact with Spine DBs."""
1414

1515
from .db_mapping import DatabaseMapping
1616
from .exception import (

spinedb_api/alembic/versions/39e860a11b05_add_alternatives_and_scenarios.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,15 @@ def alter_tables_after_update():
102102
date = datetime.now(timezone.utc)
103103
conn = op.get_bind()
104104
conn.execute(
105-
text(
106-
"""
105+
text("""
107106
UPDATE next_id
108107
SET
109108
user = :user,
110109
date = :date,
111110
alternative_id = 2,
112111
scenario_id = 1,
113112
scenario_alternative_id = 1
114-
"""
115-
),
113+
"""),
116114
{
117115
"user": user,
118116
"date": date,

spinedb_api/alembic/versions/bba1e2ef5153_move_to_entity_based_design.py

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -142,33 +142,19 @@ def insert_into_new_tables():
142142
]
143143
op.bulk_insert(meta.tables["entity_class"], entity_classes)
144144
# Id mappings
145-
obj_cls_to_ent_cls = {
146-
r.object_class_id: r.entity_class_id
147-
for r in conn.execute(
148-
text(
149-
"""
145+
obj_cls_to_ent_cls = {r.object_class_id: r.entity_class_id for r in conn.execute(text("""
150146
SELECT object_class.id AS object_class_id, entity_class.id AS entity_class_id
151147
FROM object_class, entity_class
152148
WHERE entity_class.type_id = 1
153149
AND object_class.name = entity_class.name
154-
"""
155-
)
156-
)
157-
}
158-
rel_cls_to_ent_cls = {
159-
r.relationship_class_id: r.entity_class_id
160-
for r in conn.execute(
161-
text(
162-
"""
150+
"""))}
151+
rel_cls_to_ent_cls = {r.relationship_class_id: r.entity_class_id for r in conn.execute(text("""
163152
SELECT relationship_class.id AS relationship_class_id, entity_class.id AS entity_class_id
164153
FROM relationship_class, entity_class
165154
WHERE entity_class.type_id = 2
166155
AND relationship_class.name = entity_class.name
167156
GROUP BY relationship_class_id, entity_class_id
168-
"""
169-
)
170-
)
171-
}
157+
"""))}
172158
temp_relationship_classes = [
173159
{"entity_class_id": r.id, "type_id": 2, "commit_id": r.commit_id}
174160
for r in conn.execute(text("SELECT id, commit_id FROM entity_class WHERE type_id = 2"))
@@ -195,33 +181,19 @@ def insert_into_new_tables():
195181
]
196182
op.bulk_insert(meta.tables["entity"], entities)
197183
# Id mappings
198-
obj_to_ent = {
199-
r.object_id: r.entity_id
200-
for r in conn.execute(
201-
text(
202-
"""
184+
obj_to_ent = {r.object_id: r.entity_id for r in conn.execute(text("""
203185
SELECT object.id AS object_id, entity.id AS entity_id
204186
FROM object, entity
205187
WHERE entity.type_id = 1
206188
AND object.name = entity.name
207-
"""
208-
)
209-
)
210-
}
211-
rel_to_ent = {
212-
r.relationship_id: r.entity_id
213-
for r in conn.execute(
214-
text(
215-
"""
189+
"""))}
190+
rel_to_ent = {r.relationship_id: r.entity_id for r in conn.execute(text("""
216191
SELECT relationship.id AS relationship_id, entity.id AS entity_id
217192
FROM relationship, entity
218193
WHERE entity.type_id = 2
219194
AND relationship.name = entity.name
220195
GROUP BY relationship_id, entity_id
221-
"""
222-
)
223-
)
224-
}
196+
"""))}
225197
temp_relationships = [
226198
{"entity_id": r.id, "entity_class_id": r.class_id, "type_id": 2, "commit_id": r.commit_id}
227199
for r in conn.execute(text("SELECT id, class_id, commit_id FROM entity WHERE type_id = 2"))
@@ -236,15 +208,11 @@ def insert_into_new_tables():
236208
"member_class_id": obj_cls_to_ent_cls[r.object_class_id],
237209
"commit_id": r.commit_id,
238210
}
239-
for r in conn.execute(
240-
text(
241-
"""
211+
for r in conn.execute(text("""
242212
SELECT r.id, r.class_id, r.dimension, o.class_id AS object_class_id, r.object_id, r.commit_id
243213
FROM relationship AS r, object AS o
244214
WHERE r.object_id = o.id
245-
"""
246-
)
247-
)
215+
"""))
248216
]
249217
op.bulk_insert(meta.tables["relationship_entity"], relationship_entities)
250218
# Return metadata and id mappings
@@ -309,25 +277,21 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
309277
{"entity_class_id": entity_class_id, "object_class_id": object_class_id},
310278
)
311279
conn.execute(
312-
text(
313-
"""
280+
text("""
314281
UPDATE parameter_definition SET entity_class_id = :entity_class_id
315282
WHERE object_class_id = :object_class_id
316-
"""
317-
),
283+
"""),
318284
{
319285
"entity_class_id": entity_class_id,
320286
"object_class_id": object_class_id,
321287
},
322288
)
323289
for relationship_class_id, entity_class_id in rel_cls_to_ent_cls.items():
324290
conn.execute(
325-
text(
326-
"""
291+
text("""
327292
UPDATE parameter_definition SET entity_class_id = :entity_class_id
328293
WHERE relationship_class_id = :relationship_class_id
329-
"""
330-
),
294+
"""),
331295
{
332296
"entity_class_id": entity_class_id,
333297
"relationship_class_id": relationship_class_id,
@@ -343,12 +307,10 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
343307
)
344308
entity_class_id = ent_to_ent_cls[entity_id]
345309
conn.execute(
346-
text(
347-
"""
310+
text("""
348311
UPDATE parameter_value SET entity_id = :entity_id, entity_class_id = :entity_class_id
349312
WHERE object_id = :object_id
350-
"""
351-
),
313+
"""),
352314
{
353315
"entity_id": entity_id,
354316
"entity_class_id": entity_class_id,
@@ -358,12 +320,10 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
358320
for relationship_id, entity_id in rel_to_ent.items():
359321
entity_class_id = ent_to_ent_cls[entity_id]
360322
conn.execute(
361-
text(
362-
"""
323+
text("""
363324
UPDATE parameter_value SET entity_id = :entity_id, entity_class_id = :entity_class_id
364325
WHERE relationship_id = :relationship_id
365-
"""
366-
),
326+
"""),
367327
{
368328
"entity_id": entity_id,
369329
"entity_class_id": entity_class_id,
@@ -383,8 +343,7 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
383343
user = "alembic"
384344
date = datetime.now(timezone.utc)
385345
conn.execute(
386-
text(
387-
"""
346+
text("""
388347
UPDATE next_id
389348
SET
390349
user = :user,
@@ -393,8 +352,7 @@ def update_tables(meta, obj_cls_to_ent_cls, rel_cls_to_ent_cls, obj_to_ent, rel_
393352
entity_type_id = 3,
394353
entity_class_id = :entity_class_id,
395354
entity_id = :entity_id
396-
"""
397-
),
355+
"""),
398356
{
399357
"user": user,
400358
"date": date,

spinedb_api/arrow_value.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
This is highly experimental API.
1919
2020
"""
21+
2122
from collections import defaultdict
2223
from collections.abc import Callable, Iterable
2324
import datetime

spinedb_api/dataframes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
).subquery()
105105
df = fetch_as_dataframe(db_map, final_query, maps)
106106
"""
107+
107108
from __future__ import annotations
108109
import collections
109110
from typing import Any, Union

0 commit comments

Comments
 (0)