Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Fix hardcoded APPDATA in extension manager #5300

Merged
merged 15 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/source/Getting_started/Installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ Finally, in the python console, run the following commands:
from ansys.aedt.core.workflows.installer.pyaedt_installer import add_pyaedt_to_aedt
add_pyaedt_to_aedt(“your_aedt_version", r“path_to_personalib")

You can also install the PyAEDT panels using the following steps, this is also useful if you have a centralized PyAEDT installation:

- Download the following file: :download:`PyAEDT panel Installer Python file <../Resources/toolkit_installer_from_aedt.py>`

- Define an environment variable called `PYAEDT_INTERPRETER` with the path of the python interpreter in which PyAEDT is installed.

- Open an Electronics Desktop Session and click on Tools->Run Script and execute the file. You do not need the previous step if
you pass as an argument the path of the python interpreter.


Linux support
~~~~~~~~~~~~~
Expand Down
107 changes: 107 additions & 0 deletions doc/source/Resources/toolkit_installer_from_aedt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import sys
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved

# This script installs PyAEDT tabs (PyAEDT Console, Jupyter, Run Script and Extension Manager)
# using a specific Python interpreter.
# It can be passed from an environment variable called "PYAEDT_INTERPRETER" or from the input argument.
# The environment variable has more priority.

is_linux = os.name == "posix"
is_windows = not is_linux

pyaedt_enviroment_variable = "PYAEDT_INTERPRETER"


def run_pyinstaller_from_c_python(oDesktop, pyaedt_interpreter):
# Iron Python script to create PyAEDT panels

# Get AEDT information
version = oDesktop.GetVersion()[2:6].replace(".", "")

# Add PyAEDT tabs in AEDT

# Create Toolkits in PersonalLib
import tempfile
python_script = os.path.join(tempfile.gettempdir(), "configure_pyaedt.py")
if os.path.isfile(python_script):
os.remove(python_script)
with open(python_script, "w") as f:
f.write("from ansys.aedt.core.workflows.installer.pyaedt_installer import add_pyaedt_to_aedt\n")
f.write(
'add_pyaedt_to_aedt(aedt_version="{}", personal_lib=r"{}")\n'.format(
oDesktop.GetVersion()[:6], oDesktop.GetPersonalLibDirectory()))

command = r'"{}" "{}"'.format(pyaedt_interpreter, python_script)
oDesktop.AddMessage("", "", 0, "Configuring PyAEDT panels in automation tab.")
ret_code = os.system(command)
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved
if ret_code != 0:
oDesktop.AddMessage("", "", 2, "Error occurred configuring the PyAEDT panels.")
return
# Refresh UI
oDesktop.CloseAllWindows()
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."

if "GetIsNonGraphical" in oDesktop.__dir__() and not oDesktop.GetIsNonGraphical():
from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon
oDesktop.AddMessage("", "", 0, msg)
MessageBox.Show(msg, 'Info', MessageBoxButtons.OK, MessageBoxIcon.Information)
oDesktop.AddMessage("", "", 0, "Create a project if the PyAEDT panel is not visible.")


def run_command(command):
if is_windows:
command = '"{}"'.format(command)
ret_code = os.system(command)
return ret_code
Samuelopez-ansys marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":

python_interpreter = os.getenv(pyaedt_enviroment_variable)
if python_interpreter and not os.path.exists(python_interpreter):
oDesktop.AddMessage("", "", 2, "Python environment does not exist.")
sys.exit()

# Check if interpreter path is defined.
# Retrieve the script arguments
script_args = ScriptArgument.split()
if len(script_args) == 1 and not python_interpreter:
python_interpreter = script_args[0]
if not os.path.exists(python_interpreter):
oDesktop.AddMessage("", "", 2, "Python environment does not exist.")
sys.exit()

if not python_interpreter:
oDesktop.AddMessage("", "", 2, "Invalid python environment.")
sys.exit()

run_pyinstaller_from_c_python(oDesktop, python_interpreter)
12 changes: 4 additions & 8 deletions src/ansys/aedt/core/workflows/installer/extension_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# SOFTWARE.

import os
import sys
import tkinter as tk
from tkinter import ttk

Expand Down Expand Up @@ -56,15 +57,11 @@
)
python_exe = os.path.join(venv_dir, "Scripts", "python.exe")
package_dir = os.path.join(venv_dir, "Lib", "site-packages")
pyaedt_venv_dir = os.path.join(
os.environ["APPDATA"], VENV_DIR_PREFIX, "{}".format(python_version.replace(".", "_"))
)

else:
venv_dir = os.path.join(os.environ["HOME"], VENV_DIR_PREFIX, "toolkits_{}".format(python_version.replace(".", "_")))
python_exe = os.path.join(venv_dir, "bin", "python")
package_dir = os.path.join(venv_dir, "lib", "site-packages")
pyaedt_venv_dir = os.path.join(os.environ["HOME"], VENV_DIR_PREFIX, "{}".format(python_version.replace(".", "_")))


def create_toolkit_page(frame, window_name, internal_toolkits):
Expand Down Expand Up @@ -286,10 +283,9 @@ def button_is_clicked(
else:
if install_action:
desktop.logger.info("Install {}".format(name))
if is_windows:
executable_interpreter = os.path.join(pyaedt_venv_dir, "Scripts", "python.exe")
else:
executable_interpreter = os.path.join(pyaedt_venv_dir, "bin", "python")

executable_interpreter = sys.executable

if not file:
file = os.path.join(
os.path.dirname(ansys.aedt.core.workflows.templates.__file__), "extension_template.py"
Expand Down
Loading