Skip to content

Commit a71dce5

Browse files
committed
Generate __init__py files directly in ansys.dpf.core.operators.build.build_operators()
Signed-off-by: paul.profizi <[email protected]>
1 parent 5ab5e74 commit a71dce5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/ansys/dpf/core/operators/build.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def build_operators():
183183
succeeded = 0
184184
done = 0
185185
hidden = 0
186+
categories = set()
186187
for operator_name in available_operators:
187188
if succeeded == done + 100:
188189
done += 100
@@ -194,6 +195,7 @@ def build_operators():
194195
continue
195196

196197
category = specification.properties.get("category", "")
198+
categories.add(category)
197199
if not category:
198200
raise ValueError(f"Category not defined for operator {operator_name}.")
199201
scripting_name = specification.properties.get("scripting_name", "")
@@ -239,6 +241,21 @@ def build_operators():
239241
print(error_message)
240242

241243
print(f"Generated {succeeded} out of {len(available_operators)} ({hidden} hidden)")
244+
245+
# Create __init__.py files
246+
print(f"Generating __init__.py files...")
247+
with open(os.path.join(this_path, "__init__.py"), "wb") as main_init:
248+
for category in sorted(categories):
249+
# Add category to main init file imports
250+
main_init.write(f"from . import {category}\n".encode())
251+
# Create category init file
252+
category_operators = os.listdir(os.path.join(this_path, category.split(".")[0]))
253+
with open(os.path.join(this_path, category, "__init__.py"), "wb") as category_init:
254+
for category_operator in category_operators:
255+
category_init.write(
256+
f"from .{category_operator} import {category_operator}\n".encode()
257+
)
258+
242259
if succeeded == len(available_operators) - hidden:
243260
print("Success")
244261
exit(0)

0 commit comments

Comments
 (0)