Skip to content

Commit 07c8013

Browse files
authored
Merge pull request #39 from openMetadataInitiative/sort-imports
When generating `__init__.py` files, sort imports alphabetically
2 parents f83b412 + cbec559 commit 07c8013

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

build.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,21 @@
7878

7979
# Step 5 - create additional files, e.g. __init__.py
8080
openminds_modules = defaultdict(set)
81-
for path, classes in python_modules.items():
81+
for path in sorted(python_modules):
82+
classes = python_modules[path]
8283
dir_path = ["target", "openminds"] + path.split(".")
8384
openminds_modules[dir_path[2]].add(dir_path[3])
8485
init_file_path = os.path.join(*(dir_path + ["__init__.py"]))
8586
with open(init_file_path, "w") as fp:
86-
for class_module, class_name in classes:
87+
for class_module, class_name in sorted(classes):
8788
fp.write(f"from .{class_module} import {class_name}\n")
8889
while len(dir_path) > 3:
8990
child_dir = dir_path[-1]
9091
dir_path = dir_path[:-1]
9192
init_file_path = os.path.join(*(dir_path + ["__init__.py"]))
9293
with open(init_file_path, "a") as fp:
9394
if len(dir_path) > 3:
94-
class_names = ", ".join(class_name for _, class_name in classes)
95+
class_names = ", ".join(sorted(class_name for _, class_name in classes))
9596
fp.write(f"from .{child_dir} import ({class_names})\n")
9697

9798
for version, module_list in openminds_modules.items():

0 commit comments

Comments
 (0)