-
Notifications
You must be signed in to change notification settings - Fork 23
Fix hidden operators exposure #1821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6076766
Fix mustache code style
PProfizi bddf712
Filter-out hidden operators from available operators in ansys.dpf.cor…
PProfizi 5ab5e74
Use binary string to not change line endings when writing to file
PProfizi a71dce5
Generate __init__py files directly in ansys.dpf.core.operators.build.…
PProfizi 4ca42c2
Remove usage of python_generator operator in .ci/code_generation.py
PProfizi 7fba1a5
Fix operator import
PProfizi d2e4ddd
Add an exception list for some hidden operators to still expose until…
PProfizi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,13 +182,30 @@ def build_operators(): | |
|
|
||
| succeeded = 0 | ||
| done = 0 | ||
| hidden = 0 | ||
| # List of hidden operators to still expose for retro-compatibility | ||
| # until they are fully deprecated | ||
| hidden_to_expose = [ # Use internal names | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cbellot000 here is the list of exceptions for hidden operators to still expose as Python modules |
||
| "rescope_fc", # Switch to "change_fc" once server is updated | ||
| "dot", "dot_tensor", | ||
| "scale_by_field", "scale_by_field_fc", | ||
| "invert", "invert_fc", | ||
| ] | ||
| categories = set() | ||
| for operator_name in available_operators: | ||
| if succeeded == done + 100: | ||
| done += 100 | ||
| print(f"{done} operators done...") | ||
| specification = dpf.Operator.operator_specification(operator_name) | ||
|
|
||
| if (specification.properties["exposure"] in ["hidden", "private"] | ||
| and | ||
| operator_name not in hidden_to_expose): | ||
| hidden += 1 | ||
| continue | ||
|
|
||
| category = specification.properties.get("category", "") | ||
| categories.add(category) | ||
| if not category: | ||
| raise ValueError(f"Category not defined for operator {operator_name}.") | ||
| scripting_name = specification.properties.get("scripting_name", "") | ||
|
|
@@ -211,7 +228,7 @@ def build_operators(): | |
|
|
||
| # Write to operator file | ||
| operator_file = os.path.join(category_path, scripting_name + ".py") | ||
| with open(operator_file, "w") as f: | ||
| with open(operator_file, "wb") as f: | ||
| try: | ||
| operator_str = build_operator( | ||
| specification, | ||
|
|
@@ -221,7 +238,7 @@ def build_operators(): | |
| category, | ||
| ) | ||
| exec(operator_str, globals()) | ||
| f.write(operator_str) | ||
| f.write(operator_str.encode()) | ||
| succeeded += 1 | ||
| except SyntaxError as e: | ||
| error_message = ( | ||
|
|
@@ -233,8 +250,24 @@ def build_operators(): | |
| error_file.write(f"Class: {operator_str}") | ||
| print(error_message) | ||
|
|
||
| print(f"Generated {succeeded} out of {len(available_operators)}") | ||
| if succeeded == len(available_operators): | ||
| print(f"Generated {succeeded} out of {len(available_operators)} ({hidden} hidden)") | ||
|
|
||
| # Create __init__.py files | ||
| print(f"Generating __init__.py files...") | ||
| with open(os.path.join(this_path, "__init__.py"), "wb") as main_init: | ||
| for category in sorted(categories): | ||
| # Add category to main init file imports | ||
| main_init.write(f"from . import {category}\n".encode()) | ||
| # Create category init file | ||
| category_operators = os.listdir(os.path.join(this_path, category.split(".")[0])) | ||
| with open(os.path.join(this_path, category, "__init__.py"), "wb") as category_init: | ||
| for category_operator in category_operators: | ||
| operator_name = category_operator.split(".")[0] | ||
| category_init.write( | ||
| f"from .{operator_name} import {operator_name}\n".encode() | ||
| ) | ||
|
|
||
| if succeeded == len(available_operators) - hidden: | ||
| print("Success") | ||
| exit(0) | ||
| else: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why legacy??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbellot000 that is historical but we could try with the
GrpcServer. In a next PR.