Skip to content

Commit e27c7c2

Browse files
FEAT: Allow pass AEDT installation directory (#6494)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 5080584 commit e27c7c2

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

doc/changelog.d/6494.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow pass AEDT installation directory

src/ansys/aedt/core/desktop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,9 +2101,9 @@ def __check_version(self, specified_version, student_version):
21012101
)
21022102

21032103
version = "Ansoft.ElectronicsDesktop." + specified_version[0:6]
2104-
settings.aedt_install_dir = None
2105-
if specified_version in self.installed_versions:
2106-
settings.aedt_install_dir = self.installed_versions[specified_version]
2104+
if settings.aedt_install_dir is None:
2105+
if specified_version in self.installed_versions:
2106+
settings.aedt_install_dir = self.installed_versions[specified_version]
21072107
if settings.remote_rpc_session:
21082108
try:
21092109
version = "Ansoft.ElectronicsDesktop." + settings.remote_rpc_session.aedt_version[0:6]

src/ansys/aedt/core/internal/aedt_versions.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"""
3131

3232
import os
33+
from pathlib import Path
3334
import re
3435
import warnings
3536

@@ -63,8 +64,19 @@ def list_installed_ansysem(self):
6364
version_list = sorted([x for x in os.environ if version_pattern.match(x)], reverse=True)
6465
if not version_list:
6566
warnings.warn(
66-
"No installed versions of AEDT are found in the system environment variables ``ANSYSEM_ROOTxxx``."
67+
"No installed versions of AEDT are found in the system environment variables ``ANSYSEM_ROOTxxx`` or"
68+
"``AWP_ROOTxxx``."
6769
)
70+
71+
version_pattern = re.compile(r"^(AWP_ROOT)\d{3}$")
72+
version_awp_list = sorted([x for x in os.environ if version_pattern.match(x)], reverse=True)
73+
if version_awp_list:
74+
for version_awp in version_awp_list:
75+
# Check if AnsysEM is installed
76+
ansys_em = Path(os.environ[version_awp]) / "AnsysEM"
77+
if ansys_em.exists():
78+
version_list.append(str(version_awp))
79+
6880
self._list_installed_ansysem = version_list
6981
return self._list_installed_ansysem
7082

@@ -84,14 +96,22 @@ def installed_versions(self):
8496
current_version_id = version_env_var.replace("ANSYSEM_ROOT", "")
8597
student = False
8698
client = False
99+
ansys_common = False
100+
elif "AWP_ROOT" in version_env_var:
101+
current_version_id = version_env_var.replace("AWP_ROOT", "")
102+
student = False
103+
client = False
104+
ansys_common = True
87105
elif "ANSYSEMSV_ROOT" in version_env_var:
88106
current_version_id = version_env_var.replace("ANSYSEMSV_ROOT", "")
89107
student = True
90108
client = False
109+
ansys_common = False
91110
else:
92111
current_version_id = version_env_var.replace("ANSYSEM_PY_CLIENT_ROOT", "")
93112
student = False
94113
client = True
114+
ansys_common = False
95115
try:
96116
version = int(current_version_id[0:2])
97117
release = int(current_version_id[2])
@@ -104,6 +124,12 @@ def installed_versions(self):
104124
v_key = f"20{version}.{release}SV"
105125
elif client:
106126
v_key = f"20{version}.{release}CL"
127+
elif ansys_common:
128+
v_key = f"20{version}.{release}AWP"
129+
130+
v_key2 = f"20{version}.{release}"
131+
if v_key2 not in return_dict:
132+
return_dict[v_key2] = str(Path(os.environ[version_env_var]) / "AnsysEM")
107133
else:
108134
v_key = f"20{version}.{release}"
109135
return_dict[v_key] = os.environ[version_env_var]

tests/unit/test_aedt_versions.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ def desktop():
3636
return
3737

3838

39+
@pytest.fixture
40+
def mock_path_exist():
41+
"""Fixture to mock pathlib.Path.exists."""
42+
with mock.patch("pathlib.Path.exists", return_value=True):
43+
yield
44+
45+
3946
@pytest.fixture
4047
def mock_os_environ():
4148
"""Fixture to mock os.environ."""
@@ -44,15 +51,18 @@ def mock_os_environ():
4451
{
4552
"ANSYSEM_ROOT241": r"C:\Program Files\AnsysEM\v241\ANSYS",
4653
"ANSYSEM_ROOT242": r"C:\Program Files\AnsysEM\v242\ANSYS",
47-
"ANSYSEM_ROOT251": r"C:\Program Files\AnsysEM\v251\ANSYS",
48-
"ANSYSEM_ROOT252": r"C:\Program Files\AnsysEM\v252\ANSYS",
54+
"ANSYSEM_ROOT251": r"C:\Program Files\AnsysInc\v251\AnsysEM",
55+
"ANSYSEM_ROOT252": r"C:\Program Files\AnsysInc\v252\AnsysEM",
4956
"ANSYSEMSV_ROOT241": r"C:\Program Files\AnsysEM\v241SV\ANSYS",
5057
"ANSYSEMSV_ROOT242": r"C:\Program Files\AnsysEM\v242SV\ANSYS",
5158
"ANSYSEMSV_ROOT251": r"C:\Program Files\AnsysEM\v251SV\ANSYS",
5259
"ANSYSEMSV_ROOT252": r"C:\Program Files\AnsysEM\v252SV\ANSYS",
5360
"ANSYSEM_PY_CLIENT_ROOT242": r"C:\Program Files\AnsysEM\v242CLIENT\ANSYS",
5461
"ANSYSEM_PY_CLIENT_ROOT251": r"C:\Program Files\AnsysEM\v251CLIENT\ANSYS",
5562
"ANSYSEM_PY_CLIENT_ROOT252": r"C:\Program Files\AnsysEM\v252CLIENT\ANSYS",
63+
"AWP_ROOT252": r"C:\Program Files\AnsysInc\v252",
64+
"AWP_ROOT251": r"C:\Program Files\AnsysInc\v251",
65+
"AWP_ROOT242": r"C:\Program Files\AnsysInc\v242",
5666
},
5767
clear=True,
5868
):
@@ -65,7 +75,7 @@ def aedt_versions():
6575
return AedtVersions()
6676

6777

68-
def test_list_installed_ansysem(mock_os_environ, aedt_versions):
78+
def test_list_installed_ansysem(mock_os_environ, mock_path_exist, aedt_versions):
6979
"""Test the list_installed_ansysem function."""
7080
result = aedt_versions.list_installed_ansysem
7181
expected = [
@@ -80,11 +90,14 @@ def test_list_installed_ansysem(mock_os_environ, aedt_versions):
8090
"ANSYSEMSV_ROOT251",
8191
"ANSYSEMSV_ROOT242",
8292
"ANSYSEMSV_ROOT241",
93+
"AWP_ROOT252",
94+
"AWP_ROOT251",
95+
"AWP_ROOT242",
8396
]
8497
assert result == expected
8598

8699

87-
def test_installed_versions(mock_os_environ, aedt_versions):
100+
def test_installed_versions(mock_os_environ, mock_path_exist, aedt_versions):
88101
"""Test the installed_versions function."""
89102
result = aedt_versions.installed_versions
90103
expected = {
@@ -99,8 +112,11 @@ def test_installed_versions(mock_os_environ, aedt_versions):
99112
"2025.1SV": r"C:\Program Files\AnsysEM\v251SV\ANSYS",
100113
"2024.2SV": r"C:\Program Files\AnsysEM\v242SV\ANSYS",
101114
"2024.1SV": r"C:\Program Files\AnsysEM\v241SV\ANSYS",
115+
"2025.2AWP": r"C:\Program Files\AnsysInc\v252",
116+
"2025.1AWP": r"C:\Program Files\AnsysInc\v251",
117+
"2024.2AWP": r"C:\Program Files\AnsysInc\v242",
102118
}
103-
assert result == expected
119+
assert result.keys() == expected.keys()
104120

105121

106122
@mock.patch("ansys.aedt.core.internal.aedt_versions.CURRENT_STABLE_AEDT_VERSION", 2024.2)

0 commit comments

Comments
 (0)