Skip to content

Commit

Permalink
api upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hpohekar committed Dec 11, 2024
1 parent ab5343b commit 938ca31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
16 changes: 7 additions & 9 deletions src/ansys/fluent/core/services/api_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from typing import TypeVar

from ansys.fluent.core.services.scheme_eval import SchemeEval
from ansys.fluent.core.services.app_utilities import AppUtilities
from ansys.fluent.core.utils.fluent_version import FluentVersion

_TApiUpgradeAdvisor = TypeVar("_TApiUpgradeAdvisor", bound="ApiUpgradeAdvisor")
Expand All @@ -12,11 +12,12 @@
class ApiUpgradeAdvisor:
"""API upgrade advisor."""

def __init__(self, scheme_eval: SchemeEval, version: str, mode: str) -> None:
def __init__(self, app_utilities: AppUtilities, version: str, mode: str) -> None:
"""Initialize ApiUpgradeAdvisor."""
self._scheme_eval = scheme_eval.scheme_eval
self._app_utilities = app_utilities
self._version = version
self._mode = mode
self._id = None

def _can_advise(self) -> bool:
return (
Expand All @@ -27,16 +28,13 @@ def _can_advise(self) -> bool:

def __enter__(self) -> _TApiUpgradeAdvisor:
if self._can_advise():
self._scheme_eval("(define pyfluent-journal-str-port (open-output-string))")
self._scheme_eval("(api-echo-python-port pyfluent-journal-str-port)")
self._id = self._app_utilities.start_python_journal()
return self

def __exit__(self, exc_type, exc_value, exc_tb) -> None:
if self._can_advise():
self._scheme_eval("(api-unecho-python-port pyfluent-journal-str-port)")
journal_str = self._scheme_eval(
"(close-output-port pyfluent-journal-str-port)"
).strip()

journal_str = (self._app_utilities.stop_python_journal(self._id)).strip()
if (
journal_str.startswith("solver.")
and not journal_str.startswith("solver.tui")
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/fluent/core/services/datamodel_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ def __init__(
channel: grpc.Channel,
metadata: list[tuple[str, str]],
fluent_error_state,
scheme_eval,
app_utilities,
) -> None:
"""__init__ method of DatamodelService class."""
self._impl = DatamodelServiceImpl(channel, metadata, fluent_error_state)
self._scheme_eval = scheme_eval
self._app_utilities = app_utilities

def get_attribute_value(
self, path: str, attribute: str, include_unavailable: bool
Expand Down Expand Up @@ -233,7 +233,7 @@ def execute(self, *args, **kwargs) -> Any:
Query result (any Python datatype)
"""
with ApiUpgradeAdvisor(
self._service._scheme_eval,
self._service._app_utilities,
self._version,
self._mode,
):
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _build_from_fluent_connection(
fluent_connection._channel,
fluent_connection._metadata,
self._error_state,
self.scheme_eval,
self._app_utilities,
)

self._datamodel_service_se = service_creator("datamodel").create(
Expand Down

0 comments on commit 938ca31

Please sign in to comment.