Skip to content

Commit

Permalink
Fix for menus inserted at runtime (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkundu1 authored Dec 14, 2022
1 parent ffef500 commit 6542d04
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
43 changes: 19 additions & 24 deletions src/ansys/fluent/core/services/datamodel_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,31 +256,26 @@ def __dir__(self) -> Iterable[str]:
]

def __getattribute__(self, name):
attr = super().__getattribute__(name)
if type(attr) == types.MethodType:
path = self.path + [name]
# if menus are inserted at runtime in Fluent
if PyMenu(self.service, path).get_child_names():
return TUIMenuGeneric(path, self.service)
return attr


class TUIMenuGeneric(TUIMenu):
"""Generic menu class for when the explicit menu classes aren't
available."""

def __getattribute__(self, name):
if name in ["path", "service"]:
return super().__getattribute__(name)
name = convert_func_name_to_tui_menu(name)
path = self.path + [name]
if PyMenu(self.service, path).get_child_names():
return TUIMenuGeneric(path, self.service)
else:
return TUICommandGeneric(path, self.service)

try:
attr = super().__getattribute__(name)
if type(attr) == types.MethodType:
# some runtime submenus are generated as methods during codegen
path = self.path + [name]
if PyMenu(self.service, path).get_child_names():
return TUIMenu(path, self.service)
return attr
except AttributeError as ex:
if name in dir(self):
# for runtime submenus and commands which are not available during codegen
path = self.path + [name]
if PyMenu(self.service, path).get_child_names():
return TUIMenu(path, self.service)
else:
return TUICommand(path, self.service)
else:
raise ex

class TUICommandGeneric(TUIMenu):
class TUICommand(TUIMenu):
"""Generic command class for when the explicit menu classes aren't
available."""

Expand Down
4 changes: 2 additions & 2 deletions src/ansys/fluent/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import grpc

from ansys.fluent.core.fluent_connection import _FluentConnection
from ansys.fluent.core.services.datamodel_tui import TUIMenuGeneric
from ansys.fluent.core.services.datamodel_tui import TUIMenu
from ansys.fluent.core.session_base_meshing import _BaseMeshing
from ansys.fluent.core.session_shared import _CODEGEN_MSG_DATAMODEL, _CODEGEN_MSG_TUI
from ansys.fluent.core.solver.flobject import get_root as settings_get_root
Expand Down Expand Up @@ -329,7 +329,7 @@ def tui(self):
self._tui = tui_module.main_menu([], self._tui_service)
except (ImportError, ModuleNotFoundError):
LOG.warning(_CODEGEN_MSG_TUI)
self._tui = TUIMenuGeneric([], self._tui_service)
self._tui = TUIMenu([], self._tui_service)
return self._tui

@property
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/fluent/core/session_base_meshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ansys.fluent.core.fluent_connection import _FluentConnection
from ansys.fluent.core.meshing.meshing import Meshing
from ansys.fluent.core.services.datamodel_se import PyMenuGeneric
from ansys.fluent.core.services.datamodel_tui import TUIMenuGeneric
from ansys.fluent.core.services.datamodel_tui import TUIMenu
from ansys.fluent.core.session_shared import _CODEGEN_MSG_DATAMODEL, _CODEGEN_MSG_TUI
from ansys.fluent.core.utils.fluent_version import get_version_for_filepath
from ansys.fluent.core.utils.logging import LOG
Expand Down Expand Up @@ -46,7 +46,7 @@ def tui(self):
self._tui = tui_module.main_menu([], self._tui_service)
except (ImportError, ModuleNotFoundError):
LOG.warning(_CODEGEN_MSG_TUI)
self._tui = TUIMenuGeneric([], self._tui_service)
self._tui = TUIMenu([], self._tui_service)
return self._tui

@property
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/fluent/core/session_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import importlib

from ansys.fluent.core.services.datamodel_se import PyMenuGeneric
from ansys.fluent.core.services.datamodel_tui import TUIMenuGeneric
from ansys.fluent.core.services.datamodel_tui import TUIMenu
from ansys.fluent.core.session import (
_CODEGEN_MSG_TUI,
_BaseSession,
Expand Down Expand Up @@ -54,7 +54,7 @@ def tui(self):
self._tui = tui_module.main_menu([], self._tui_service)
except ImportError:
LOG.warning(_CODEGEN_MSG_TUI)
self._tui = TUIMenuGeneric([], self._tui_service)
self._tui = TUIMenu([], self._tui_service)
return self._tui

@property
Expand Down
9 changes: 9 additions & 0 deletions tests/test_tui_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
from util.solver_workflow import new_solver_session # noqa: F401

from ansys.fluent.core.services.datamodel_tui import TUIMenu


@pytest.mark.skip("randomly failing due to missing transcript capture")
def test_report_system_proc_stats_tui(new_solver_session, capsys) -> None:
Expand All @@ -10,3 +12,10 @@ def test_report_system_proc_stats_tui(new_solver_session, capsys) -> None:
new_solver_session.solver.tui.report.system.sys_stats()
captured = capsys.readouterr()
assert "CPU" in captured.out

def test_runtime_tui_menus(load_static_mixer_case) -> None:
solver = load_static_mixer_case
solver.tui.define.models.addon_module(3)
rmf = solver.tui.define.models.resolved_MEA_fuelcells
assert rmf is not None
assert rmf.__class__ == TUIMenu

0 comments on commit 6542d04

Please sign in to comment.