From cf8ab695d702cd1fc7645a82840d6e34fbf630ca Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 6 Nov 2024 11:17:10 +0100 Subject: [PATCH 01/15] WIP: use popen simplify IO redirect --- .../Resources/pyaedt_installer_from_aedt.py | 80 ++++++++++++++++--- 1 file changed, 68 insertions(+), 12 deletions(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index 8836d21d080..739eafb5cd0 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -86,18 +86,18 @@ def run_pyinstaller_from_c_python(oDesktop): command.extend(['--wheel="{}"'.format(wheelpyaedt)]) oDesktop.AddMessage("", "", 0, "Installing PyAEDT.") - if is_windows: - import subprocess - - process = subprocess.Popen(" ".join(command)) - process.wait() - return_code = process.returncode - err_msg = "There was an error while installing PyAEDT." - else: - 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 is_windows: + import subprocess + + process = subprocess.Popen(" ".join(command)) + process.wait() + return_code = process.returncode + err_msg = "There was an error while installing PyAEDT." + # else: + # 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 str(return_code) != "0": oDesktop.AddMessage("", "", 2, err_msg) @@ -223,6 +223,62 @@ def install_pyaedt(): args.edt_root, args.python_version.replace(".", "_") ) + ########### + import tkinter as tk + from tkinter import ttk + + # def create_disclaimer_window(root: tk.Tk): + # """Notify users about extra packages.""" + # DISCLAIMER = ( + # "The extension manager will download and install certain third-party software and/or " + # "open-source software (collectively, 'Third-Party Software'). Such Third-Party " + # "Software is subject to separate terms and conditions and not the terms of your " + # "Ansys software license agreement. Ansys does not warrant or support such " + # "Third-Party Software. Do you still wish to proceed?" + # ) + + # root.protocol("WM_DELETE_WINDOW", lambda: None) + # label = tk.Label(root, text=DISCLAIMER, wraplength=275) + # label.pack() + # yes_button = tk.Button(root, text="Yes", command=lambda: close_widget(disclaimer_window)) + # yes_button.pack(side=tk.LEFT, padx=50, pady=10) + # no_button = tk.Button(root, text="No", command=lambda: close_widget(root)) + # no_button.pack(side=tk.RIGHT, padx=50, pady=10) + + # return disclaimer_window + + root = tk.Tk() + root.title("Disclaimer") + style = ttk.Style() + style.configure("Toolbutton.TButton", padding=6, font=("Helvetica", 10)) + window_width, window_height = 500, 250 + screen_width = root.winfo_screenwidth() + screen_height = root.winfo_screenheight() + x_position = (screen_width - window_width) // 2 + y_position = (screen_height - window_height) // 2 + + root.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}") + + DISCLAIMER = ( + "The extension manager will download and install certain third-party software and/or " + "open-source software (collectively, 'Third-Party Software'). Such Third-Party " + "Software is subject to separate terms and conditions and not the terms of your " + "Ansys software license agreement. Ansys does not warrant or support such " + "Third-Party Software. Do you still wish to proceed?" + ) + + root.protocol("WM_DELETE_WINDOW", lambda: None) + label = tk.Label(root, text=DISCLAIMER, wraplength=275) + label.pack() + yes_button = tk.Button(root, text="Yes", command=lambda: root.destroy()) + yes_button.pack(side=tk.LEFT, padx=50, pady=10) + no_button = tk.Button(root, text="No", command=lambda: close_widget(root)) + no_button.pack(side=tk.RIGHT, padx=50, pady=10) + + disclaimer_window = create_disclaimer_window(root) + disclaimer_window.geometry("300x170+{}+{}".format(x_position + 110, y_position + 45)) + + ############ response = disclaimer() if not response: exit(1) From 689e1089ebe8f43c8ce1d42f8f8311d18bc60c10 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 6 Nov 2024 11:19:22 +0100 Subject: [PATCH 02/15] WIP --- .../Resources/pyaedt_installer_from_aedt.py | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index 739eafb5cd0..14995a52062 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -223,62 +223,62 @@ def install_pyaedt(): args.edt_root, args.python_version.replace(".", "_") ) - ########### - import tkinter as tk - from tkinter import ttk - - # def create_disclaimer_window(root: tk.Tk): - # """Notify users about extra packages.""" - # DISCLAIMER = ( - # "The extension manager will download and install certain third-party software and/or " - # "open-source software (collectively, 'Third-Party Software'). Such Third-Party " - # "Software is subject to separate terms and conditions and not the terms of your " - # "Ansys software license agreement. Ansys does not warrant or support such " - # "Third-Party Software. Do you still wish to proceed?" - # ) - - # root.protocol("WM_DELETE_WINDOW", lambda: None) - # label = tk.Label(root, text=DISCLAIMER, wraplength=275) - # label.pack() - # yes_button = tk.Button(root, text="Yes", command=lambda: close_widget(disclaimer_window)) - # yes_button.pack(side=tk.LEFT, padx=50, pady=10) - # no_button = tk.Button(root, text="No", command=lambda: close_widget(root)) - # no_button.pack(side=tk.RIGHT, padx=50, pady=10) - - # return disclaimer_window - - root = tk.Tk() - root.title("Disclaimer") - style = ttk.Style() - style.configure("Toolbutton.TButton", padding=6, font=("Helvetica", 10)) - window_width, window_height = 500, 250 - screen_width = root.winfo_screenwidth() - screen_height = root.winfo_screenheight() - x_position = (screen_width - window_width) // 2 - y_position = (screen_height - window_height) // 2 - - root.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}") - - DISCLAIMER = ( - "The extension manager will download and install certain third-party software and/or " - "open-source software (collectively, 'Third-Party Software'). Such Third-Party " - "Software is subject to separate terms and conditions and not the terms of your " - "Ansys software license agreement. Ansys does not warrant or support such " - "Third-Party Software. Do you still wish to proceed?" - ) - - root.protocol("WM_DELETE_WINDOW", lambda: None) - label = tk.Label(root, text=DISCLAIMER, wraplength=275) - label.pack() - yes_button = tk.Button(root, text="Yes", command=lambda: root.destroy()) - yes_button.pack(side=tk.LEFT, padx=50, pady=10) - no_button = tk.Button(root, text="No", command=lambda: close_widget(root)) - no_button.pack(side=tk.RIGHT, padx=50, pady=10) - - disclaimer_window = create_disclaimer_window(root) - disclaimer_window.geometry("300x170+{}+{}".format(x_position + 110, y_position + 45)) - - ############ + # ########### + # import tkinter as tk + # from tkinter import ttk + + # # def create_disclaimer_window(root: tk.Tk): + # # """Notify users about extra packages.""" + # # DISCLAIMER = ( + # # "The extension manager will download and install certain third-party software and/or " + # # "open-source software (collectively, 'Third-Party Software'). Such Third-Party " + # # "Software is subject to separate terms and conditions and not the terms of your " + # # "Ansys software license agreement. Ansys does not warrant or support such " + # # "Third-Party Software. Do you still wish to proceed?" + # # ) + + # # root.protocol("WM_DELETE_WINDOW", lambda: None) + # # label = tk.Label(root, text=DISCLAIMER, wraplength=275) + # # label.pack() + # # yes_button = tk.Button(root, text="Yes", command=lambda: close_widget(disclaimer_window)) + # # yes_button.pack(side=tk.LEFT, padx=50, pady=10) + # # no_button = tk.Button(root, text="No", command=lambda: close_widget(root)) + # # no_button.pack(side=tk.RIGHT, padx=50, pady=10) + + # # return disclaimer_window + + # root = tk.Tk() + # root.title("Disclaimer") + # style = ttk.Style() + # style.configure("Toolbutton.TButton", padding=6, font=("Helvetica", 10)) + # window_width, window_height = 500, 250 + # screen_width = root.winfo_screenwidth() + # screen_height = root.winfo_screenheight() + # x_position = (screen_width - window_width) // 2 + # y_position = (screen_height - window_height) // 2 + + # root.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}") + + # DISCLAIMER = ( + # "The extension manager will download and install certain third-party software and/or " + # "open-source software (collectively, 'Third-Party Software'). Such Third-Party " + # "Software is subject to separate terms and conditions and not the terms of your " + # "Ansys software license agreement. Ansys does not warrant or support such " + # "Third-Party Software. Do you still wish to proceed?" + # ) + + # root.protocol("WM_DELETE_WINDOW", lambda: None) + # label = tk.Label(root, text=DISCLAIMER, wraplength=275) + # label.pack() + # yes_button = tk.Button(root, text="Yes", command=lambda: root.destroy()) + # yes_button.pack(side=tk.LEFT, padx=50, pady=10) + # no_button = tk.Button(root, text="No", command=lambda: close_widget(root)) + # no_button.pack(side=tk.RIGHT, padx=50, pady=10) + + # disclaimer_window = create_disclaimer_window(root) + # disclaimer_window.geometry("300x170+{}+{}".format(x_position + 110, y_position + 45)) + + # ############ response = disclaimer() if not response: exit(1) From 094bffa0087b84640cff31e6ce457e5dfc088d63 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 6 Nov 2024 11:30:28 +0100 Subject: [PATCH 03/15] WIP --- doc/source/Resources/pyaedt_installer_from_aedt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index 14995a52062..3b911e23bf1 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -89,7 +89,7 @@ def run_pyinstaller_from_c_python(oDesktop): # if is_windows: import subprocess - process = subprocess.Popen(" ".join(command)) + process = subprocess.Popen(command) process.wait() return_code = process.returncode err_msg = "There was an error while installing PyAEDT." From f4d4807766e2a9bd621e1e71a102bdf8e3f767e2 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 6 Nov 2024 11:32:06 +0100 Subject: [PATCH 04/15] WIP --- doc/source/Resources/pyaedt_installer_from_aedt.py | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index 3b911e23bf1..a2a73c4ca1a 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -89,6 +89,7 @@ def run_pyinstaller_from_c_python(oDesktop): # if is_windows: import subprocess + oDesktop.AddMessage("", "", 0, " ".join(command)) process = subprocess.Popen(command) process.wait() return_code = process.returncode From 41821d279291018e6fda614ec7c05061eba20be5 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 6 Nov 2024 11:35:21 +0100 Subject: [PATCH 05/15] WIP --- doc/source/Resources/pyaedt_installer_from_aedt.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index a2a73c4ca1a..51b029fe817 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -26,12 +26,14 @@ import os import platform import shutil +import subprocessdotnet as subprocess import sys is_iron_python = platform.python_implementation().lower() == "ironpython" is_linux = os.name == "posix" is_windows = not is_linux + VENV_DIR_PREFIX = ".pyaedt_env" @@ -87,7 +89,7 @@ def run_pyinstaller_from_c_python(oDesktop): oDesktop.AddMessage("", "", 0, "Installing PyAEDT.") # if is_windows: - import subprocess + oDesktop.AddMessage("", "", 0, " ".join(command)) process = subprocess.Popen(command) From e905405f0d83498a39f1251da6a81394d3f3583b Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 6 Nov 2024 11:38:08 +0100 Subject: [PATCH 06/15] WIP --- doc/source/Resources/pyaedt_installer_from_aedt.py | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index 51b029fe817..404084367aa 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -94,6 +94,7 @@ def run_pyinstaller_from_c_python(oDesktop): oDesktop.AddMessage("", "", 0, " ".join(command)) process = subprocess.Popen(command) process.wait() + oDesktop.AddMessage("", "", 0, "CALLED") return_code = process.returncode err_msg = "There was an error while installing PyAEDT." # else: From 211ca2e8eb8a5a46e2ceab13bfce9ace69ee60df Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 6 Nov 2024 11:40:02 +0100 Subject: [PATCH 07/15] WIP --- doc/source/Resources/pyaedt_installer_from_aedt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index 404084367aa..b5522aa940f 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -77,7 +77,7 @@ def run_pyinstaller_from_c_python(oDesktop): # Launch this script again from the CPython interpreter. This calls the ``install_pyaedt()`` method, # which creates a virtual environment and installs PyAEDT and its dependencies - command = ['"{}"'.format(python_exe), '"{}"'.format(os.path.normpath(__file__)), "--version=" + version] + command = [python_exe, os.path.normpath(__file__), "--version=" + version] if is_student_version(oDesktop): command.append("--student") From f8ddb68498b61d58e0c9b0ddb68a2e55bc538fda Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 6 Nov 2024 11:47:00 +0100 Subject: [PATCH 08/15] WIP --- doc/source/Resources/pyaedt_installer_from_aedt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index b5522aa940f..fd34f61d23b 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -26,7 +26,7 @@ import os import platform import shutil -import subprocessdotnet as subprocess +import subprocess import sys is_iron_python = platform.python_implementation().lower() == "ironpython" From fad1c353d77a0604ab734ba98a6cf66afc8900d9 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Wed, 6 Nov 2024 11:55:12 +0100 Subject: [PATCH 09/15] WIP --- doc/source/Resources/pyaedt_installer_from_aedt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index fd34f61d23b..b5522aa940f 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -26,7 +26,7 @@ import os import platform import shutil -import subprocess +import subprocessdotnet as subprocess import sys is_iron_python = platform.python_implementation().lower() == "ironpython" From 55f4312600d0784087f2caf9bee7f07b8f970204 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Thu, 7 Nov 2024 18:30:51 +0100 Subject: [PATCH 10/15] FIX: Pyaedt installer in Linux --- .../Resources/pyaedt_installer_from_aedt.py | 227 +++++++----------- .../workflows/customize_automation_tab.py | 4 +- 2 files changed, 88 insertions(+), 143 deletions(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index b5522aa940f..14ebf02b0c5 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -26,31 +26,27 @@ import os import platform import shutil -import subprocessdotnet as subprocess import sys +try: + import subprocess +except ImportError: + import subprocessdotnet as subprocess + is_iron_python = platform.python_implementation().lower() == "ironpython" is_linux = os.name == "posix" is_windows = not is_linux VENV_DIR_PREFIX = ".pyaedt_env" - - -def disclaimer(): - """Notify users about extra packages.""" - DISCLAIMER = ( - "This script will download and install certain third-party software and/or " - "open-source software (collectively, 'Third-Party Software'). Such Third-Party " - "Software is subject to separate terms and conditions and not the terms of your " - "Ansys software license agreement. Ansys does not warrant or support such " - "Third-Party Software." - ) - print(DISCLAIMER) - - response = input("Do you want to proceed ? (y/n)").strip().lower() - return response == "y" - +DISCLAIMER = ( + "This script will download and install certain third-party software and/or " + "open-source software (collectively, 'Third-Party Software'). Such Third-Party " + "Software is subject to separate terms and conditions and not the terms of your " + "Ansys software license agreement. Ansys does not warrant or support such " + "Third-Party Software.\n" + "Do you want to proceed ?" +) def run_pyinstaller_from_c_python(oDesktop): # Iron Python script to create the virtual environment and install PyAEDT @@ -88,21 +84,11 @@ def run_pyinstaller_from_c_python(oDesktop): command.extend(['--wheel="{}"'.format(wheelpyaedt)]) oDesktop.AddMessage("", "", 0, "Installing PyAEDT.") - # if is_windows: - + return_code = subprocess.call(command) - oDesktop.AddMessage("", "", 0, " ".join(command)) - process = subprocess.Popen(command) - process.wait() - oDesktop.AddMessage("", "", 0, "CALLED") - return_code = process.returncode err_msg = "There was an error while installing PyAEDT." - # else: - # 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 is_linux: + err_msg += " Refer to the Terminal window where AEDT was launched from." if str(return_code) != "0": oDesktop.AddMessage("", "", 2, err_msg) return @@ -152,7 +138,8 @@ def run_pyinstaller_from_c_python(oDesktop): command = r'"{}" "{}"'.format(python_exe, python_script) oDesktop.AddMessage("", "", 0, "Configuring PyAEDT panels in automation tab.") - ret_code = os.system(command) + # ret_code = os.system(command) + ret_code = subprocess.call([python_exe, python_script]) if ret_code != 0: oDesktop.AddMessage("", "", 2, "Error occurred configuring the PyAEDT panels.") return @@ -227,72 +214,12 @@ def install_pyaedt(): args.edt_root, args.python_version.replace(".", "_") ) - # ########### - # import tkinter as tk - # from tkinter import ttk - - # # def create_disclaimer_window(root: tk.Tk): - # # """Notify users about extra packages.""" - # # DISCLAIMER = ( - # # "The extension manager will download and install certain third-party software and/or " - # # "open-source software (collectively, 'Third-Party Software'). Such Third-Party " - # # "Software is subject to separate terms and conditions and not the terms of your " - # # "Ansys software license agreement. Ansys does not warrant or support such " - # # "Third-Party Software. Do you still wish to proceed?" - # # ) - - # # root.protocol("WM_DELETE_WINDOW", lambda: None) - # # label = tk.Label(root, text=DISCLAIMER, wraplength=275) - # # label.pack() - # # yes_button = tk.Button(root, text="Yes", command=lambda: close_widget(disclaimer_window)) - # # yes_button.pack(side=tk.LEFT, padx=50, pady=10) - # # no_button = tk.Button(root, text="No", command=lambda: close_widget(root)) - # # no_button.pack(side=tk.RIGHT, padx=50, pady=10) - - # # return disclaimer_window - - # root = tk.Tk() - # root.title("Disclaimer") - # style = ttk.Style() - # style.configure("Toolbutton.TButton", padding=6, font=("Helvetica", 10)) - # window_width, window_height = 500, 250 - # screen_width = root.winfo_screenwidth() - # screen_height = root.winfo_screenheight() - # x_position = (screen_width - window_width) // 2 - # y_position = (screen_height - window_height) // 2 - - # root.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}") - - # DISCLAIMER = ( - # "The extension manager will download and install certain third-party software and/or " - # "open-source software (collectively, 'Third-Party Software'). Such Third-Party " - # "Software is subject to separate terms and conditions and not the terms of your " - # "Ansys software license agreement. Ansys does not warrant or support such " - # "Third-Party Software. Do you still wish to proceed?" - # ) - - # root.protocol("WM_DELETE_WINDOW", lambda: None) - # label = tk.Label(root, text=DISCLAIMER, wraplength=275) - # label.pack() - # yes_button = tk.Button(root, text="Yes", command=lambda: root.destroy()) - # yes_button.pack(side=tk.LEFT, padx=50, pady=10) - # no_button = tk.Button(root, text="No", command=lambda: close_widget(root)) - # no_button.pack(side=tk.RIGHT, padx=50, pady=10) - - # disclaimer_window = create_disclaimer_window(root) - # disclaimer_window.geometry("300x170+{}+{}".format(x_position + 110, y_position + 45)) - - # ############ - response = disclaimer() - if not response: - exit(1) - if not os.path.exists(venv_dir): if args.version == "231": - run_command('"{}" -m venv "{}" --system-site-packages'.format(sys.executable, venv_dir)) + subprocess.call([sys.executable, "-m", "venv", venv_dir, "--system-site-packages"]) else: - run_command('"{}" -m venv "{}"'.format(sys.executable, venv_dir)) + subprocess.call([sys.executable, "-m", "venv", venv_dir]) if args.wheel and os.path.exists(args.wheel): wheel_pyaedt = args.wheel @@ -311,33 +238,35 @@ def install_pyaedt(): # Extracted folder. unzipped_path = wheel_pyaedt if args.version <= "231": - run_command( - '"{}" install --no-cache-dir --no-index --find-links={} pyaedt[all,dotnet]'.format( - pip_exe, unzipped_path - ) ) + subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[all,dotnet]"]) else: - run_command( - '"{}" install --no-cache-dir --no-index --find-links={} pyaedt[installer]'.format( - pip_exe, unzipped_path - ) - ) + subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[installer]"]) else: - run_command('"{}" -m pip install --upgrade pip'.format(python_exe)) - run_command('"{}" --default-timeout=1000 install wheel'.format(pip_exe)) + subprocess.call([python_exe, "-m", "pip", "install", "--upgrade", "pip"]) + # run_command('"{}" -m pip install --upgrade pip'.format(python_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "wheel"]) + # run_command('"{}" --default-timeout=1000 install wheel'.format(pip_exe)) if args.version <= "231": - run_command('"{}" --default-timeout=1000 install pyaedt[all]=="0.9.0"'.format(pip_exe)) - run_command('"{}" --default-timeout=1000 install jupyterlab'.format(pip_exe)) - run_command('"{}" --default-timeout=1000 install ipython -U'.format(pip_exe)) - run_command('"{}" --default-timeout=1000 install ipyvtklink'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[all]=='0.9.0'"]) + # run_command('"{}" --default-timeout=1000 install pyaedt[all]=="0.9.0"'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "jupyterlab"]) + # run_command('"{}" --default-timeout=1000 install jupyterlab'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipython", "-U"]) + # run_command('"{}" --default-timeout=1000 install ipython -U'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipyvtklink"]) + # run_command('"{}" --default-timeout=1000 install ipyvtklink'.format(pip_exe)) else: - run_command('"{}" --default-timeout=1000 install pyaedt[installer]'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[installer]"]) + # run_command('"{}" --default-timeout=1000 install pyaedt[installer]'.format(pip_exe)) if args.version == "231": - run_command('"{}" uninstall -y pywin32'.format(pip_exe)) + subprocess.call([pip_exe, "uninstall", "-y", "pywin32"]) + # run_command('"{}" uninstall -y pywin32'.format(pip_exe)) else: - run_command('"{}" uninstall --yes pyaedt'.format(pip_exe)) + subprocess.call([pip_exe, "uninstall", "-y", "pyaedt"]) + # run_command('"{}" uninstall --yes pyaedt'.format(pip_exe)) if args.wheel and os.path.exists(args.wheel): wheel_pyaedt = args.wheel @@ -352,25 +281,32 @@ def install_pyaedt(): # Extract all contents to a directory. (You can specify a different extraction path if needed.) zip_ref.extractall(unzipped_path) if args.version <= "231": - run_command( - '"{}" install --no-cache-dir --no-index --find-links={} pyaedt[all]=="0.9.0"'.format( - pip_exe, unzipped_path - ) - ) + subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[all]=='0.9.0'"]) + # run_command( + # '"{}" install --no-cache-dir --no-index --find-links={} pyaedt[all]=="0.9.0"'.format( + # pip_exe, unzipped_path + # ) + # ) else: - run_command( - '"{}" install --no-cache-dir --no-index --find-links={} pyaedt[installer]'.format( - pip_exe, unzipped_path - ) - ) + subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[installer]"]) + # run_command( + # '"{}" install --no-cache-dir --no-index --find-links={} pyaedt[installer]'.format( + # pip_exe, unzipped_path + # ) + # ) else: if args.version <= "231": - run_command('"{}" --default-timeout=1000 install pyaedt[all]=="0.9.0"'.format(pip_exe)) - run_command('"{}" --default-timeout=1000 install jupyterlab'.format(pip_exe)) - run_command('"{}" --default-timeout=1000 install ipython -U'.format(pip_exe)) - run_command('"{}" --default-timeout=1000 install ipyvtklink'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[all]=='0.9.0'"]) + # run_command('"{}" --default-timeout=1000 install pyaedt[all]=="0.9.0"'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "jupyterlab"]) + # run_command('"{}" --default-timeout=1000 install jupyterlab'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipython", "-U"]) + # run_command('"{}" --default-timeout=1000 install ipython -U'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipyvtklink"]) + # run_command('"{}" --default-timeout=1000 install ipyvtklink'.format(pip_exe)) else: - run_command('"{}" --default-timeout=1000 install pyaedt[installer]'.format(pip_exe)) + subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[installer]"]) + # run_command('"{}" --default-timeout=1000 install pyaedt[installer]'.format(pip_exe)) sys.exit(0) @@ -382,24 +318,33 @@ def is_student_version(oDesktop): return False -def run_command(command): - if is_windows: - command = '"{}"'.format(command) - ret_code = os.system(command) - return ret_code - +def validate_disclaimer(): + """Display dialog box and evaluate the response to the disclaimer.""" + from System.Windows.Forms import MessageBox + from System.Windows.Forms import MessageBoxButtons + from System.Windows.Forms import DialogResult + + response = MessageBox.Show(DISCLAIMER, "Disclaimer", MessageBoxButtons.YesNo) + return response == DialogResult.Yes if __name__ == "__main__": if is_iron_python: - # Check if wheelhouse defined. Wheelhouse is created for Windows only. - wheelpyaedt = [] - # Retrieve the script arguments - script_args = ScriptArgument.split() - if len(script_args) == 1: - wheelpyaedt = script_args[0] - if not os.path.exists(wheelpyaedt): - wheelpyaedt = [] - run_pyinstaller_from_c_python(oDesktop) + if "GetIsNonGraphical" in oDesktop.__dir__() and oDesktop.GetIsNonGraphical(): + print("When using IronPython, this script is expected to be run in graphical mode.") + sys.exit(1) + if validate_disclaimer(): + oDesktop.AddMessage("", "", 0, "Disclaimer accepted.") + # Check if wheelhouse defined. Wheelhouse is created for Windows only. + wheelpyaedt = [] + # Retrieve the script arguments + script_args = ScriptArgument.split() + if len(script_args) == 1: + wheelpyaedt = script_args[0] + if not os.path.exists(wheelpyaedt): + wheelpyaedt = [] + run_pyinstaller_from_c_python(oDesktop) + else: + oDesktop.AddMessage("", "", 1, "Disclaimer refused, installation canceled.") else: install_pyaedt() diff --git a/src/ansys/aedt/core/workflows/customize_automation_tab.py b/src/ansys/aedt/core/workflows/customize_automation_tab.py index 4a0736ce80a..dfe0ebca6ca 100644 --- a/src/ansys/aedt/core/workflows/customize_automation_tab.py +++ b/src/ansys/aedt/core/workflows/customize_automation_tab.py @@ -90,7 +90,7 @@ def add_automation_tab( else: try: tree = ET.parse(tab_config_file_path) # nosec - except ParseError as e: # pragma: no cover + except ParseError: # pragma: no cover warnings.warn("Unable to parse %s\nError received = %s" % (tab_config_file_path, str(e))) return root = tree.getroot() @@ -169,7 +169,7 @@ def remove_xml_tab(toolkit_dir, name, panel="Panel_PyAEDT_Extensions"): return True try: tree = ET.parse(tab_config_file_path) # nosec - except ParseError as e: # pragma: no cover + except ParseError: # pragma: no cover warnings.warn("Unable to parse %s\nError received = %s" % (tab_config_file_path, str(e))) return root = tree.getroot() From 2f28f674bc9ac5152325864a663fb0f7b76b84e6 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Fri, 8 Nov 2024 09:03:36 +0100 Subject: [PATCH 11/15] REFACTOR: Clean up commented commands --- .../Resources/pyaedt_installer_from_aedt.py | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index 14ebf02b0c5..87c87a7d92a 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -244,29 +244,20 @@ def install_pyaedt(): else: subprocess.call([python_exe, "-m", "pip", "install", "--upgrade", "pip"]) - # run_command('"{}" -m pip install --upgrade pip'.format(python_exe)) subprocess.call([pip_exe, "--default-timeout=1000", "install", "wheel"]) - # run_command('"{}" --default-timeout=1000 install wheel'.format(pip_exe)) if args.version <= "231": subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[all]=='0.9.0'"]) - # run_command('"{}" --default-timeout=1000 install pyaedt[all]=="0.9.0"'.format(pip_exe)) subprocess.call([pip_exe, "--default-timeout=1000", "install", "jupyterlab"]) - # run_command('"{}" --default-timeout=1000 install jupyterlab'.format(pip_exe)) subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipython", "-U"]) - # run_command('"{}" --default-timeout=1000 install ipython -U'.format(pip_exe)) subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipyvtklink"]) - # run_command('"{}" --default-timeout=1000 install ipyvtklink'.format(pip_exe)) else: subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[installer]"]) - # run_command('"{}" --default-timeout=1000 install pyaedt[installer]'.format(pip_exe)) if args.version == "231": subprocess.call([pip_exe, "uninstall", "-y", "pywin32"]) - # run_command('"{}" uninstall -y pywin32'.format(pip_exe)) else: subprocess.call([pip_exe, "uninstall", "-y", "pyaedt"]) - # run_command('"{}" uninstall --yes pyaedt'.format(pip_exe)) if args.wheel and os.path.exists(args.wheel): wheel_pyaedt = args.wheel @@ -282,31 +273,16 @@ def install_pyaedt(): zip_ref.extractall(unzipped_path) if args.version <= "231": subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[all]=='0.9.0'"]) - # run_command( - # '"{}" install --no-cache-dir --no-index --find-links={} pyaedt[all]=="0.9.0"'.format( - # pip_exe, unzipped_path - # ) - # ) else: subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[installer]"]) - # run_command( - # '"{}" install --no-cache-dir --no-index --find-links={} pyaedt[installer]'.format( - # pip_exe, unzipped_path - # ) - # ) else: if args.version <= "231": subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[all]=='0.9.0'"]) - # run_command('"{}" --default-timeout=1000 install pyaedt[all]=="0.9.0"'.format(pip_exe)) subprocess.call([pip_exe, "--default-timeout=1000", "install", "jupyterlab"]) - # run_command('"{}" --default-timeout=1000 install jupyterlab'.format(pip_exe)) subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipython", "-U"]) - # run_command('"{}" --default-timeout=1000 install ipython -U'.format(pip_exe)) subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipyvtklink"]) - # run_command('"{}" --default-timeout=1000 install ipyvtklink'.format(pip_exe)) else: subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[installer]"]) - # run_command('"{}" --default-timeout=1000 install pyaedt[installer]'.format(pip_exe)) sys.exit(0) From a47df8cd8c3805649781c5e2e0e08727a94aab54 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Fri, 8 Nov 2024 09:44:26 +0100 Subject: [PATCH 12/15] REFACTOR: Remove unwanted changes --- src/ansys/aedt/core/workflows/customize_automation_tab.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/aedt/core/workflows/customize_automation_tab.py b/src/ansys/aedt/core/workflows/customize_automation_tab.py index dfe0ebca6ca..4a0736ce80a 100644 --- a/src/ansys/aedt/core/workflows/customize_automation_tab.py +++ b/src/ansys/aedt/core/workflows/customize_automation_tab.py @@ -90,7 +90,7 @@ def add_automation_tab( else: try: tree = ET.parse(tab_config_file_path) # nosec - except ParseError: # pragma: no cover + except ParseError as e: # pragma: no cover warnings.warn("Unable to parse %s\nError received = %s" % (tab_config_file_path, str(e))) return root = tree.getroot() @@ -169,7 +169,7 @@ def remove_xml_tab(toolkit_dir, name, panel="Panel_PyAEDT_Extensions"): return True try: tree = ET.parse(tab_config_file_path) # nosec - except ParseError: # pragma: no cover + except ParseError as e: # pragma: no cover warnings.warn("Unable to parse %s\nError received = %s" % (tab_config_file_path, str(e))) return root = tree.getroot() From 9864c38fd29c406c88cc7d6efd6bf86ed1da7787 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Fri, 8 Nov 2024 09:45:15 +0100 Subject: [PATCH 13/15] REFACTOR: Remove comments --- doc/source/Resources/pyaedt_installer_from_aedt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index 87c87a7d92a..894d7f0dd2a 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -138,7 +138,6 @@ def run_pyinstaller_from_c_python(oDesktop): command = r'"{}" "{}"'.format(python_exe, python_script) oDesktop.AddMessage("", "", 0, "Configuring PyAEDT panels in automation tab.") - # ret_code = os.system(command) ret_code = subprocess.call([python_exe, python_script]) if ret_code != 0: oDesktop.AddMessage("", "", 2, "Error occurred configuring the PyAEDT panels.") From a28a626c3ea745346e7706dc509231be65963edc Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Fri, 8 Nov 2024 09:48:55 +0100 Subject: [PATCH 14/15] REFACTOR: Format file --- .../Resources/pyaedt_installer_from_aedt.py | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/doc/source/Resources/pyaedt_installer_from_aedt.py b/doc/source/Resources/pyaedt_installer_from_aedt.py index 894d7f0dd2a..f92cffe78a6 100644 --- a/doc/source/Resources/pyaedt_installer_from_aedt.py +++ b/doc/source/Resources/pyaedt_installer_from_aedt.py @@ -48,6 +48,7 @@ "Do you want to proceed ?" ) + def run_pyinstaller_from_c_python(oDesktop): # Iron Python script to create the virtual environment and install PyAEDT # Get AEDT information @@ -237,9 +238,27 @@ def install_pyaedt(): # Extracted folder. unzipped_path = wheel_pyaedt if args.version <= "231": - subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[all,dotnet]"]) + subprocess.call( + [ + pip_exe, + "install", + "--no-cache-dir", + "--no-index", + "--find-links={}".format(unzipped_path), + "pyaedt[all,dotnet]", + ] + ) else: - subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[installer]"]) + subprocess.call( + [ + pip_exe, + "install", + "--no-cache-dir", + "--no-index", + "--find-links={}".format(unzipped_path), + "pyaedt[installer]", + ] + ) else: subprocess.call([python_exe, "-m", "pip", "install", "--upgrade", "pip"]) @@ -271,9 +290,27 @@ def install_pyaedt(): # Extract all contents to a directory. (You can specify a different extraction path if needed.) zip_ref.extractall(unzipped_path) if args.version <= "231": - subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[all]=='0.9.0'"]) + subprocess.call( + [ + pip_exe, + "install", + "--no-cache-dir", + "--no-index", + "--find-links={}".format(unzipped_path), + "pyaedt[all]=='0.9.0'", + ] + ) else: - subprocess.call([pip_exe, "install", "--no-cache-dir", "--no-index", "--find-links={}".format(unzipped_path), "pyaedt[installer]"]) + subprocess.call( + [ + pip_exe, + "install", + "--no-cache-dir", + "--no-index", + "--find-links={}".format(unzipped_path), + "pyaedt[installer]", + ] + ) else: if args.version <= "231": subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[all]=='0.9.0'"]) @@ -295,13 +332,14 @@ def is_student_version(oDesktop): def validate_disclaimer(): """Display dialog box and evaluate the response to the disclaimer.""" + from System.Windows.Forms import DialogResult from System.Windows.Forms import MessageBox from System.Windows.Forms import MessageBoxButtons - from System.Windows.Forms import DialogResult - + response = MessageBox.Show(DISCLAIMER, "Disclaimer", MessageBoxButtons.YesNo) return response == DialogResult.Yes + if __name__ == "__main__": if is_iron_python: From 60e86d58ca7f569cceee86bd8cc389200423690d Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Fri, 8 Nov 2024 11:43:45 +0100 Subject: [PATCH 15/15] REFACTOR: Extension manager disclaimer --- .../workflows/installer/extension_manager.py | 33 -------- .../core/workflows/templates/pyaedt_utils.py | 16 ++++ .../templates/run_extension_manager.py_build | 82 ++++++++++--------- 3 files changed, 59 insertions(+), 72 deletions(-) diff --git a/src/ansys/aedt/core/workflows/installer/extension_manager.py b/src/ansys/aedt/core/workflows/installer/extension_manager.py index b57565df6e9..1c2265549a5 100644 --- a/src/ansys/aedt/core/workflows/installer/extension_manager.py +++ b/src/ansys/aedt/core/workflows/installer/extension_manager.py @@ -313,36 +313,6 @@ def button_is_clicked( desktop.release_desktop(False, False) -def close_widget(widget): - """Close specific widget.""" - widget.destroy() - - -def create_disclaimer_window(root: tk.Tk): - """Notify users about extra packages.""" - DISCLAIMER = ( - "The extension manager will download and install certain third-party software and/or " - "open-source software (collectively, 'Third-Party Software'). Such Third-Party " - "Software is subject to separate terms and conditions and not the terms of your " - "Ansys software license agreement. Ansys does not warrant or support such " - "Third-Party Software. Do you still wish to proceed?" - ) - - disclaimer_window = tk.Toplevel(root) - disclaimer_window.title("Disclaimer") - disclaimer_window.grab_set() - disclaimer_window.protocol("WM_DELETE_WINDOW", lambda: None) - disclaimer_window.transient(root) - label = tk.Label(disclaimer_window, text=DISCLAIMER, wraplength=275) - label.pack() - yes_button = tk.Button(disclaimer_window, text="Yes", command=lambda: close_widget(disclaimer_window)) - yes_button.pack(side=tk.LEFT, padx=50, pady=10) - no_button = tk.Button(disclaimer_window, text="No", command=lambda: close_widget(root)) - no_button.pack(side=tk.RIGHT, padx=50, pady=10) - - return disclaimer_window - - root = tk.Tk() root.title("Extension Manager") @@ -385,9 +355,6 @@ def create_disclaimer_window(root: tk.Tk): root.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}") -disclaimer_window = create_disclaimer_window(root) -disclaimer_window.geometry("300x170+{}+{}".format(x_position + 110, y_position + 45)) - # Create buttons in a 4x4 grid, centered for i, level in enumerate(toolkit_levels): row_num = i // 4 diff --git a/src/ansys/aedt/core/workflows/templates/pyaedt_utils.py b/src/ansys/aedt/core/workflows/templates/pyaedt_utils.py index 2c91258a451..e155ed40765 100644 --- a/src/ansys/aedt/core/workflows/templates/pyaedt_utils.py +++ b/src/ansys/aedt/core/workflows/templates/pyaedt_utils.py @@ -31,6 +31,7 @@ import string import sys +from System.Windows.Forms import DialogResult from System.Windows.Forms import MessageBox from System.Windows.Forms import MessageBoxButtons from System.Windows.Forms import MessageBoxIcon @@ -147,3 +148,18 @@ def generate_unique_name(root_name, suffix="", n=6): if suffix: unique_name += suffix return unique_name + + +def validate_disclaimer(): + """Display dialog box and evaluate the response to the disclaimer.""" + DISCLAIMER = ( + "This script will download and install certain third-party software and/or " + "open-source software (collectively, 'Third-Party Software'). Such Third-Party " + "Software is subject to separate terms and conditions and not the terms of your " + "Ansys software license agreement. Ansys does not warrant or support such " + "Third-Party Software.\n" + "Do you want to proceed ?" + ) + + response = MessageBox.Show(DISCLAIMER, "Disclaimer", MessageBoxButtons.YesNo) + return response == DialogResult.Yes diff --git a/src/ansys/aedt/core/workflows/templates/run_extension_manager.py_build b/src/ansys/aedt/core/workflows/templates/run_extension_manager.py_build index 38811b98fcd..8ec46c8c71f 100644 --- a/src/ansys/aedt/core/workflows/templates/run_extension_manager.py_build +++ b/src/ansys/aedt/core/workflows/templates/run_extension_manager.py_build @@ -44,45 +44,49 @@ import pyaedt_utils def main(): - try: - # Get AEDT version - version_short = oDesktop.GetVersion()[2:6].replace(".", "") - # Launch extension manager - python_exe = r"##PYTHON_EXE##" % version - # Extensions directory - current_dir = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) - pyaedt_extensions_dir = os.path.normpath(os.path.join(current_dir, r"##TOOLKIT_REL_LIB_DIR##")) - pyaedt_script = os.path.join(pyaedt_extensions_dir, "extension_manager.py") - # Check if CPython interpreter and AEDT release match - python_exe = pyaedt_utils.sanitize_interpreter_path(python_exe, version_short) - # Check python executable - python_exe_flag = pyaedt_utils.check_file(python_exe, oDesktop) - if not python_exe_flag: - return - # Check script file - pyaedt_script_flag = pyaedt_utils.check_file(pyaedt_script, oDesktop) - if not pyaedt_script_flag: - return - # Add environment variables - pyaedt_utils.environment_variables(oDesktop) - # Open extension manager - if is_linux: - pyaedt_utils.set_ansys_em_environment(oDesktop) - command = [ - python_exe, - pyaedt_script, - ] - my_env = os.environ.copy() - subprocess.Popen(command, env=my_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) - else: - command = [ - '"{}"'.format(python_exe), - '"{}"'.format(pyaedt_script), - ] - my_env = os.environ.copy() - subprocess.Popen(" ".join(command), env=my_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) - except Exception as e: - pyaedt_utils.show_error(str(e), oDesktop) + if pyaedt_utils.validate_disclaimer(): + oDesktop.AddMessage("", "", 0, "Disclaimer accepted.") + try: + # Get AEDT version + version_short = oDesktop.GetVersion()[2:6].replace(".", "") + # Launch extension manager + python_exe = r"C:\Users\smorais\AppData\Roaming\.pyaedt_env\3_10\Scripts\python.exe" + # Extensions directory + current_dir = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) + pyaedt_extensions_dir = os.path.normpath(os.path.join(current_dir, r"Lib")) + pyaedt_script = os.path.join(pyaedt_extensions_dir, "extension_manager.py") + # Check if CPython interpreter and AEDT release match + python_exe = pyaedt_utils.sanitize_interpreter_path(python_exe, version_short) + # Check python executable + python_exe_flag = pyaedt_utils.check_file(python_exe, oDesktop) + if not python_exe_flag: + return + # Check script file + pyaedt_script_flag = pyaedt_utils.check_file(pyaedt_script, oDesktop) + if not pyaedt_script_flag: + return + # Add environment variables + pyaedt_utils.environment_variables(oDesktop) + # Open extension manager + if is_linux: + pyaedt_utils.set_ansys_em_environment(oDesktop) + command = [ + python_exe, + pyaedt_script, + ] + my_env = os.environ.copy() + subprocess.Popen(command, env=my_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) + else: + command = [ + '"{}"'.format(python_exe), + '"{}"'.format(pyaedt_script), + ] + my_env = os.environ.copy() + subprocess.Popen(" ".join(command), env=my_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) + except Exception as e: + pyaedt_utils.show_error(str(e), oDesktop) + else: + oDesktop.AddMessage("", "", 1, "Disclaimer refused.") if __name__ == "__main__":