Skip to content

Commit 92bd3fb

Browse files
committed
improved finding ansys on linux
1 parent f382d3d commit 92bd3fb

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pyansys/launcher.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Module for launching MAPDL locally."""
2+
import pathlib
3+
from glob import glob
24
import time
35
import subprocess
46
import re
@@ -58,6 +60,20 @@ def find_ansys():
5860
if is_float(version_str):
5961
paths[int(version_str)] = path
6062

63+
# On Linux ansys is usually installed at the root directory at
64+
# /usr/ansys_inc
65+
# /ansys_inc
66+
if not paths and os.name == 'posix':
67+
for directory in ['/usr/ansys_inc/', '/ansys_inc/']:
68+
if os.path.isdir(directory):
69+
# construct ansys path
70+
for subdirectory in glob('%s*/' % directory):
71+
ver = os.path.basename(os.path.normpath('/usr/ansys_inc/v202/'))
72+
groups = re.findall(r'v\d\d\d', ver)
73+
if groups:
74+
ver = int(groups[0][1:])
75+
paths[ver] = os.path.join(subdirectory, 'ansys')
76+
6177
if not paths:
6278
return '', ''
6379

tests/test_launcher.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
pytestmark = pytest.mark.skip("Requires MAPDL")
3030

3131

32+
@pytest.mark.skipif(os.name != 'posix', reason="Requires Linux")
33+
@pytest.mark.skipif(not versions, reason="Requires ANSYS install")
34+
def test_find_ansys_linux():
35+
# assuming ansys is installed, should be able to find it on linux
36+
# without env var
37+
bin_file, ver = pyansys.launcher.find_ansys()
38+
assert os.path.isfile(bin_file)
39+
assert isinstance(ver, float)
40+
41+
3242
def test_invalid_mode():
3343
with pytest.raises(ValueError):
3444
exec_file = get_ansys_bin(valid_versions[0])

0 commit comments

Comments
 (0)