feat: adhere to ruff's B rules (#2423)

* feat: adhere to ruff's `B` rules
last of the ruff checks.
closes #2308
* B904
* B008
* B005
* B025
* cleanup on fake
This commit is contained in:
dni ⚡ 2024-04-17 13:11:51 +02:00 committed by GitHub
parent e13a37c193
commit 98ec59df96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 226 additions and 169 deletions

View file

@ -7,7 +7,7 @@ import argparse
import os
import sqlite3
import sys
from typing import List
from typing import List, Optional
import psycopg2
@ -90,21 +90,23 @@ def insert_to_pg(query, data):
for d in data:
try:
cursor.execute(query, d)
except Exception as e:
except Exception as exc:
if args.ignore_errors:
print(e)
print(exc)
print(f"Failed to insert {d}")
else:
print("query:", query)
print("data:", d)
raise ValueError(f"Failed to insert {d}")
raise ValueError(f"Failed to insert {d}") from exc
connection.commit()
cursor.close()
connection.close()
def migrate_core(file: str, exclude_tables: List[str] = []):
def migrate_core(file: str, exclude_tables: Optional[List[str]] = None):
if exclude_tables is None:
exclude_tables = []
print(f"Migrating core: {file}")
migrate_db(file, "public", exclude_tables)
print("✅ Migrated core")
@ -118,8 +120,10 @@ def migrate_ext(file: str):
print(f"✅ Migrated ext: {schema}")
def migrate_db(file: str, schema: str, exclude_tables: List[str] = []):
def migrate_db(file: str, schema: str, exclude_tables: Optional[List[str]] = None):
# first we check if this file exists:
if exclude_tables is None:
exclude_tables = []
assert os.path.isfile(file), f"{file} does not exist!"
cursor = get_sqlite_cursor(file)