Skip to content

Commit 4cc8187

Browse files
committed
Expose aliases in Input, Output, and PinSpecification
1 parent f3d5f98 commit 4cc8187

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

src/ansys/dpf/core/dpf_operator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ def id(self) -> int:
681681
return self._id
682682

683683
@property
684-
def inputs(self):
684+
def inputs(self) -> Inputs:
685685
"""Inputs connected to the operator.
686686
687687
Returns
@@ -703,7 +703,7 @@ def inputs(self):
703703
return self._inputs
704704

705705
@property
706-
def outputs(self):
706+
def outputs(self) -> Outputs:
707707
"""Outputs from the operator's evaluation.
708708
709709
Returns

src/ansys/dpf/core/inputs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(self, spec, pin, operator, count_ellipsis=-1):
6262
self._python_expected_types.append(map_types_to_python[cpp_type])
6363
if len(self._spec.type_names) == 0:
6464
self._python_expected_types.append("Any")
65+
self.aliases = self._spec.aliases
6566
docstr = self.__str__()
6667
self.name = self._spec.name
6768
if self._count_ellipsis != -1:
@@ -184,6 +185,8 @@ def __str__(self):
184185
docstr += "\n".join(wrap(self._spec.document.capitalize())) + "\n"
185186
if self._count_ellipsis >= 0:
186187
docstr += "is ellipsis\n"
188+
if self.aliases:
189+
docstr += f"aliases: {self.aliases}\n"
187190
return docstr
188191

189192
def __inc_if_ellipsis(self):
@@ -312,6 +315,9 @@ def _add_input(self, pin, spec, count_ellipsis=-1):
312315
def __call__(self, inpt):
313316
self.connect(inpt)
314317

318+
def __getitem__(self, item) -> Input:
319+
return self._inputs[item]
320+
315321

316322
# Dynamic class Inputs
317323
class Inputs(_Inputs):

src/ansys/dpf/core/operator_specification.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class PinSpecification:
7878
optional: bool
7979
ellipsis: bool
8080
name_derived_class = str
81+
aliases: list[str]
8182

8283
def __init__(
8384
self,
@@ -87,13 +88,15 @@ def __init__(
8788
optional=False,
8889
ellipsis=False,
8990
name_derived_class="",
91+
aliases=[],
9092
):
9193
self.name = name
9294
self.type_names = type_names
9395
self.optional = optional
9496
self.document = document
9597
self.ellipsis = ellipsis
9698
self.name_derived_class = name_derived_class
99+
self.aliases = aliases
97100

98101
@property
99102
def type_names(self) -> list[str]:
@@ -140,6 +143,7 @@ def _get_copy(other, changed_types) -> PinSpecification:
140143
other.optional,
141144
other.ellipsis,
142145
other.name_derived_class,
146+
other.aliases,
143147
)
144148

145149
def __repr__(self):
@@ -367,7 +371,7 @@ def description(self) -> str:
367371
return ""
368372

369373
@property
370-
def inputs(self) -> dict:
374+
def inputs(self) -> dict[int, PinSpecification]:
371375
"""Returns a dictionary mapping the input pin numbers to their ``PinSpecification``.
372376
373377
Returns
@@ -390,7 +394,7 @@ def inputs(self) -> dict:
390394
return self._map_input_pin_spec
391395

392396
@property
393-
def outputs(self) -> dict:
397+
def outputs(self) -> dict[int, PinSpecification]:
394398
"""Returns a dictionary mapping the output pin numbers to their ``PinSpecification``.
395399
396400
Returns
@@ -429,7 +433,13 @@ def _fill_pins(self, binput, to_fill):
429433
self._api.operator_specification_get_pin_type_name(self, binput, i_pin, i_type)
430434
for i_type in range(n_types)
431435
]
432-
436+
pin_aliases = []
437+
for i_alias in range(
438+
self._api.operator_specification_get_pin_num_aliases(self, binput, i_pin)
439+
):
440+
pin_aliases.append(
441+
self._api.operator_specification_get_pin_alias(self, binput, i_pin, i_alias)
442+
)
433443
pin_derived_class_type_name = ""
434444
if server_meet_version("7.0", self._server) and hasattr(
435445
self._api, "operator_specification_get_pin_derived_class_type_name"
@@ -448,6 +458,7 @@ def _fill_pins(self, binput, to_fill):
448458
pin_opt,
449459
pin_ell,
450460
pin_derived_class_type_name,
461+
pin_aliases,
451462
)
452463

453464
@property

src/ansys/dpf/core/outputs.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(self, spec, pin, operator):
5454
self._python_expected_types = []
5555
for cpp_type in self._spec.type_names:
5656
self._python_expected_types.append(map_types_to_python[cpp_type])
57+
self.aliases = self._spec.aliases
5758

5859
def get_data(self):
5960
"""Retrieve the output of the operator."""
@@ -118,6 +119,8 @@ def __str__(self):
118119
docstr += " -" + exp_types + "\n"
119120
if self._spec.document:
120121
docstr += "help: " + self._spec.document + "\n"
122+
if self.aliases:
123+
docstr += f"aliases: {self.aliases}\n"
121124
return docstr
122125

123126

@@ -148,7 +151,7 @@ def _get_given_output(self, input_type_name):
148151
corresponding_pins.append(pin)
149152
return corresponding_pins
150153

151-
def __getitem__(self, index):
154+
def __getitem__(self, index) -> Output:
152155
return self._outputs[index]
153156

154157
def __str__(self):
@@ -157,8 +160,9 @@ def __str__(self):
157160
tot_string = str(output._spec.name)
158161
input_string = tot_string.split("\n")
159162
input_string1 = input_string[0]
160-
line = [" ", "- ", input_string1]
161-
docstr += "{:<5}{:<4}{:<20}\n".format(*line)
163+
aliases = tuple(output._spec.aliases) if output._spec.aliases else ""
164+
line = [" ", "- ", input_string1, aliases]
165+
docstr += "{:<5}{:<4}{:<20}{}\n".format(*line)
162166
for inputstr in input_string:
163167
if inputstr != input_string1:
164168
line = [" ", " ", inputstr]

0 commit comments

Comments
 (0)