Skip to content
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

REFACTOR: Improve API and security in Desktop #5892

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions doc/changelog.d/5892.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve API and security in Desktop
37 changes: 21 additions & 16 deletions src/ansys/aedt/core/application/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from ansys.aedt.core.application.design_solutions import solutions_defaults
from ansys.aedt.core.application.variables import DataSet
from ansys.aedt.core.application.variables import VariableManager
from ansys.aedt.core.desktop import _init_desktop_from_design
from ansys.aedt.core.desktop import Desktop
from ansys.aedt.core.desktop import exception_to_desktop
from ansys.aedt.core.generic.aedt_versions import aedt_versions
from ansys.aedt.core.generic.constants import AEDT_UNITS
Expand Down Expand Up @@ -195,7 +195,7 @@
self._design_datasets: List = []
self.close_on_exit: bool = close_on_exit
self._desktop_class = None
self._desktop_class = _init_desktop_from_design(
self._desktop_class = self.__init_desktop_from_design(

Check warning on line 198 in src/ansys/aedt/core/application/design.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/application/design.py#L198

Added line #L198 was not covered by tests
version,
non_graphical,
new_desktop,
Expand Down Expand Up @@ -4230,6 +4230,11 @@
self.odesign.EditNotes(text)
return True

def __init_desktop_from_design(*args, **kwargs):
"""Internal instantiation of the ``Desktop`` class."""
Desktop._invoked_from_design = True
return Desktop(*args, **kwargs)

Check warning on line 4236 in src/ansys/aedt/core/application/design.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/application/design.py#L4235-L4236

Added lines #L4235 - L4236 were not covered by tests


class DesignSettings:
"""Get design settings for the current AEDT app.
Expand All @@ -4243,20 +4248,6 @@
self._app: Any = app
self.manipulate_inputs: Optional[DesignSettingsManipulation] = None

@property
def design_settings(self) -> Optional[Any]:
"""Design settings."""
try:
return self._app.odesign.GetChildObject("Design Settings")
except GrpcApiError: # pragma: no cover
self._app.logger.error("Failed to retrieve design settings.")
return None

@property
def available_properties(self) -> List[str]:
"""Available properties names for the current design."""
return [prop for prop in self.design_settings.GetPropNames() if not prop.endswith("/Choices")]

def __repr__(self) -> str:
lines = ["{"]
for prop in self.available_properties:
Expand Down Expand Up @@ -4291,6 +4282,20 @@
def __contains__(self, item: str) -> bool:
return item in self.available_properties

@property
def design_settings(self) -> Optional[Any]:
"""Design settings."""
try:
return self._app.odesign.GetChildObject("Design Settings")

Check warning on line 4289 in src/ansys/aedt/core/application/design.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/application/design.py#L4288-L4289

Added lines #L4288 - L4289 were not covered by tests
except GrpcApiError: # pragma: no cover
self._app.logger.error("Failed to retrieve design settings.")
return None

@property
def available_properties(self) -> List[str]:
"""Available properties names for the current design."""
return [prop for prop in self.design_settings.GetPropNames() if not prop.endswith("/Choices")]

Check warning on line 4297 in src/ansys/aedt/core/application/design.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/application/design.py#L4297

Added line #L4297 was not covered by tests


class DesignSettingsManipulation:
@abstractmethod
Expand Down
Loading
Loading