Skip to content

Commit

Permalink
Fix installation script (#3506)
Browse files Browse the repository at this point in the history
* Fix 2022R2 installation script issue

* Improved installation file to support

* Update antenna toolkit
Add toolkit message

---------

Co-authored-by: maxcapodi78 <Shark78>
  • Loading branch information
Samuelopez-ansys authored Sep 1, 2023
1 parent ab04ab3 commit 5334f5c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 81 deletions.
58 changes: 40 additions & 18 deletions doc/source/Resources/PyAEDTInstallerFromDesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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)


Expand Down
3 changes: 3 additions & 0 deletions pyaedt/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions pyaedt/misc/Run_PyAEDT_Toolkit_Script.py_build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
136 changes: 75 additions & 61 deletions pyaedt/misc/aedtlib_personalib_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pyaedt/misc/install_extra_toolkits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5334f5c

Please sign in to comment.