From 37d8b7f188fc09c2f8cd5abd0c5e221affa24a5b Mon Sep 17 00:00:00 2001 From: Massimo Capodiferro <77293250+maxcapodi78@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:49:11 +0200 Subject: [PATCH] remove __import__ (#4445) Co-authored-by: maxcapodi78 --- pyaedt/desktop.py | 15 ++++----------- pyaedt/generic/configurations.py | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/pyaedt/desktop.py b/pyaedt/desktop.py index a90d6c07966..dc086fbdb90 100644 --- a/pyaedt/desktop.py +++ b/pyaedt/desktop.py @@ -58,8 +58,6 @@ modules = [tup[1] for tup in pkgutil.iter_modules()] -python_grpc_wrapper = None - @pyaedt_function_handler() def launch_aedt(full_path, non_graphical, port, student_version, first_run=True): @@ -239,7 +237,6 @@ def _close_aedt_application(desktop_class, close_desktop, pid, is_grpc_api): ``True`` when successful, ``False`` when failed. """ - global python_grpc_wrapper if settings.remote_rpc_session or (settings.aedt_version >= "2022.2" and is_grpc_api and not is_ironpython): if close_desktop and desktop_class.parent_desktop_id: pyaedt_logger.error("A child desktop session is linked to this session.") @@ -273,9 +270,8 @@ def _close_aedt_application(desktop_class, close_desktop, pid, is_grpc_api): return False else: try: - if not python_grpc_wrapper: - python_grpc_wrapper = __import__("pyaedt.generic.grpc_plugin") - # import pyaedt.generic.grpc_plugin as StandalonePyScriptWrapper + import pyaedt.generic.grpc_plugin as python_grpc_wrapper + python_grpc_wrapper.AedtAPI.ReleaseAll() return True except Exception: # pragma: no cover @@ -911,7 +907,6 @@ def _initialize( version=None, is_grpc=True, ): - global python_grpc_wrapper if not is_grpc: from pyaedt.generic.clr_module import _clr @@ -934,10 +929,8 @@ def _initialize( os.environ["DesktopPluginPyAEDT"] = os.path.join(settings.aedt_install_dir, "PythonFiles", "DesktopPlugin") launch_msg = "AEDT installation Path {}".format(base_path) self.logger.info(launch_msg) - if not python_grpc_wrapper: - python_grpc_wrapper = __import__("pyaedt.generic.grpc_plugin") - python_grpc_wrapper = python_grpc_wrapper.generic.grpc_plugin - # import pyaedt.generic.grpc_plugin as StandalonePyScriptWrapper + import pyaedt.generic.grpc_plugin as python_grpc_wrapper + if _desktop_sessions: last_session = list(_desktop_sessions.values())[-1] all_desktop = [i for i in last_session.odesktop.GetRunningInstancesMgr().GetAllRunningInstances()] diff --git a/pyaedt/generic/configurations.py b/pyaedt/generic/configurations.py index c8197437066..ad1dcaf5a03 100644 --- a/pyaedt/generic/configurations.py +++ b/pyaedt/generic/configurations.py @@ -697,7 +697,7 @@ def __init__(self, app): config_schema_path = os.path.join(pyaedt_installed_path, "misc", "config.schema.json") - if os.path.isfile(config_schema_path): + if os.path.exists(config_schema_path): with open(config_schema_path, "rb") as schema: schema_bytes = schema.read()