Skip to content

Commit 1df4c81

Browse files
committed
Merge branch 'main' into release/0.4
2 parents e1cd103 + 1799400 commit 1df4c81

File tree

6 files changed

+133
-1616
lines changed

6 files changed

+133
-1616
lines changed

.github/workflows/autoupdate_python_versions.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ jobs:
4848
branch: feat/update-python-version
4949
base: main
5050
delete-branch: true
51+
add-paths: src/ansys/tools/installer/constants.py

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ tests = [
4343
"pytest==8.3.5",
4444
"pytest-cov==6.1.1",
4545
"pytest-qt==4.4.0",
46-
"setuptools==80.3.1",
46+
"setuptools==80.7.1",
4747
]
4848
doc = [
4949
"Sphinx==8.1.3",
50-
"ansys-sphinx-theme==1.4.2",
50+
"ansys-sphinx-theme==1.4.4",
5151
"sphinx-copybutton==0.5.2",
5252
"sphinx_design==0.6.1",
53-
"sphinx_toolbox==3.9.0",
53+
"sphinx_toolbox==4.0.0",
5454
]
5555
freeze = [
5656
"pyinstaller==6.13.0",

src/ansys/tools/installer/common.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,65 @@ def get_pkg_versions(pkg_name):
127127
session.verify = True
128128

129129
return all_versions
130+
131+
132+
def get_targets(pkg_name, version, exclude_tests_and_docs=True):
133+
"""
134+
Get the available targets for a package version.
135+
136+
Parameters
137+
----------
138+
pkg_name : str
139+
Name of the package for which to fetch the available targets.
140+
version : str
141+
Version of the package.
142+
exclude_tests_and_docs : bool, optional
143+
If True, exclude test and documentation targets from the list.
144+
Default is True.
145+
146+
Returns
147+
-------
148+
list
149+
A sorted list of available targets for the specified package version.
150+
The first element is an empty string, mimicking the behavior of
151+
no target.
152+
153+
Examples
154+
--------
155+
>>> get_targets("pyansys", "0.1.0")
156+
['target1', 'target2', ...]
157+
"""
158+
session = requests.Session()
159+
session.verify = False
160+
urls = [
161+
f"https://pypi.python.org/pypi/{pkg_name}/{version}/json",
162+
f"https://pypi.org/pypi/{pkg_name}/{version}/json",
163+
]
164+
all_targets = []
165+
166+
for url in urls:
167+
try:
168+
targets = json.loads(requests.get(url, verify=certifi.where()).content)[
169+
"info"
170+
]
171+
# Check if targets are available
172+
if targets.get("provides_extra"):
173+
all_targets = targets["provides_extra"]
174+
break
175+
except (requests.exceptions.SSLError, requests.exceptions.ConnectionError):
176+
LOG.warning(f"Cannot connect to {url}... No target listed.")
177+
178+
session.verify = True
179+
180+
# Ensure the first element is an empty string
181+
all_targets.insert(0, "")
182+
183+
# Exclude test and documentation targets if specified
184+
if exclude_tests_and_docs:
185+
all_targets = [
186+
target
187+
for target in all_targets
188+
if "tests" not in target.lower() and "doc" not in target.lower()
189+
]
190+
191+
return all_targets

src/ansys/tools/installer/installed_table.py

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from PySide6.QtGui import QStandardItem, QStandardItemModel
3333
from PySide6.QtWidgets import QComboBox
3434

35-
from ansys.tools.installer.common import get_pkg_versions
35+
from ansys.tools.installer.common import get_pkg_versions, get_targets
3636
from ansys.tools.installer.configure_json import ConfigureJson
3737
from ansys.tools.installer.constants import PYANSYS_LIBS, SELECT_VENV_MANAGE_TAB
3838
from ansys.tools.installer.find_python import (
@@ -300,23 +300,45 @@ def __init__(self, parent=None):
300300
hbox_install_pyansys = QtWidgets.QHBoxLayout()
301301
pyansys_pkg_manage_box_layout.addLayout(hbox_install_pyansys)
302302

303+
package_layout = QtWidgets.QVBoxLayout()
304+
package_label = QtWidgets.QLabel("Package")
303305
self.model = QStandardItemModel()
304306
self.packages_combo = QComboBox()
305307
self.packages_combo.setModel(self.model)
308+
package_layout.addWidget(package_label)
309+
package_layout.addWidget(self.packages_combo)
306310

311+
version_layout = QtWidgets.QVBoxLayout()
312+
version_label = QtWidgets.QLabel("Version")
307313
self.versions_combo = QComboBox()
314+
version_layout.addWidget(version_label)
315+
version_layout.addWidget(self.versions_combo)
316+
317+
target_layout = QtWidgets.QVBoxLayout()
318+
target_label = QtWidgets.QLabel("Target (optional)")
319+
self.version_target_combo = QComboBox()
320+
target_layout.addWidget(target_label)
321+
target_layout.addWidget(self.version_target_combo)
322+
323+
install_button_layout = QtWidgets.QVBoxLayout()
324+
install_button_label = QtWidgets.QLabel(" ")
308325
self.button_launch_cmd = QtWidgets.QPushButton("Install")
309-
self.button_launch_cmd.clicked.connect(self.install_pyansys_packages)
326+
install_button_layout.addWidget(install_button_label)
327+
install_button_layout.addWidget(self.button_launch_cmd)
310328

329+
self.button_launch_cmd.clicked.connect(self.install_pyansys_packages)
311330
for library in PYANSYS_LIBS:
312331
self.model.appendRow(QStandardItem(library))
313-
314332
self.packages_combo.currentIndexChanged.connect(self.update_package_combo)
333+
self.versions_combo.currentIndexChanged.connect(
334+
self.update_package_target_combo
335+
)
315336
self.update_package_combo(0)
316337

317-
hbox_install_pyansys.addWidget(self.packages_combo)
318-
hbox_install_pyansys.addWidget(self.versions_combo)
319-
hbox_install_pyansys.addWidget(self.button_launch_cmd)
338+
hbox_install_pyansys.addLayout(package_layout)
339+
hbox_install_pyansys.addLayout(version_layout)
340+
hbox_install_pyansys.addLayout(target_layout)
341+
hbox_install_pyansys.addLayout(install_button_layout)
320342
layout.addWidget(pyansys_pkg_manage_box)
321343

322344
# ensure the table is always in focus
@@ -391,8 +413,10 @@ def install_pyansys_packages(self):
391413
"""Install PyAnsys - chosen packages."""
392414
chosen_pkg = self.packages_combo.currentText()
393415
chosen_ver = self.versions_combo.currentText()
416+
chosen_target = self.version_target_combo.currentText()
417+
fmt_target = "" if not chosen_target else f"[{chosen_target}]"
394418
pck_ver = (
395-
f"{PYANSYS_LIBS[chosen_pkg]}=={chosen_ver}"
419+
f"{PYANSYS_LIBS[chosen_pkg]}{fmt_target}=={chosen_ver}"
396420
if chosen_ver
397421
else f"{PYANSYS_LIBS[chosen_pkg]}"
398422
)
@@ -415,6 +439,24 @@ def update_package_combo(self, index):
415439
self.versions_combo.setModel(versions_model)
416440
self.versions_combo.setCurrentIndex(0)
417441

442+
def update_package_target_combo(self, index):
443+
"""Depending on the version chosen for a package, update the available list of targets."""
444+
package_name = PYANSYS_LIBS[self.packages_combo.currentText()]
445+
version = self.versions_combo.currentText()
446+
447+
# Clear the previous targets
448+
self.version_target_combo.clear()
449+
450+
# Get the available targets for the selected package version
451+
targets = get_targets(package_name, version)
452+
453+
# Populate the target combo box with the available targets
454+
for target in targets:
455+
self.version_target_combo.addItem(target)
456+
457+
# Set the first target as the current selection
458+
self.version_target_combo.setCurrentIndex(0)
459+
418460
def list_packages(self):
419461
"""List installed Python packages."""
420462
self.launch_cmd("uv pip list")

src/ansys/tools/installer/windows_functions.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,26 @@ def create_venv_windows(venv_dir: str, py_path: str):
4646
4747
"""
4848
user_profile = os.path.expanduser("~")
49-
scripts_path = os.path.join(py_path, "Scripts")
50-
new_path = f"{py_path};{scripts_path};%PATH%"
5149

5250
# Update the package managers
53-
subprocess.call(
54-
f'start /w /min cmd /K "set PATH={new_path} && python -m pip install --upgrade pip uv && exit"',
55-
shell=True,
56-
cwd=user_profile,
57-
)
58-
59-
# Create venv using uv
60-
subprocess.call(
61-
f'start /w /min cmd /K "set PATH={new_path} && python -m uv venv {venv_dir} && exit"',
62-
shell=True,
63-
cwd=user_profile,
64-
)
51+
try:
52+
# Update pip and uv using the py_path
53+
LOG.debug("Updating package managers - pip & uv...")
54+
subprocess.call(
55+
f'start /w /min cmd /K ""{py_path}\\python.exe" -m pip install --upgrade pip uv && exit"',
56+
shell=True,
57+
cwd=user_profile,
58+
)
59+
60+
# Create venv using uv
61+
LOG.debug("Creating virtual environment using uv...")
62+
subprocess.call(
63+
f'start /w /min cmd /K ""{py_path}\\python.exe" -m uv venv {venv_dir} && exit"',
64+
shell=True,
65+
cwd=user_profile,
66+
)
67+
except Exception as e:
68+
LOG.debug(f"Error creating virtual environment: {e}")
6569

6670

6771
def create_venv_windows_conda(venv_dir: str, py_path: str):

0 commit comments

Comments
 (0)