Skip to content

Commit a53552f

Browse files
committed
lint
another take at lint
1 parent 262c108 commit a53552f

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

scripts/get_source_data_schema_changelog.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import os
21
import json
2+
import os
33
from datetime import datetime
44

55
old_schemas_dir = "original_schemas"
@@ -13,10 +13,12 @@
1313
print(f"Directory {new_schemas_dir} does not exist.")
1414
exit(1)
1515

16+
1617
def read_json_file(filepath):
17-
with open(filepath, 'r') as f:
18+
with open(filepath, "r") as f:
1819
return json.load(f)
1920

21+
2022
new_schemas = [file.replace("_schema.json", "") for file in os.listdir(new_schemas_dir)]
2123
old_schemas = [file.replace("_schema.json", "") for file in os.listdir(old_schemas_dir)]
2224

@@ -27,36 +29,37 @@ def read_json_file(filepath):
2729
schema_changes = {}
2830

2931
for schema in common_tables:
30-
old_file_path = os.path.join(old_schemas_dir, schema + '_schema.json')
31-
new_file_path = os.path.join(new_schemas_dir, schema + '_schema.json')
32+
old_file_path = os.path.join(old_schemas_dir, schema + "_schema.json")
33+
new_file_path = os.path.join(new_schemas_dir, schema + "_schema.json")
3234

3335
new_data = read_json_file(new_file_path)
3436
old_data = read_json_file(old_file_path)
3537

36-
old_dict = {item['name']: item for item in old_data}
37-
new_dict = {item['name']: item for item in new_data}
38+
old_dict = {item["name"]: item for item in old_data}
39+
new_dict = {item["name"]: item for item in new_data}
3840

39-
added = [new_dict[name]['name'] for name in new_dict if name not in old_dict]
40-
deleted = [old_dict[name]['name'] for name in old_dict if name not in new_dict]
41+
added = [new_dict[name]["name"] for name in new_dict if name not in old_dict]
42+
deleted = [old_dict[name]["name"] for name in old_dict if name not in new_dict]
4143
type_changed = [
42-
(new_dict[name]['name'], new_dict[name]['type'], old_dict[name]['type']) for name in new_dict
43-
if name in old_dict and new_dict[name]['type'] != old_dict[name]['type']
44+
(new_dict[name]["name"], new_dict[name]["type"], old_dict[name]["type"])
45+
for name in new_dict
46+
if name in old_dict and new_dict[name]["type"] != old_dict[name]["type"]
4447
]
4548

4649
if added:
4750
if schema not in schema_changes:
4851
schema_changes[schema] = {}
49-
schema_changes[schema]['column_added'] = added
52+
schema_changes[schema]["column_added"] = added
5053

5154
if deleted:
5255
if schema not in schema_changes:
5356
schema_changes[schema] = {}
54-
schema_changes[schema]['column_removed'] = deleted
57+
schema_changes[schema]["column_removed"] = deleted
5558

5659
if type_changed:
5760
if schema not in schema_changes:
5861
schema_changes[schema] = {}
59-
schema_changes[schema]['type_changed'] = type_changed
62+
schema_changes[schema]["type_changed"] = type_changed
6063

6164
if tables_added or tables_removed or schema_changes:
6265
current_date = datetime.now().strftime("%Y-%m-%d")
@@ -73,15 +76,19 @@ def read_json_file(filepath):
7376
print("### Tables Removed:")
7477
print([table for table in tables_removed])
7578

79+
7680
def sort_schema_changes(changes):
7781
sorted_data = {}
7882

7983
for table_name in sorted(changes.keys()):
80-
sorted_operations = {op_type: sorted(changes[table_name][op_type])
81-
for op_type in sorted(changes[table_name].keys())}
84+
sorted_operations = {
85+
op_type: sorted(changes[table_name][op_type])
86+
for op_type in sorted(changes[table_name].keys())
87+
}
8288
sorted_data[table_name] = sorted_operations
8389
return sorted_data
8490

91+
8592
if schema_changes:
8693
sorted_schema_changes = sort_schema_changes(schema_changes)
8794
print("")
@@ -92,9 +99,13 @@ def sort_schema_changes(changes):
9299

93100
for table_name, operations in sorted_schema_changes.items():
94101
for operation, columns in operations.items():
95-
if operation in ['column_added', 'column_removed']:
102+
if operation in ["column_added", "column_removed"]:
96103
columns_str = ", ".join(columns)
97-
if operation in ['type_changed']:
98-
columns_str = ", ".join([f"{column[0]} ({column[2]} -> {column[1]})" for column in columns])
99-
markdown_table += f"| {table_name:<33} | {operation:<13} | {columns_str:<24} |\n"
104+
if operation in ["type_changed"]:
105+
columns_str = ", ".join(
106+
[f"{column[0]} ({column[2]} -> {column[1]})" for column in columns]
107+
)
108+
markdown_table += (
109+
f"| {table_name:<33} | {operation:<13} | {columns_str:<24} |\n"
110+
)
100111
print(markdown_table)

0 commit comments

Comments
 (0)