Skip to content

Commit 17a1105

Browse files
committed
Fix linting
1 parent 6a0cdd7 commit 17a1105

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

orchestrator/migrations/helpers.py

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from uuid import uuid4
2+
13
import sqlalchemy as sa
2-
from uuid import UUID, uuid4
4+
35

46
def get_resource_type_id_by_name(conn, name):
57
result = conn.execute(
@@ -78,12 +80,12 @@ def create_missing_modify_note_workflows(conn):
7880

7981
def create_workflows(conn, new):
8082
"""
81-
Create a new workflow
83+
Create a new workflow.
8284
8385
Args:
8486
conn: DB connection as available in migration main file
8587
new: an dict of your workflow data
86-
88+
8789
Example:
8890
>>> new_workflows = {
8991
"workflow_name": {
@@ -121,13 +123,13 @@ def create_workflows(conn, new):
121123

122124
def create_fixed_inputs(conn, product_id, new):
123125
"""
124-
Created fixed inputs for a product
126+
Create a fixed inputs for a product.
125127
126128
Args:
127129
conn: DB connection as available in migration main file
128130
product_id: UUID of the product to link to
129131
new: an dict of your workflow data
130-
132+
131133
Example:
132134
>>> new = {
133135
"fixed_input_1": "value",
@@ -138,23 +140,26 @@ def create_fixed_inputs(conn, product_id, new):
138140
for key, value in new.items():
139141
uuids[key] = uuid4()
140142
conn.execute(
141-
sa.text("""
143+
sa.text(
144+
"""
142145
INSERT INTO fixed_inputs (fixed_input_id, name, value, created_at, product_id)
143146
VALUES (:fixed_input_id, :key, :value, now(), :product_id)
144147
ON CONFLICT DO NOTHING;
145-
"""),
148+
"""
149+
),
146150
{"fixed_input_id": uuids[key], "key": key, "value": value, "product_id": product_id},
147151
)
148152
return uuids
149153

154+
150155
def create_products(conn, new):
151156
"""
152-
Create a new workflow
157+
Create a new workflow.
153158
154159
Args:
155160
conn: DB connection as available in migration main file
156161
new: an dict of your workflow data
157-
162+
158163
Example:
159164
>>> new = {
160165
"Example Product": {
@@ -186,37 +191,39 @@ def create_products(conn, new):
186191
current_uuid = product["product_id"]
187192
uuids[name] = current_uuid
188193
conn.execute(
189-
sa.text("""
194+
sa.text(
195+
"""
190196
INSERT INTO products (product_id, name, description, product_type, tag, status, created_at)
191197
VALUES (:product_id, :name, :description, :product_type, :tag, :status, now())
192198
ON CONFLICT DO NOTHING;
193-
"""),
199+
"""
200+
),
194201
product,
195202
)
196203
if "product_block_ids" in product:
197204
for product_block_uuid in product["product_block_ids"]:
198205
# Link many-to-many if product blocks are given.
199-
conn.execute(
200-
sa.text("INSERT INTO product_product_blocks VALUES (:product_id, :product_block_id)"),
201-
{
202-
"product_id": current_uuid,
203-
"product_block_id": product_block_uuid,
204-
},
205-
)
206+
conn.execute(
207+
sa.text("INSERT INTO product_product_blocks VALUES (:product_id, :product_block_id)"),
208+
{
209+
"product_id": current_uuid,
210+
"product_block_id": product_block_uuid,
211+
},
212+
)
206213
if "fixed_inputs" in product:
207214
create_fixed_inputs(conn, current_uuid, product["fixed_inputs"])
208215
return uuids
209216

210217

211218
def create_product_blocks(conn, new):
212219
"""
213-
Create a new workflow
220+
Create a new workflow.
214221
215222
Args:
216223
conn: DB connection as available in migration main file
217224
new: an dict of your workflow data
218225
products: list of product block ids to link these product blocks to
219-
226+
220227
Example:
221228
>>> new = {
222229
"Example Product Block": {
@@ -239,14 +246,16 @@ def create_product_blocks(conn, new):
239246
product_block["product_block_id"] = str(product_block.get("product_block_id", uuid4()))
240247
uuids[name] = product_block["product_block_id"]
241248
conn.execute(
242-
sa.text("""
249+
sa.text(
250+
"""
243251
INSERT INTO product_blocks (product_block_id, name, description, tag, status, created_at)
244252
VALUES (:product_block_id, :name, :description, :tag, :status, now())
245253
ON CONFLICT DO NOTHING;
246-
"""),
254+
"""
255+
),
247256
product_block,
248257
)
249-
258+
250259
return uuids
251260

252261

@@ -336,10 +345,9 @@ def delete_resource_types(conn, delete):
336345
conn.execute(sa.text("DELETE FROM resource_types WHERE resource_type in :obsolete"), obsolete=tuple(delete))
337346

338347

339-
340348
def create(conn, new):
341349
"""
342-
Call other functions in this file based on the schema
350+
Call other functions in this file based on the schema.
343351
344352
Args:
345353
conn: DB connection as available in migration main file
@@ -381,7 +389,7 @@ def create(conn, new):
381389
"status": "active",
382390
"resources": {
383391
"resource_type1": "Resource description",
384-
"resource_type2": "Resource description"
392+
"resource_type2": "Resource description"
385393
}
386394
},
387395
"Generated UUID Product Block": {
@@ -391,14 +399,14 @@ def create(conn, new):
391399
"status": "active",
392400
"resources": {
393401
"resource_type1": "Resource description",
394-
"resource_type3": "Resource description"
402+
"resource_type3": "Resource description"
395403
}
396404
}
397405
},
398406
"resources": {
399407
"Existing Product": {
400408
"resource_type4": "Resource description",
401-
"resource_type5": "Resource description"
409+
"resource_type5": "Resource description"
402410
}
403411
},
404412
"workflows": {
@@ -413,7 +421,6 @@ def create(conn, new):
413421
"""
414422
resources = new.get("resources", {})
415423
product_block_uuids = {}
416-
product_uuids = {}
417424

418425
if "product_blocks" in new:
419426
for product_block_name, product_block in new["product_blocks"].items():
@@ -423,7 +430,7 @@ def create(conn, new):
423430
resources.update(res_dict)
424431
del product_block["resources"]
425432
product_block_uuids = create_product_blocks(conn, new["product_blocks"])
426-
433+
427434
if "products" in new:
428435
for product in new.get("product_blocks", {}).values():
429436
if "product_blocks" in product:
@@ -435,13 +442,13 @@ def create(conn, new):
435442
except KeyError:
436443
try:
437444
product["product_block_ids"].append(get_product_block_id_by_name(conn, product_block_name))
438-
except:
445+
except Exception:
439446
raise ValueError(f"{product_block_name} is not a valid product block.")
440447
del product["product_blocks"]
441-
product_uuids = create_products(conn, new["products"])
442-
448+
create_products(conn, new["products"])
449+
443450
if resources:
444451
create_resource_types_for_product_blocks(conn, resources)
445-
452+
446453
if "workflows" in new:
447454
create_workflows(conn, new["workflows"])

0 commit comments

Comments
 (0)