Skip to content

Commit

Permalink
Merge branch 'main' into fix/issue_5485
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys authored Dec 20, 2024
2 parents 64bcdc8 + 5ea9436 commit 12f3443
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 120 deletions.
143 changes: 71 additions & 72 deletions doc/source/Resources/pyaedt_installer_from_aedt.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def run_pyinstaller_from_c_python(oDesktop):
if is_student_version(oDesktop):
command.append("--student")
if is_linux:
command.extend(['--edt_root="{}"'.format(edt_root), '--python_version="{}"'.format(python_version)])
command.extend([r'--edt_root={}'.format(edt_root), '--python_version="{}"'.format(python_version)])

if wheelpyaedt:
command.extend(['--wheel="{}"'.format(wheelpyaedt)])
command.extend([r'--wheel={}'.format(wheelpyaedt)])

oDesktop.AddMessage("", "", 0, "Installing PyAEDT.")
return_code = subprocess.call(command)
Expand Down Expand Up @@ -179,8 +179,26 @@ def parse_arguments_for_pyaedt_installer(args=None):
parser.error("No arguments given!")
return args

def unzip_if_zip(path):
"""Unzip path if it is a ZIP file."""
import zipfile

# Extracted folder
unzipped_path = path
if path.suffix == '.zip':
unzipped_path = path.parent / path.stem
if unzipped_path.exists():
shutil.rmtree(unzipped_path, ignore_errors=True)
with zipfile.ZipFile(path, "r") as zip_ref:
# Extract all contents to a directory. (You can specify a different extraction path if needed.)
zip_ref.extractall(unzipped_path)
return unzipped_path


def install_pyaedt():
"""Install PyAEDT in CPython."""
from pathlib import Path

# This is called when run from CPython
args = parse_arguments_for_pyaedt_installer()

Expand All @@ -189,136 +207,117 @@ def install_pyaedt():
python_version = "3_7"

if is_windows:
venv_dir = os.path.join(os.environ["APPDATA"], VENV_DIR_PREFIX, python_version)
python_exe = os.path.join(venv_dir, "Scripts", "python.exe")
pip_exe = os.path.join(venv_dir, "Scripts", "pip.exe")
venv_dir = Path(os.environ["APPDATA"], VENV_DIR_PREFIX, python_version)
python_exe = venv_dir / "Scripts" / "python.exe"
pip_exe = venv_dir / "Scripts" / "pip.exe"
else:
venv_dir = os.path.join(os.environ["HOME"], VENV_DIR_PREFIX, python_version)
python_exe = os.path.join(venv_dir, "bin", "python")
pip_exe = os.path.join(venv_dir, "bin", "pip")
venv_dir = Path(os.environ["HOME"], VENV_DIR_PREFIX, python_version)
python_exe = venv_dir / "bin" / "python"
pip_exe = venv_dir / "bin" / "pip"
os.environ["ANSYSEM_ROOT{}".format(args.version)] = args.edt_root
ld_library_path_dirs_to_add = [
"{}/commonfiles/CPython/{}/linx64/Release/python/lib".format(
r"{}/commonfiles/CPython/{}/linx64/Release/python/lib".format(
args.edt_root, args.python_version.replace(".", "_")
),
"{}/common/mono/Linux64/lib64".format(args.edt_root),
"{}".format(args.edt_root),
r"{}/common/mono/Linux64/lib64".format(args.edt_root),
r"{}".format(args.edt_root),
]
if args.version < "232":
ld_library_path_dirs_to_add.append("{}/Delcross".format(args.edt_root))
ld_library_path_dirs_to_add.append(r"{}/Delcross".format(args.edt_root))
os.environ["LD_LIBRARY_PATH"] = ":".join(ld_library_path_dirs_to_add) + ":" + os.getenv("LD_LIBRARY_PATH", "")
os.environ["TK_LIBRARY"] = "{}/commonfiles/CPython/{}/linx64/Release/python/lib/tk8.5".format(
os.environ["TK_LIBRARY"] = r"{}/commonfiles/CPython/{}/linx64/Release/python/lib/tk8.5".format(
args.edt_root, args.python_version.replace(".", "_")
)
os.environ["TCL_LIBRARY"] = "{}/commonfiles/CPython/{}/linx64/Release/python/lib/tcl8.5".format(
os.environ["TCL_LIBRARY"] = r"{}/commonfiles/CPython/{}/linx64/Release/python/lib/tcl8.5".format(
args.edt_root, args.python_version.replace(".", "_")
)

if not os.path.exists(venv_dir):

if args.version == "231":
subprocess.call([sys.executable, "-m", "venv", venv_dir, "--system-site-packages"])
if not venv_dir.exists():
print("Creating the virtual environment in {}".format(venv_dir))
if args.version <= "231":
subprocess.call([sys.executable, "-m", "venv", str(venv_dir), "--system-site-packages"])
else:
subprocess.call([sys.executable, "-m", "venv", venv_dir])
subprocess.call([sys.executable, "-m", "venv", str(venv_dir)])

if args.wheel and os.path.exists(args.wheel):
wheel_pyaedt = args.wheel
if wheel_pyaedt.endswith(".zip"):
import zipfile

unzipped_path = os.path.join(
os.path.dirname(wheel_pyaedt), os.path.splitext(os.path.basename(wheel_pyaedt))[0]
)
if os.path.exists(unzipped_path):
shutil.rmtree(unzipped_path, ignore_errors=True)
with zipfile.ZipFile(wheel_pyaedt, "r") as zip_ref:
# Extract all contents to a directory. (You can specify a different extraction path if needed.)
zip_ref.extractall(unzipped_path)
else:
# Extracted folder.
unzipped_path = wheel_pyaedt
if args.wheel and Path(args.wheel).exists():
print("Installing PyAEDT using provided wheels argument")
unzipped_path = unzip_if_zip(Path(args.wheel))
if args.version <= "231":
subprocess.call(
[
pip_exe,
str(pip_exe),
"install",
"--no-cache-dir",
"--no-index",
"--find-links={}".format(unzipped_path),
"pyaedt[all,dotnet]",
r"--find-links={}".format(str(unzipped_path)),
"pyaedt[all,dotnet]=='0.9.0'",
]
)
else:
subprocess.call(
[
pip_exe,
str(pip_exe),
"install",
"--no-cache-dir",
"--no-index",
"--find-links={}".format(unzipped_path),
r"--find-links={}".format(str(unzipped_path)),
"pyaedt[installer]",
]
)

else:
subprocess.call([python_exe, "-m", "pip", "install", "--upgrade", "pip"])
subprocess.call([pip_exe, "--default-timeout=1000", "install", "wheel"])
print("Installing PyAEDT using online sources")
subprocess.call([str(python_exe), "-m", "pip", "install", "--upgrade", "pip"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "wheel"])
if args.version <= "231":
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"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "pyaedt[all]=='0.9.0'"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "jupyterlab"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "ipython", "-U"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "ipyvtklink"])
else:
subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[installer]"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "pyaedt[installer]"])

if args.version == "231":
subprocess.call([pip_exe, "uninstall", "-y", "pywin32"])
if args.version <= "231":
subprocess.call([str(pip_exe), "uninstall", "-y", "pywin32"])

else:
subprocess.call([pip_exe, "uninstall", "-y", "pyaedt"])
print("Using existing virtual environment in {}".format(venv_dir))
subprocess.call([str(pip_exe), "uninstall", "-y", "pyaedt"])

if args.wheel and os.path.exists(args.wheel):
wheel_pyaedt = args.wheel
import zipfile

unzipped_path = os.path.join(
os.path.dirname(wheel_pyaedt), os.path.splitext(os.path.basename(wheel_pyaedt))[0]
)
if os.path.exists(unzipped_path):
shutil.rmtree(unzipped_path, ignore_errors=True)
with zipfile.ZipFile(wheel_pyaedt, "r") as zip_ref:
# Extract all contents to a directory. (You can specify a different extraction path if needed.)
zip_ref.extractall(unzipped_path)
if args.wheel and Path(args.wheel).exists():
print("Installing PyAEDT using provided wheels argument")
unzipped_path = unzip_if_zip(Path(args.wheel))
if args.version <= "231":
subprocess.call(
[
pip_exe,
str(pip_exe),
"install",
"--no-cache-dir",
"--no-index",
"--find-links={}".format(unzipped_path),
"pyaedt[all]=='0.9.0'",
r"--find-links={}".format(str(unzipped_path)),
"pyaedt[all,dotnet]=='0.9.0'",
]
)
else:
subprocess.call(
[
pip_exe,
str(pip_exe),
"install",
"--no-cache-dir",
"--no-index",
"--find-links={}".format(unzipped_path),
r"--find-links={}".format(str(unzipped_path)),
"pyaedt[installer]",
]
)
else:
print("Installing PyAEDT using online sources")
if args.version <= "231":
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"])
subprocess.call([str(pip_exe), "pip=1000", "install", "pyaedt[all]=='0.9.0'"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "jupyterlab"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "ipython", "-U"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "ipyvtklink"])
else:
subprocess.call([pip_exe, "--default-timeout=1000", "install", "pyaedt[installer]"])
subprocess.call([str(pip_exe), "--default-timeout=1000", "install", "pyaedt[installer]"])
sys.exit(0)


Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/application/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def boundaries(self) -> List[BoundaryObject]:
del self._boundaries[k]
for boundary, boundarytype in zip(current_boundaries, current_types):
if boundary in self._boundaries:
self._boundaries[boundary]._initialize_bynary_tree()
self._boundaries[boundary]._initialize_tree_node()
continue
if boundarytype == "MaxwellParameters":
maxwell_parameter_type = self.get_oo_property_value(self.odesign, f"Parameters\\{boundary}", "Type")
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/aedt/core/modules/boundary/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _get_args(self, props=None):
return arg

@pyaedt_function_handler()
def _initialize_bynary_tree(self):
def _initialize_tree_node(self):
if self._child_object:
BinaryTreeNode.__init__(self, self._name, self._child_object, False)
return True
Expand Down Expand Up @@ -222,7 +222,7 @@ def __init__(self, app, name, props=None, boundarytype=None, auto_update=True):
self.__props = BoundaryProps(self, props) if props else {}
self._type = boundarytype
self.auto_update = auto_update
self._initialize_bynary_tree()
self._initialize_tree_node()

@property
def _child_object(self):
Expand Down Expand Up @@ -542,7 +542,7 @@ def create(self):
else:
return False

return self._initialize_bynary_tree()
return self._initialize_tree_node()

@pyaedt_function_handler()
def update(self):
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/aedt/core/modules/boundary/hfss_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, app, component_name, props, component_type):
self._name = component_name
self.__props = BoundaryProps(self, props) if props else {}
self.auto_update = True
self._initialize_bynary_tree()
self._initialize_tree_node()

@property
def _child_object(self):
Expand Down Expand Up @@ -138,7 +138,7 @@ def create(self):
self._app.oradfield.AddAntennaOverlay(self._get_args())
elif self.type == "FieldSourceGroup":
self._app.oradfield.AddRadFieldSourceGroup(self._get_args())
return self._initialize_bynary_tree()
return self._initialize_tree_node()

@pyaedt_function_handler()
def update(self):
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/aedt/core/modules/boundary/layout_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self, app, component_type, component_name, props):
self.native_properties = self.__props["NativeComponentDefinitionProvider"]
self.auto_update = True

self._initialize_bynary_tree()
self._initialize_tree_node()

@property
def _child_object(self):
Expand Down Expand Up @@ -218,7 +218,7 @@ def create(self):
self.excitation_name = a[0].split(":")[0]
except (GrpcApiError, IndexError):
self.excitation_name = self._name
return self._initialize_bynary_tree()
return self._initialize_tree_node()

@pyaedt_function_handler()
def update(self):
Expand Down Expand Up @@ -295,7 +295,7 @@ def __init__(self, app, name, props=None, boundarytype="Port"):
self.__props = BoundaryProps(self, props)
self.type = boundarytype
self.auto_update = True
self._initialize_bynary_tree()
self._initialize_tree_node()

@property
def _child_object(self):
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/aedt/core/modules/boundary/maxwell_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, app, name, props=None, boundarytype=None):
self.auto_update = True
self.__reduced_matrices = None
self.matrix_assignment = None
self._initialize_bynary_tree()
self._initialize_tree_node()

@property
def reduced_matrices(self):
Expand Down Expand Up @@ -177,7 +177,7 @@ def create(self):
self._app.o_maxwell_parameters.AssignLayoutForce(self._get_args())
else:
return False
return self._initialize_bynary_tree()
return self._initialize_tree_node()

@pyaedt_function_handler()
def update(self):
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/aedt/core/modules/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(self, mesh, name, props, meshoptype):
self._type = meshoptype
self._name = name
self.auto_update = True
self._initialize_bynary_tree()
self._initialize_tree_node()

@property
def _child_object(self):
Expand Down Expand Up @@ -259,7 +259,7 @@ def create(self):
self._mesh.omeshmodule.AssignCylindricalGapOp(self._get_args())
else:
return False
return self._initialize_bynary_tree()
return self._initialize_tree_node()

@pyaedt_function_handler()
def update(self, key_name=None, value=None):
Expand Down Expand Up @@ -405,7 +405,7 @@ def delete(self):
return True

@pyaedt_function_handler()
def _initialize_bynary_tree(self):
def _initialize_tree_node(self):
if self._child_object:
BinaryTreeNode.__init__(self, self._name, self._child_object, False)
return True
Expand Down
Loading

0 comments on commit 12f3443

Please sign in to comment.