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

REFACTOR: Issue launch toolkit from aedt #4652

Merged
merged 15 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 8 additions & 6 deletions doc/source/Resources/PyAEDTInstallerFromDesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def run_pyinstaller_from_c_python(oDesktop):
oDesktop.GetVersion()[:6], oDesktop.GetPersonalLibDirectory()))

command = r'"{}" "{}"'.format(python_exe, python_script)
oDesktop.AddMessage("", "", 0, command)
oDesktop.AddMessage("", "", 0, "Configuring PyAEDT Tabs.")
ret_code = os.system(command)
if ret_code != 0:
oDesktop.AddMessage("", "", 2, "Error configuring the configuration Tab.")
Expand All @@ -97,9 +97,11 @@ def run_pyinstaller_from_c_python(oDesktop):
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."
from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon
oDesktop.AddMessage("", "", 0, msg)
MessageBox.Show(msg, 'Info', MessageBoxButtons.OK, MessageBoxIcon.Information)

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)


def parse_arguments_for_pyaedt_installer(args=None):
Expand Down Expand Up @@ -175,9 +177,9 @@ def install_pyaedt():
else:
run_command('"{}" -m pip install --upgrade pip'.format(python_exe))
run_command('"{}" --default-timeout=1000 install wheel'.format(pip_exe))
run_command('"{}" --default-timeout=1000 install pyaedt[all]'.format(pip_exe))
# run_command(
# '"{}" --default-timeout=1000 install git+https://github.com/ansys/pyaedt.git@main'.format(pip_exe))
# '"{}" --default-timeout=1000 install git+https://github.com/ansys/pyaedt.git@fix/main'.format(pip_exe))
run_command('"{}" --default-timeout=1000 install pyaedt[all]'.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))
Expand Down
1 change: 1 addition & 0 deletions pyaedt/workflows/customize_automation_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def add_script_to_menu(
build_file_data = build_file_data.replace("##IPYTHON_EXE##", ipython_executable)
build_file_data = build_file_data.replace("##PYTHON_EXE##", executable_version_agnostic)
build_file_data = build_file_data.replace("##JUPYTER_EXE##", jupyter_executable)
build_file_data = build_file_data.replace("##TOOLKIT_NAME##", name)
if dest_script_path:
build_file_data = build_file_data.replace("##PYTHON_SCRIPT##", dest_script_path)

Expand Down
2 changes: 1 addition & 1 deletion pyaedt/workflows/hfss3dlayout/export_to_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def callback():
suffixes = {"Export to HFSS": "HFSS", "Export to Q3D": "Q3D", "Export to Maxwell 3D": "M3D", "Export to Icepak": "IPK"}

if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ:
port = os.environ["PYAEDT_SCRIPT_PORT"]
port = int(os.environ["PYAEDT_SCRIPT_PORT"])
version = os.environ["PYAEDT_SCRIPT_VERSION"]
else:
port = 0
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/workflows/installer/create_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pyaedt.generic.pdf import AnsysReport

if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ:
port = os.environ["PYAEDT_SCRIPT_PORT"]
port = int(os.environ["PYAEDT_SCRIPT_PORT"])
version = os.environ["PYAEDT_SCRIPT_VERSION"]
else:
port = 0
Expand Down
4 changes: 3 additions & 1 deletion pyaedt/workflows/installer/toolkit_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from pyaedt.workflows.customize_automation_tab import add_script_to_menu
from pyaedt.workflows.customize_automation_tab import available_toolkits
from pyaedt.workflows.customize_automation_tab import remove_script_from_menu
import pyaedt.workflows.templates

env_vars = ["PYAEDT_SCRIPT_VERSION", "PYAEDT_SCRIPT_PORT", "PYAEDT_STUDENT_VERSION"]
if all(var in os.environ for var in env_vars):
Expand Down Expand Up @@ -278,7 +279,8 @@ def button_is_clicked(
else:
pyaedt_venv_dir = os.path.join(os.environ["HOME"], "pyaedt_env_ide", "v{}".format(version))
executable_interpreter = os.path.join(pyaedt_venv_dir, "bin", "python")

if not file:
file = os.path.join(os.path.dirname(pyaedt.workflows.templates.__file__), "toolkit_template.py")
if os.path.isfile(executable_interpreter):
add_script_to_menu(
name=name,
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/workflows/project/create_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pyaedt.generic.pdf import AnsysReport

if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ:
port = os.environ["PYAEDT_SCRIPT_PORT"]
port = int(os.environ["PYAEDT_SCRIPT_PORT"])
version = os.environ["PYAEDT_SCRIPT_VERSION"]
else:
port = 0
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/workflows/project/import_nastran.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def browseFiles():

nas_input = browseFiles()
if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ:
port = os.environ["PYAEDT_SCRIPT_PORT"]
port = int(os.environ["PYAEDT_SCRIPT_PORT"])
version = os.environ["PYAEDT_SCRIPT_VERSION"]
else:
port = 0
Expand Down
43 changes: 24 additions & 19 deletions pyaedt/workflows/templates/Run_PyAEDT_Toolkit_Script.py_build
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ script_name = os.path.splitext(os.path.basename(__file__))[0]

if is_linux:
import subprocessdotnet as subprocess
else:
import subprocess


def main():
try:
Expand All @@ -41,6 +38,7 @@ def main():
os.environ["PYAEDT_SCRIPT_VERSION"] = version
if version > "2022.2":
os.environ["PYAEDT_SCRIPT_PORT"] = str(oDesktop.GetGrpcServerPort())

if is_linux:
edt_root = os.path.normpath(oDesktop.GetExeDir())
os.environ["ANSYSEM_ROOT{}".format(version)] = edt_root
Expand All @@ -53,24 +51,31 @@ def main():
]
os.environ["LD_LIBRARY_PATH"] = ":".join(ld_library_path_dirs_to_add) + ":" + os.getenv(
"LD_LIBRARY_PATH", "")
command = [
python_exe,
pyaedt_script,
str(oDesktop.GetProcessID()),
str(oDesktop.GetVersion()[:6]),
]
my_env = os.environ.copy()

if version > "2023.1":
os.environ["TCL_LIBRARY"] = os.path.join("{}/commonfiles/CPython/3_10/linx64/Release/python/lib".format(edt_root), "tcl8.5")
os.environ["TK_LIBRARY"] = os.path.join("{}/commonfiles/CPython/3_10/linx64/Release/python/lib".format(edt_root), "tk8.5")
os.environ["TKPATH"] = os.path.join("{}/commonfiles/CPython/3_10/linx64/Release/python/lib".format(edt_root), "tk8.5")
else:
os.environ["TCL_LIBRARY"] = os.path.join("{}/commonfiles/CPython/3_7/linx64/Release/python/lib".format(edt_root), "tcl8.5")
os.environ["TK_LIBRARY"] = os.path.join("{}/commonfiles/CPython/3_7/linx64/Release/python/lib".format(edt_root), "tk8.5")
os.environ["TKPATH"] = os.path.join("{}/commonfiles/CPython/3_7/linx64/Release/python/lib".format(edt_root), "tk8.5")

my_env = dict(os.environ.copy())
command = [python_exe, pyaedt_script]
subprocess.Popen(command, env=my_env)
else:
CREATE_NO_WINDOW = 0x08000000
command = [
'"{}"'.format(python_exe),
'"{}"'.format(pyaedt_script),
str(oDesktop.GetProcessID()),
str(oDesktop.GetVersion()[:6]),
]
my_env = os.environ.copy()
subprocess.Popen(" ".join(command), env=my_env, creationflags=CREATE_NO_WINDOW)
toolkit_name = r"##TOOLKIT_NAME##"
runme = "run_pyaedt_toolkit_{0}.cmd".format(toolkit_name)
edt_temp = oDesktop.GetTempDirectory()
cmd = '"{0}"'.format(pyaedt_script)
target = os.path.join(edt_temp, runme)
my_env = dict(os.environ.copy())
with open(target, 'w') as cmdfile:
for env in my_env:
cmdfile.write('SET {0}={1}\n'.format(env, my_env[env]))
cmdfile.write('"{0}" {1}\n'.format(python_exe, cmd))
oDesktop.RunProgram(runme, edt_temp, edt_temp, "")
except Exception as e:
show_error(str(e))

Expand Down
46 changes: 46 additions & 0 deletions pyaedt/workflows/templates/toolkit_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2023 - 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.

# Toolkit template if the user does not pass any valid script in the toolkit manager

import os

import pyaedt
from pyaedt import get_pyaedt_app

if "PYAEDT_SCRIPT_PORT" in os.environ and "PYAEDT_SCRIPT_VERSION" in os.environ:
port = int(os.environ["PYAEDT_SCRIPT_PORT"])
version = os.environ["PYAEDT_SCRIPT_VERSION"]
else:
port = 0
version = "2024.1"

app = pyaedt.Desktop(new_desktop_session=False, specified_version=version, port=port)

active_project = app.odesktop.GetActiveProject()
active_design = active_project.GetActiveDesign()

aedtapp = get_pyaedt_app(design_name=active_design.GetName(), desktop=app)

# Your PyAEDT script

app.release_desktop(False, False)
Loading