Skip to content

Commit

Permalink
Merge branch 'main' into feat/issue_5384
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed Nov 11, 2024
2 parents a077237 + c4a1475 commit 1dbffaf
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 230 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-unit-tests
file: ./coverage.xml
flags: unit
flags: linux_unit

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-system-solvers-tests-windows
file: ./coverage.xml
flags: system,solvers,windows
flags: windows_system_solvers

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -214,7 +214,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-system-solvers-tests-linux
file: ./coverage.xml
flags: system,solvers,linux
flags: linux_system_solvers

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -278,7 +278,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-system-general-tests-windows
file: ./coverage.xml
flags: system,general,windows
flags: windows_system_general

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -346,7 +346,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-system-general-tests
file: ./coverage.xml
flags: system,general,linux
flags: linux_system_general

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down
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()
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies = [
"pytomlpp; python_version < '3.12'",
"rpyc>=6.0.0,<6.1",
"pyyaml",
"defusedxml>=0.7,<8.0"
]

[project.optional-dependencies]
Expand All @@ -65,7 +66,7 @@ tests = [
"pyvista[io]>=0.38.0,<0.45",
# Never directly imported but required when loading ML related file see #4713
"scikit-learn>=1.0.0,<1.6",
"scikit-rf>=0.30.0,<1.4",
"scikit-rf>=0.30.0,<1.5",
"SRTM.py",
"utm",
]
Expand Down Expand Up @@ -99,7 +100,7 @@ all = [
"fast-simplification>=0.1.7",
# Never directly imported but required when loading ML related file see #4713
"scikit-learn>=1.0.0,<1.6",
"scikit-rf>=0.30.0,<1.4",
"scikit-rf>=0.30.0,<1.5",
"SRTM.py",
"utm",
]
Expand All @@ -112,7 +113,7 @@ installer = [
"pyvista[io]>=0.38.0,<0.45",
# Never directly imported but required when loading ML related file see #4713
"scikit-learn>=1.0.0,<1.6",
"scikit-rf>=0.30.0,<1.4",
"scikit-rf>=0.30.0,<1.5",
"SRTM.py",
"utm",
"jupyterlab>=3.6.0,<4.4",
Expand Down
Loading

0 comments on commit 1dbffaf

Please sign in to comment.