Skip to content

Commit

Permalink
CHORE: remove all ironpython instances (#5340)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Morais <[email protected]>
Co-authored-by: Sebastien Morais <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent 14e68c1 commit b3fd3cb
Show file tree
Hide file tree
Showing 24 changed files with 154 additions and 340 deletions.
15 changes: 1 addition & 14 deletions _unittest/test_22_Circuit_DynamicLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from ansys.aedt.core import Circuit
from ansys.aedt.core import Q2d
from ansys.aedt.core import Q3d
from ansys.aedt.core.generic.general_methods import is_ironpython
from ansys.aedt.core.generic.settings import is_linux
import pytest

Expand Down Expand Up @@ -95,16 +94,13 @@ def init(self, aedtapp, local_scratch, examples):
def test_01_save(self):
assert os.path.exists(self.aedtapp.project_path)

@pytest.mark.skipif(
is_ironpython or config.get("skip_circuits", False), reason="Skipped because Desktop is crashing"
)
@pytest.mark.skipif(config.get("skip_circuits", False), reason="Skipped because Desktop is crashing")
def test_02_add_subcircuits_3dlayout(self):
layout_design = "layout_cutout"
hfss3Dlayout_comp = self.aedtapp.modeler.schematic.add_subcircuit_3dlayout(layout_design)
assert hfss3Dlayout_comp.id == 86
assert hfss3Dlayout_comp

@pytest.mark.skipif(is_ironpython, reason="Skipped because Desktop is crashing")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical.")
def test_03_add_subcircuits_hfss_link(self, add_app):
pin_names = self.aedtapp.get_source_pin_names(src_design_name, src_project_name, self.src_project_file, 2)
Expand All @@ -115,26 +111,22 @@ def test_03_add_subcircuits_hfss_link(self, add_app):
assert hfss_comp.id == 87
assert hfss_comp.composed_name == "CompInst@uUSB;87;3"

@pytest.mark.skipif(is_ironpython, reason="Skipped because Desktop is crashing")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical")
def test_04_refresh_dynamic_link(self):
assert self.aedtapp.modeler.schematic.refresh_dynamic_link("uUSB")

@pytest.mark.skipif(is_ironpython, reason="Skipped because Desktop is crashing")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical")
def test_05_set_sim_option_on_hfss_subcircuit(self):
hfss_comp = "CompInst@uUSB;87;3"
assert self.aedtapp.modeler.schematic.set_sim_option_on_hfss_subcircuit(hfss_comp)
assert self.aedtapp.modeler.schematic.set_sim_option_on_hfss_subcircuit(hfss_comp, option="interpolate")
assert not self.aedtapp.modeler.schematic.set_sim_option_on_hfss_subcircuit(hfss_comp, option="not_good")

@pytest.mark.skipif(is_ironpython, reason="Skipped because AEDT is crashing.")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical")
def test_06_set_sim_solution_on_hfss_subcircuit(self):
hfss_comp = "CompInst@uUSB;87;3"
assert self.aedtapp.modeler.schematic.set_sim_solution_on_hfss_subcircuit(hfss_comp)

@pytest.mark.skipif(is_ironpython, reason="Skipped because Desktop is crashing")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical")
def test_07_create_page_port_and_interface_port(self):
hfss_comp_id = 87
Expand Down Expand Up @@ -207,7 +199,6 @@ def test_07_create_page_port_and_interface_port(self):

assert "Port_remove" not in self.aedtapp.excitations

@pytest.mark.skipif(is_ironpython, reason="Skipped because Desktop is crashing")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical")
def test_08_assign_excitations(self):
filepath = os.path.join(local_path, "example_models", test_subfloder, "frequency_dependent_source.fds")
Expand All @@ -233,7 +224,6 @@ def test_09_setup(self):
LNA_setup.props["SweepDefinition"]["Data"] = " ".join(sweep_list)
assert LNA_setup.update()

@pytest.mark.skipif(is_ironpython, reason="Skipped because Desktop is crashing")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical")
def test_10_q2d_link(self, add_app):
self.aedtapp.insert_design("test_link")
Expand All @@ -244,7 +234,6 @@ def test_10_q2d_link(self, add_app):
assert c1.parameters["Length"] == "25mm"
assert c1.parameters["r1"] == "0.3mm"

@pytest.mark.skipif(is_ironpython, reason="Skipped because Desktop is crashing")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical")
def test_10_q3d_link(self, add_app):
q3d = add_app(application=Q3d, project_name=self.q3d, just_open=True)
Expand All @@ -255,7 +244,6 @@ def test_10_q3d_link(self, add_app):
assert q3d_comp
assert len(q3d_comp.pins) == 4

@pytest.mark.skipif(is_ironpython, reason="Skipped because Desktop is crashing")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical")
def test_10_hfss_link(self, add_app):
hfss = add_app(project_name=self.q3d, just_open=True)
Expand All @@ -268,7 +256,6 @@ def test_10_hfss_link(self, add_app):
hfss2, solution_name="Setup2 : Sweep", tline_port="1"
)

@pytest.mark.skipif(is_ironpython, reason="Skipped because Desktop is crashing")
@pytest.mark.skipif(config["NonGraphical"] and is_linux, reason="Method not working in Linux and Non graphical")
def test_11_siwave_link(self):
model = os.path.join(local_path, "example_models", test_subfloder, "siwave_syz.siw")
Expand Down
3 changes: 1 addition & 2 deletions src/ansys/aedt/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def custom_show_warning(message, category, filename, lineno, file=None, line=Non

# isort: on

if not ("IronPython" in sys.version or ".NETFramework" in sys.version): # pragma: no cover
if not (".NETFramework" in sys.version): # pragma: no cover
import ansys.aedt.core.downloads as downloads
from ansys.aedt.core.edb import Edb # nosec
from ansys.aedt.core.edb import Siwave # nosec
Expand Down Expand Up @@ -105,7 +105,6 @@ def custom_show_warning(message, category, filename, lineno, file=None, line=Non
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import generate_unique_project_name
from ansys.aedt.core.generic.general_methods import inside_desktop
from ansys.aedt.core.generic.general_methods import is_ironpython
from ansys.aedt.core.generic.general_methods import is_linux
from ansys.aedt.core.generic.general_methods import is_windows
from ansys.aedt.core.generic.general_methods import online_help
Expand Down
7 changes: 1 addition & 6 deletions src/ansys/aedt/core/application/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import os
import re
import shutil
import subprocess # nosec
import tempfile
import time

Expand All @@ -49,7 +50,6 @@
from ansys.aedt.core.generic.constants import VIEW
from ansys.aedt.core.generic.general_methods import filter_tuple
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import is_ironpython
from ansys.aedt.core.generic.general_methods import is_linux
from ansys.aedt.core.generic.general_methods import is_windows
from ansys.aedt.core.generic.general_methods import open_file
Expand All @@ -69,11 +69,6 @@
from ansys.aedt.core.modules.solve_setup import SetupSBR
from ansys.aedt.core.modules.solve_sweeps import SetupProps

if is_linux and is_ironpython:
import subprocessdotnet as subprocess # nosec
else:
import subprocess # nosec


class Analysis(Design, object):
"""Contains all common analysis functions.
Expand Down
7 changes: 2 additions & 5 deletions src/ansys/aedt/core/application/analysis_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from ansys.aedt.core.generic.configurations import Configurations
from ansys.aedt.core.generic.constants import unit_converter
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import is_ironpython
from ansys.aedt.core.generic.general_methods import open_file
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
from ansys.aedt.core.generic.settings import settings
Expand Down Expand Up @@ -283,9 +282,7 @@ def plot(
:class:`ansys.aedt.core.generic.plot.ModelPlotter`
Model Object.
"""
if is_ironpython:
self.logger.warning("Plot is available only on CPython")
elif self._aedt_version < "2021.2":
if self._aedt_version < "2021.2":
self.logger.warning("Plot is supported from AEDT 2021 R2.")
else:
return self.post.plot_model_obj(
Expand Down Expand Up @@ -1175,7 +1172,7 @@ def identify_touching_conductors(self, assignment=None):
dict
"""
if is_ironpython and settings.aedt_version < "2023.2": # pragma: no cover
if settings.aedt_version < "2023.2": # pragma: no cover
self.logger.error("This method requires CPython and PyVista.")
return {}
if settings.aedt_version >= "2023.2" and self.design_type == "HFSS": # pragma: no cover
Expand Down
11 changes: 4 additions & 7 deletions src/ansys/aedt/core/application/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
from ansys.aedt.core.generic.general_methods import check_and_download_file
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import inner_project_settings
from ansys.aedt.core.generic.general_methods import is_ironpython
from ansys.aedt.core.generic.general_methods import is_project_locked
from ansys.aedt.core.generic.general_methods import is_windows
from ansys.aedt.core.generic.general_methods import open_file
Expand Down Expand Up @@ -240,8 +239,7 @@ def __init__(
self._project_path = None
self.__t = None
if (
not is_ironpython
and project_name
project_name
and os.path.exists(project_name)
and (os.path.splitext(project_name)[1] == ".aedt" or os.path.splitext(project_name)[1] == ".a3dcomp")
):
Expand Down Expand Up @@ -301,7 +299,7 @@ def __init__(
self._logger.odesign = self.odesign
AedtObjects.__init__(self, self._desktop_class, self.oproject, self.odesign, is_inherithed=True)
self.logger.info("Aedt Objects correctly read")
if not self.__t and not settings.lazy_load and not is_ironpython and os.path.exists(self.project_file):
if not self.__t and not settings.lazy_load and os.path.exists(self.project_file):
self.__t = threading.Thread(target=load_aedt_thread, args=(self.project_file,), daemon=True)
self.__t.start()
self._variable_manager = VariableManager(self)
Expand Down Expand Up @@ -2660,7 +2658,7 @@ def load_project(self, file_name, design=None, close_active=False, set_active=Fa

@pyaedt_function_handler()
def _close_edb(self):
if self.design_type == "HFSS 3D Layout Design" and not is_ironpython: # pragma: no cover
if self.design_type == "HFSS 3D Layout Design": # pragma: no cover
if self.modeler and self.modeler._edb:
self.modeler._edb.close_edb()

Expand Down Expand Up @@ -3292,8 +3290,7 @@ def close_project(self, name=None, save=True):
self._logger = self._global_logger
self.odesktop.CloseProject(name)
if name == legacy_name:
if not is_ironpython:
self._init_variables()
self._init_variables()
self._oproject = None
self._odesign = None
self.logger.odesign = None
Expand Down
12 changes: 4 additions & 8 deletions src/ansys/aedt/core/common_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,17 @@

from ansys.aedt.core.aedt_logger import pyaedt_logger as logger
from ansys.aedt.core.generic.aedt_versions import aedt_versions
from ansys.aedt.core.generic.general_methods import is_ironpython
from ansys.aedt.core.generic.settings import settings

# import sys
from ansys.aedt.core.rpc.rpyc_services import FileManagement
from ansys.aedt.core.rpc.rpyc_services import GlobalService
from ansys.aedt.core.rpc.rpyc_services import ServiceManager
from ansys.aedt.core.rpc.rpyc_services import check_port

if not is_ironpython:
import rpyc
from rpyc.core import consts
from rpyc.utils.server import OneShotServer
from rpyc.utils.server import ThreadedServer

import rpyc
from rpyc.core import consts
from rpyc.utils.server import OneShotServer
from rpyc.utils.server import ThreadedServer

# Maximum Stream message size. Set to 256MB
consts.STREAM_CHUNK = 256000000
Expand Down
51 changes: 8 additions & 43 deletions src/ansys/aedt/core/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@
from ansys.aedt.core.aedt_logger import AedtLogger
from ansys.aedt.core.aedt_logger import pyaedt_logger
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import is_ironpython
from ansys.aedt.core.generic.general_methods import is_linux
from ansys.aedt.core.generic.general_methods import is_windows

if is_linux:
os.environ["ANS_NODEPCHECK"] = str(1)

if is_linux and is_ironpython: # pragma: no cover
import subprocessdotnet as subprocess
else:
import subprocess
import subprocess

from ansys.aedt.core import __version__
from ansys.aedt.core.generic.aedt_versions import aedt_versions
Expand All @@ -71,7 +67,6 @@
from ansys.aedt.core.generic.general_methods import get_string_version
from ansys.aedt.core.generic.general_methods import grpc_active_sessions
from ansys.aedt.core.generic.general_methods import inside_desktop
from ansys.aedt.core.generic.general_methods import is_ironpython
from ansys.aedt.core.generic.general_methods import open_file
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
from ansys.aedt.core.generic.settings import settings
Expand Down Expand Up @@ -296,7 +291,7 @@ def _close_aedt_application(desktop_class, close_desktop, pid, is_grpc_api):
``True`` when successful, ``False`` when failed.
"""
if settings.remote_rpc_session or (settings.aedt_version >= "2022.2" and is_grpc_api and not is_ironpython):
if settings.remote_rpc_session or (settings.aedt_version >= "2022.2" and is_grpc_api):
if close_desktop and desktop_class.parent_desktop_id: # pragma: no cover
pyaedt_logger.error("A child desktop session is linked to this session.")
pyaedt_logger.error("Multiple desktop sessions must be released in reverse order.")
Expand Down Expand Up @@ -340,7 +335,7 @@ def _close_aedt_application(desktop_class, close_desktop, pid, is_grpc_api):
pyaedt_logger.warning(
"Something went wrong releasing AEDT. Exception in `_main.COMUtil.ReleaseCOMObjectScope`."
)
if not settings.remote_rpc_session and not is_ironpython and close_desktop: # pragma: no cover
if not settings.remote_rpc_session and close_desktop: # pragma: no cover
timeout = 10
while pid in active_sessions():
time.sleep(1)
Expand Down Expand Up @@ -579,20 +574,18 @@ def __init__(
student_version_flag, version_key, version = self._assert_version(version, student_version)

# start the AEDT opening decision tree
# starting_mode can be one of these: "grpc", "com", "ironpython", "console_in", "console_out"
# starting_mode can be one of these: "grpc", "com", "console_in", "console_out"
if "oDesktop" in dir(sys.modules["__main__"]): # pragma: no cover
# we are inside the AEDT Ironpython console
pyaedt_logger.logger.info("Iropnpython session with embedded oDesktop")
pyaedt_logger.logger.info("Ironpython session with embedded oDesktop")
starting_mode = "console_in"
elif is_linux:
starting_mode = "grpc"
elif is_windows and "pythonnet" not in modules:
starting_mode = "grpc"
elif settings.remote_rpc_session:
starting_mode = "grpc"
elif is_ironpython:
starting_mode = "ironpython"
elif aedt_process_id and not new_desktop and not is_ironpython: # pragma: no cover
elif aedt_process_id and not new_desktop: # pragma: no cover
# connecting to an existing session has the precedence over use_grpc_api user preference
sessions = active_sessions(
version=version, student_version=student_version_flag, non_graphical=non_graphical
Expand Down Expand Up @@ -642,10 +635,7 @@ def __init__(

else:
settings.aedt_version = version_key
if starting_mode == "ironpython": # pragma no cover
self._logger.info("Launching PyAEDT with IronPython.")
self._init_ironpython(non_graphical, new_desktop, version)
elif starting_mode == "com": # pragma no cover
if starting_mode == "com": # pragma no cover
self._logger.info("Launching PyAEDT with CPython and PythonNET.")
self._init_dotnet(
non_graphical,
Expand Down Expand Up @@ -680,8 +670,6 @@ def __init__(

self.aedt_version_id = self.odesktop.GetVersion()[0:6]

if is_ironpython: # pragma no cover
sys.path.append(os.path.join(settings.aedt_install_dir, "common", "commonfiles", "IronPython", "DLLs"))
if "GetGrpcServerPort" in dir(self.odesktop):
self.port = self.odesktop.GetGrpcServerPort()
# save the current desktop session in the database
Expand All @@ -698,7 +686,7 @@ def __exit__(self, ex_type, ex_value, ex_traceback): # pragma no cover
# Write the trace stack to the log file if an exception occurred in the main script.
if ex_type:
err = self._exception(ex_value, ex_traceback)
if self.close_on_exit or not is_ironpython:
if self.close_on_exit:
self.release_desktop(close_projects=self.close_on_exit, close_on_exit=self.close_on_exit)
self.__closed = True

Expand Down Expand Up @@ -898,28 +886,6 @@ def _assert_version(self, specified_version, student_version):

return student_version, specified_version, version

def _init_ironpython(self, non_graphical, new_aedt_session, version): # pragma no cover
from ansys.aedt.core.generic.clr_module import _clr

base_path = settings.aedt_install_dir
sys.path.append(base_path)
sys.path.append(os.path.join(base_path, "PythonFiles", "DesktopPlugin"))
_clr.AddReference("Ansys.Ansoft.CoreCOMScripting")
AnsoftCOMUtil = __import__("Ansys.Ansoft.CoreCOMScripting")
self.COMUtil = AnsoftCOMUtil.Ansoft.CoreCOMScripting.Util.COMUtil
StandalonePyScriptWrapper = AnsoftCOMUtil.Ansoft.CoreCOMScripting.COM.StandalonePyScriptWrapper
if non_graphical or new_aedt_session:
# forcing new thread to start in non-graphical
oAnsoftApp = StandalonePyScriptWrapper.CreateObjectNew(non_graphical)
else:
oAnsoftApp = StandalonePyScriptWrapper.CreateObject(version)
self.odesktop = oAnsoftApp.GetAppDesktop()
self.isoutsideDesktop = True
sys.path.append(os.path.join(base_path, "common", "commonfiles", "IronPython", "DLLs"))
self.is_grpc_api = False

return True

@staticmethod
def _run_student(): # pragma: no cover
DETACHED_PROCESS = 0x00000008
Expand Down Expand Up @@ -1049,7 +1015,6 @@ def _initialize(
self.grpc_plugin = AEDT(os.environ["DesktopPluginPyAEDT"])
oapp = self.grpc_plugin.CreateAedtApplication(machine, port, non_graphical, new_session)
if oapp:

self.isoutsideDesktop = True
self.aedt_process_id = self.odesktop.GetProcessID()
return True
Expand Down
Loading

0 comments on commit b3fd3cb

Please sign in to comment.