Skip to content

Commit 68f0755

Browse files
Feat: add operator internal name alias for operator Python modules (#2168)
* Add operator internal name alias for retro * Limit changes to operators with an alias * Fix error raising * update generated code (#2169) Co-authored-by: PProfizi <[email protected]> * Handle DPFServerException error (remote case) * Handle DPFServerException error (remote case) * update generated code (#2173) Co-authored-by: PProfizi <[email protected]> * Add NMISC and SMISC to operators with aliases --------- Co-authored-by: PyAnsys CI Bot <[email protected]>
1 parent a71146a commit 68f0755

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import black
99
import chevron
10+
1011
from ansys.dpf import core as dpf
1112
from ansys.dpf.core import common
1213
from ansys.dpf.core.dpf_operator import available_operator_names
@@ -15,6 +16,14 @@
1516
from ansys.dpf.core.operators.translator import Markdown2RstTranslator
1617

1718

19+
# Operator internal names to call if first name is not available
20+
# Allows deprecating internal names associated to public Python operator modules
21+
operator_aliases = {
22+
"support_provider_cyclic": "mapdl::rst::support_provider_cyclic",
23+
"NMISC": "mapdl::nmisc",
24+
"SMISC": "mapdl::smisc",
25+
}
26+
1827
def build_docstring(specification_description):
1928
"""Used to generate class docstrings."""
2029
docstring = ""
@@ -157,6 +166,8 @@ def build_operator(
157166
"date_and_time": date_and_time,
158167
"has_input_aliases": has_input_aliases,
159168
"has_output_aliases": has_output_aliases,
169+
"has_internal_name_alias": operator_name in operator_aliases.keys(),
170+
"internal_name_alias": operator_aliases.get(operator_name),
160171
}
161172

162173
this_path = os.path.dirname(os.path.abspath(__file__))

src/ansys/dpf/core/operators/metadata/cyclic_support_provider.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import annotations
88

99
from warnings import warn
10+
from ansys.dpf.core.core import errors
1011
from ansys.dpf.core.dpf_operator import Operator
1112
from ansys.dpf.core.inputs import Input, _Inputs
1213
from ansys.dpf.core.outputs import Output, _Outputs
@@ -81,7 +82,19 @@ def __init__(
8182
config=None,
8283
server=None,
8384
):
84-
super().__init__(name="support_provider_cyclic", config=config, server=server)
85+
try:
86+
super().__init__(
87+
name="support_provider_cyclic", config=config, server=server
88+
)
89+
except (KeyError, errors.DPFServerException) as e:
90+
if "doesn't exist in the registry" in str(e):
91+
super().__init__(
92+
name="mapdl::rst::support_provider_cyclic",
93+
config=config,
94+
server=server,
95+
)
96+
else:
97+
raise e
8598
self._inputs = InputsCyclicSupportProvider(self)
8699
self._outputs = OutputsCyclicSupportProvider(self)
87100
if streams_container is not None:

src/ansys/dpf/core/operators/operator.mustache

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Autogenerated DPF operator classes.
77
from __future__ import annotations
88

99
from warnings import warn
10+
{{#has_internal_name_alias}}
11+
from ansys.dpf.core.core import errors
12+
{{/has_internal_name_alias}}
1013
from ansys.dpf.core.dpf_operator import Operator
1114
from ansys.dpf.core.inputs import Input, _Inputs
1215
{{#outputs}}
@@ -83,7 +86,18 @@ class {{class_name}}(Operator):
8386
"""
8487

8588
def __init__(self, {{#input_pins}}{{name}}=None, {{/input_pins}}config=None, server=None{{#has_input_aliases}}, {{#input_pins}}{{#aliases_list}}{{alias}}=None, {{/aliases_list}}{{/input_pins}}{{/has_input_aliases}}):
89+
{{^has_internal_name_alias}}
8690
super().__init__(name="{{operator_name}}", config=config, server=server)
91+
{{/has_internal_name_alias}}
92+
{{#has_internal_name_alias}}
93+
try:
94+
super().__init__(name="{{operator_name}}", config=config, server=server)
95+
except (KeyError, errors.DPFServerException) as e:
96+
if "doesn't exist in the registry" in str(e):
97+
super().__init__(name="{{internal_name_alias}}", config=config, server=server)
98+
else:
99+
raise e
100+
{{/has_internal_name_alias}}
87101
self._inputs = Inputs{{capital_class_name}}(self)
88102
self._outputs = Outputs{{capital_class_name}}(self)
89103
{{#input_pins}}

0 commit comments

Comments
 (0)