diff --git a/doc/source/Resources/PyAEDTInstallerFromDesktop.py b/doc/source/Resources/PyAEDTInstallerFromDesktop.py index 706cabed594..1ed1eefd86e 100644 --- a/doc/source/Resources/PyAEDTInstallerFromDesktop.py +++ b/doc/source/Resources/PyAEDTInstallerFromDesktop.py @@ -42,15 +42,37 @@ def run_pyinstaller_from_c_python(oDesktop): return_code = run_command(" ".join(command)) err_msg = "There was an error while installing PyAEDT. Refer to the Terminal window where AEDT was launched " \ "from." - - if version >= "232": - oDesktop.RefreshToolkitUI() - + if is_windows: + venv_dir = os.path.join(os.environ["APPDATA"], "pyaedt_env_ide", "v" + version) + python_exe = os.path.join(venv_dir, "Scripts", "python.exe") + else: + venv_dir = os.path.join(os.environ["HOME"], "pyaedt_env_ide", "v" + version) + python_exe = os.path.join(venv_dir, "bin", "python") if str(return_code) != "0": oDesktop.AddMessage("", "", 2, err_msg) return + else: + oDesktop.AddMessage("", "", 0, "PyAEDT setup complete.") + - msg = "PyAEDT setup complete." + import tempfile + python_script = os.path.join(tempfile.gettempdir(), "configure_pyaedt.py") + with open(python_script, "w") as f: + # enable in debu mode + #f.write("import sys\n") + #f.write('sys.path.insert(0, r"c:\\ansysdev\\git\\repos\\pyaedt")\n') + f.write("from pyaedt.misc.aedtlib_personalib_install import add_pyaedt_to_aedt\n") + f.write('add_pyaedt_to_aedt(aedt_version="{}", is_student_version={}, use_sys_lib=False, new_desktop_session=False, pers_dir=r"{}")\n'.format(oDesktop.GetVersion()[:6], is_student_version(oDesktop), oDesktop.GetPersonalLibDirectory())) + + command = r'"{}" "{}"'.format(python_exe, python_script) + oDesktop.AddMessage("", "", 0, command) + ret_code = os.system(command) + if ret_code != 0: + oDesktop.AddMessage("", "", 2, "Error configuring the configuration Tab.") + return + if version >= "232": + oDesktop.RefreshToolkitUI() + msg = "PyAEDT configuration complete." if is_linux: msg += " Please ensure Ansys Electronics Desktop is launched in gRPC mode (i.e. launch ansysedt with -grpcsrv" \ " argument) to take advantage of the new toolkits." @@ -152,19 +174,19 @@ def install_pyaedt(): else: run_command('"{}" --default-timeout=1000 install pyaedt[full]'.format(pip_exe)) - if is_windows: - pyaedt_setup_script = "{}/Lib/site-packages/pyaedt/misc/aedtlib_personalib_install.py".format(venv_dir) - else: - pyaedt_setup_script = "{}/lib/python{}/site-packages/pyaedt/misc/aedtlib_personalib_install.py".format( - venv_dir, args.python_version) - - if not os.path.isfile(pyaedt_setup_script): - sys.exit("[ERROR] PyAEDT was not setup properly since {} file does not exist.".format(pyaedt_setup_script)) - - command = '"{}" "{}" --version={}'.format(python_exe, pyaedt_setup_script, args.version) - if args.student: - command += " --student" - run_command(command) + # if is_windows: + # pyaedt_setup_script = "{}/Lib/site-packages/pyaedt/misc/aedtlib_personalib_install.py".format(venv_dir) + # else: + # pyaedt_setup_script = "{}/lib/python{}/site-packages/pyaedt/misc/aedtlib_personalib_install.py".format( + # venv_dir, args.python_version) + # + # if not os.path.isfile(pyaedt_setup_script): + # sys.exit("[ERROR] PyAEDT was not setup properly since {} file does not exist.".format(pyaedt_setup_script)) + # + # command = '"{}" "{}" --version={}'.format(python_exe, pyaedt_setup_script, args.version) + # if args.student: + # command += " --student" + # run_command(command) sys.exit(0) diff --git a/pyaedt/desktop.py b/pyaedt/desktop.py index e57146407a0..30aca77ef6d 100644 --- a/pyaedt/desktop.py +++ b/pyaedt/desktop.py @@ -476,6 +476,8 @@ def __init__( port=0, aedt_process_id=None, ): + if aedt_process_id: # pragma no cover + aedt_process_id = int(aedt_process_id) if getattr(self, "_initialized", None) is not None and self._initialized: return else: @@ -552,6 +554,7 @@ def __init__( sessions = active_sessions( version=specified_version, student_version=student_version_flag, non_graphical=non_graphical ) + self.logger.info(sessions) if aedt_process_id in sessions: if sessions[aedt_process_id] != -1: self.port = sessions[aedt_process_id] diff --git a/pyaedt/misc/Run_PyAEDT_Toolkit_Script.py_build b/pyaedt/misc/Run_PyAEDT_Toolkit_Script.py_build index c203856005b..aaac748a78b 100644 --- a/pyaedt/misc/Run_PyAEDT_Toolkit_Script.py_build +++ b/pyaedt/misc/Run_PyAEDT_Toolkit_Script.py_build @@ -30,6 +30,7 @@ else: def main(): try: + oDesktop.AddMessage("", "", 0, "Toolkit launched. Please wait.") # launch file version = oDesktop.GetVersion()[2:6].replace(".", "") python_exe = r"##PYTHON_EXE##" % version diff --git a/pyaedt/misc/aedtlib_personalib_install.py b/pyaedt/misc/aedtlib_personalib_install.py index 2cbc5905b14..e1f3bda7fa8 100644 --- a/pyaedt/misc/aedtlib_personalib_install.py +++ b/pyaedt/misc/aedtlib_personalib_install.py @@ -55,70 +55,84 @@ def process_arguments(args, parser): return args -def add_pyaedt_to_aedt(aedt_version, is_student_version=False, use_sys_lib=False, new_desktop_session=False): - from pyaedt import Desktop - from pyaedt.generic.general_methods import grpc_active_sessions - - sessions = grpc_active_sessions(aedt_version, is_student_version) - if not sessions: - if not new_desktop_session: - print("Launching a new AEDT desktop session.") - new_desktop_session = True - with Desktop( - specified_version=aedt_version, - non_graphical=new_desktop_session, - new_desktop_session=new_desktop_session, - student_version=is_student_version, - ) as d: - desktop = sys.modules["__main__"].oDesktop - pers1 = os.path.join(desktop.GetPersonalLibDirectory(), "pyaedt") - pid = desktop.GetProcessID() - # Linking pyaedt in PersonalLib for IronPython compatibility. - if os.path.exists(pers1): - d.logger.info("PersonalLib already mapped.") +def add_pyaedt_to_aedt( + aedt_version, is_student_version=False, use_sys_lib=False, new_desktop_session=False, sys_dir="", pers_dir="" +): + if not (sys_dir or pers_dir): + from pyaedt import Desktop + from pyaedt import settings + from pyaedt.generic.general_methods import grpc_active_sessions + + sessions = grpc_active_sessions(aedt_version, is_student_version) + close_on_exit = True + if not sessions: + if not new_desktop_session: + print("Launching a new AEDT desktop session.") + new_desktop_session = True else: - if is_windows: - os.system('mklink /D "{}" "{}"'.format(pers1, pyaedt_path)) + close_on_exit = False + settings.use_grpc_api = True + with Desktop( + specified_version=aedt_version, + non_graphical=new_desktop_session, + new_desktop_session=new_desktop_session, + student_version=is_student_version, + close_on_exit=close_on_exit, + ) as d: + desktop = sys.modules["__main__"].oDesktop + pers1 = os.path.join(desktop.GetPersonalLibDirectory(), "pyaedt") + pid = desktop.GetProcessID() + # Linking pyaedt in PersonalLib for IronPython compatibility. + if os.path.exists(pers1): + d.logger.info("PersonalLib already mapped.") else: - os.system('ln -s "{}" "{}"'.format(pyaedt_path, pers1)) - - toolkits = ["Project"] - # Bug on Linux 23.1 and before where Project level toolkits don't show up. Thus copying to individual design - # toolkits. - if is_linux and aedt_version <= "2023.1": - toolkits = [ - "2DExtractor", - "CircuitDesign", - "HFSS", - "HFSS-IE", - "HFSS3DLayoutDesign", - "Icepak", - "Maxwell2D", - "Maxwell3D", - "Q3DExtractor", - "Mechanical", - ] - - for product in toolkits: - if use_sys_lib: - try: - sys_dir = os.path.join(d.syslib, "Toolkits") - install_toolkit(sys_dir, product, aedt_version) - d.logger.info("Installed toolkit for {} in sys lib.".format(product)) - - except IOError: - pers_dir = os.path.join(d.personallib, "Toolkits") - install_toolkit(pers_dir, product, aedt_version) - d.logger.info("Installed toolkit for {} in personal lib.".format(product)) - else: - pers_dir = os.path.join(d.personallib, "Toolkits") + if is_windows: + os.system('mklink /D "{}" "{}"'.format(pers1, pyaedt_path)) + else: + os.system('ln -s "{}" "{}"'.format(pyaedt_path, pers1)) + sys_dir = d.syslib + pers_dir = d.personallib + if pid and new_desktop_session: + try: + os.kill(pid, 9) + except: + pass + + toolkits = ["Project"] + # Bug on Linux 23.1 and before where Project level toolkits don't show up. Thus copying to individual design + # toolkits. + if is_linux and aedt_version <= "2023.1": + toolkits = [ + "2DExtractor", + "CircuitDesign", + "HFSS", + "HFSS-IE", + "HFSS3DLayoutDesign", + "Icepak", + "Maxwell2D", + "Maxwell3D", + "Q3DExtractor", + "Mechanical", + ] + + for product in toolkits: + if use_sys_lib: + try: + sys_dir = os.path.join(sys_dir, "Toolkits") + install_toolkit(sys_dir, product, aedt_version) + print("Installed toolkit for {} in sys lib.".format(product)) + # d.logger.info("Installed toolkit for {} in sys lib.".format(product)) + + except IOError: + pers_dir = os.path.join(pers_dir, "Toolkits") install_toolkit(pers_dir, product, aedt_version) - d.logger.info("Installed toolkit for {} in personal lib.".format(product)) - if pid and new_desktop_session: - try: - os.kill(pid, 9) - except: - pass + print("Installed toolkit for {} in sys lib.".format(product)) + # d.logger.info("Installed toolkit for {} in personal lib.".format(product)) + else: + pers_dir = os.path.join(pers_dir, "Toolkits") + install_toolkit(pers_dir, product, aedt_version) + print("Installed toolkit for {} in sys lib.".format(product)) + # d.logger.info("Installed toolkit for {} in personal lib.".format(product)) def install_toolkit(toolkit_dir, product, aedt_version): diff --git a/pyaedt/misc/install_extra_toolkits.py b/pyaedt/misc/install_extra_toolkits.py index b6778764736..8d97f8c5425 100644 --- a/pyaedt/misc/install_extra_toolkits.py +++ b/pyaedt/misc/install_extra_toolkits.py @@ -11,9 +11,9 @@ "AntennaWizard": { "pip": "git+https://github.com/ansys/pyaedt-antenna-toolkit.git", "image": "pyansys.png", - "toolkit_script": "ansys/aedt/toolkits/antennas/run_toolkit.py", + "toolkit_script": "ansys/aedt/toolkits/antenna/run_toolkit.py", "installation_path": "HFSS", - "package_name": "ansys.aedt.toolkits.antennas", + "package_name": "ansys.aedt.toolkits.antenna", }, "ChokeWizard": { "pip": "git+https://github.com/ansys/pyaedt-choke-toolkit.git",