Skip to content

FEAT: Install pyaedt via uv #6338

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions doc/changelog.d/6338.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Install pyaedt via uv
53 changes: 32 additions & 21 deletions doc/source/Resources/pyaedt_installer_from_aedt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ruff: noqa: F821
#
# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates.
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
Expand Down Expand Up @@ -224,10 +224,12 @@ def install_pyaedt():
venv_dir = Path(VENV_DIR, python_version)
python_exe = venv_dir / "Scripts" / "python.exe"
pip_exe = venv_dir / "Scripts" / "pip.exe"
uv_exe = venv_dir / "Scripts" / "uv.exe"
else:
venv_dir = Path(VENV_DIR, python_version)
python_exe = venv_dir / "bin" / "python"
pip_exe = venv_dir / "bin" / "pip"
uv_exe = venv_dir / "bin" / "uv"
os.environ["ANSYSEM_ROOT{}".format(args.version)] = args.edt_root
ld_library_path_dirs_to_add = [
r"{}/commonfiles/CPython/{}/linx64/Release/python/lib".format(
Expand All @@ -245,6 +247,11 @@ def install_pyaedt():
os.environ["TCL_LIBRARY"] = r"{}/commonfiles/CPython/{}/linx64/Release/python/lib/tcl8.5".format(
args.edt_root, args.python_version.replace(".", "_")
)
# Prepare environment for subprocess
env = os.environ.copy()
env["VIRTUAL_ENV"] = str(venv_dir)
env["PATH"] = str(venv_dir / "Scripts") + os.pathsep + env.get("PATH", "")
env["UV_HTTP_TIMEOUT"] = "1000" # Increase timeout for uv

if not venv_dir.exists():
print("Creating the virtual environment in {}".format(venv_dir))
Expand All @@ -253,12 +260,15 @@ def install_pyaedt():
else:
subprocess.run([sys.executable, "-m", "venv", str(venv_dir)], check=True) # nosec

# Install uv in the virtual environment
print("Installing uv in the virtual environment...")
subprocess.run([str(pip_exe), "install", "uv"], check=True) # nosec

if args.wheel and Path(args.wheel).exists():
print("Installing PyAEDT using provided wheels argument")
unzipped_path = unzip_if_zip(Path(args.wheel))
command = [
str(pip_exe),
"install",
str(uv_exe), "pip", "install",
"--no-cache-dir",
"--no-index",
r"--find-links={}".format(str(unzipped_path)),
Expand All @@ -269,30 +279,31 @@ def install_pyaedt():
command.append("pyaedt[all]")
subprocess.run(command, check=True) # nosec
else:
print("Installing PyAEDT using online sources")
subprocess.run([str(python_exe), "-m", "pip", "install", "--upgrade", "pip"], check=True) # nosec
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "wheel"], check=True) # nosec
print("Installing PyAEDT using online sources with uv...")
subprocess.run([str(uv_exe), "pip", "install", "--upgrade", "pip"], check=True, env=env) # nosec
subprocess.run([str(uv_exe), "pip", "install", "wheel"], check=True, env=env) # nosec
if args.version <= "231":
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "pyaedt[all]=='0.9.0'"], check=True) # nosec
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "jupyterlab"], check=True) # nosec
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "ipython", "-U"], check=True) # nosec
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "ipyvtklink"], check=True) # nosec
subprocess.run([str(uv_exe), "pip", "install", "pyaedt[all]=='0.9.0'"] , check=True, env=env) # nosec
subprocess.run([str(uv_exe), "pip", "install", "jupyterlab"], check=True, env=env) # nosec
subprocess.run([str(uv_exe), "pip", "install", "ipython", "-U"], check=True, env=env) # nosec
subprocess.run([str(uv_exe), "pip", "install", "ipyvtklink"], check=True, env=env) # nosec
else:
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "pyaedt[all]"], check=True) # nosec
subprocess.run([str(uv_exe), "pip", "install", "pyaedt[all]"], check=True, env=env) # nosec

if args.version <= "231":
subprocess.run([str(pip_exe), "uninstall", "-y", "pywin32"], check=True) # nosec
subprocess.run([str(uv_exe), "pip", "uninstall", "-y", "pywin32"], check=True) # nosec

else:
print("Using existing virtual environment in {}".format(venv_dir))
subprocess.call([str(pip_exe), "uninstall", "-y", "pyaedt"], check=True) # nosec
# Ensure uv is installed in the venv
subprocess.run([str(pip_exe), "install", "uv"], check=True) # nosec
subprocess.call([str(uv_exe), "pip", "uninstall", "-y", "pyaedt"], check=True) # nosec

if args.wheel and Path(args.wheel).exists():
print("Installing PyAEDT using provided wheels argument")
unzipped_path = unzip_if_zip(Path(args.wheel))
command = [
str(pip_exe),
"install",
str(uv_exe), "pip", "install",
"--no-cache-dir",
"--no-index",
r"--find-links={}".format(str(unzipped_path)),
Expand All @@ -303,14 +314,14 @@ def install_pyaedt():
command.append("pyaedt[all]")
subprocess.run(command, check=True) # nosec
else:
print("Installing PyAEDT using online sources")
print("Installing PyAEDT using online sources with uv...")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to define the env variable here too or possibly sooner in your script.

if args.version <= "231":
subprocess.run([str(pip_exe), "pip=1000", "install", "pyaedt[all]=='0.9.0'"], check=True) # nosec
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "jupyterlab"], check=True) # nosec
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "ipython", "-U"], check=True) # nosec
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "ipyvtklink"], check=True) # nosec
subprocess.run([str(uv_exe), "pip", "install", "pyaedt[all]=='0.9.0'"] , check=True, env=env) # nosec
subprocess.run([str(uv_exe), "pip", "install", "jupyterlab"], check=True, env=env) # nosec
subprocess.run([str(uv_exe), "pip", "install", "ipython", "-U"], check=True, env=env) # nosec
subprocess.run([str(uv_exe), "pip", "install", "ipyvtklink"], check=True, env=env) # nosec
else:
subprocess.run([str(pip_exe), "--default-timeout=1000", "install", "pyaedt[all]"], check=True) # nosec
subprocess.run([str(uv_exe), "pip", "install", "pyaedt[all]"], check=True, env=env) # nosec
sys.exit(0)


Expand Down
Loading