Skip to content

Commit

Permalink
FIX: Pyaedt installer in linux (#5392)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Lopez <[email protected]>
  • Loading branch information
SMoraisAnsys and Samuelopez-ansys authored Nov 8, 2024
1 parent 8e0bca8 commit 41c9e2d
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 151 deletions.
176 changes: 97 additions & 79 deletions doc/source/Resources/pyaedt_installer_from_aedt.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,25 @@
import shutil
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"
VENV_DIR_PREFIX = ".pyaedt_env"
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):
Expand Down Expand Up @@ -75,7 +74,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")
Expand All @@ -86,19 +85,11 @@ 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."
)
return_code = subprocess.call(command)

err_msg = "There was an error while installing PyAEDT."
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
Expand Down Expand Up @@ -148,7 +139,7 @@ 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.")
return
Expand Down Expand Up @@ -223,16 +214,12 @@ def install_pyaedt():
args.edt_root, args.python_version.replace(".", "_")
)

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
Expand All @@ -251,33 +238,44 @@ 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"])
subprocess.call([pip_exe, "--default-timeout=1000", "install", "wheel"])
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'"])
subprocess.call([pip_exe, "--default-timeout=1000", "install", "jupyterlab"])
subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipython", "-U"])
subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipyvtklink"])
else:
run_command('"{}" --default-timeout=1000 install pyaedt[installer]'.format(pip_exe))
subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[installer]"])

if args.version == "231":
run_command('"{}" uninstall -y pywin32'.format(pip_exe))
subprocess.call([pip_exe, "uninstall", "-y", "pywin32"])

else:
run_command('"{}" uninstall --yes pyaedt'.format(pip_exe))
subprocess.call([pip_exe, "uninstall", "-y", "pyaedt"])

if args.wheel and os.path.exists(args.wheel):
wheel_pyaedt = args.wheel
Expand All @@ -292,25 +290,35 @@ 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'",
]
)
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:
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'"])
subprocess.call([pip_exe, "--default-timeout=1000", "install", "jupyterlab"])
subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipython", "-U"])
subprocess.call([pip_exe, "--default-timeout=1000", "install", "ipyvtklink"])
else:
run_command('"{}" --default-timeout=1000 install pyaedt[installer]'.format(pip_exe))
subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[installer]"])
sys.exit(0)


Expand All @@ -322,24 +330,34 @@ 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 DialogResult
from System.Windows.Forms import MessageBox
from System.Windows.Forms import MessageBoxButtons

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()
33 changes: 0 additions & 33 deletions src/ansys/aedt/core/workflows/installer/extension_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,36 +318,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")

Expand Down Expand Up @@ -390,9 +360,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
Expand Down
16 changes: 16 additions & 0 deletions src/ansys/aedt/core/workflows/templates/pyaedt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading

0 comments on commit 41c9e2d

Please sign in to comment.