Skip to content

Commit 6bddcba

Browse files
authored
Fix parsing of ansys_path version in start_local_server (#1388)
* Stop throwing silently when DPF version of ansys_path is not understood, and parse folder name when dpf_standalone Signed-off-by: paul.profizi <[email protected]> * Fix case of ansys_path being a Path and not a str Signed-off-by: paul.profizi <[email protected]> * Add DPFServerPathFormatError Signed-off-by: paul.profizi <[email protected]> * Move the ansys_path format checks to core\misc.py\get_ansys_path Signed-off-by: paul.profizi <[email protected]> * Fix regex patterns compilation Signed-off-by: paul.profizi <[email protected]> * Update BaseServer.info Signed-off-by: paul.profizi <[email protected]> * Update test_launcher.py tests Signed-off-by: paul.profizi <[email protected]> * Revert "Update test_launcher.py tests" This reverts commit cf360fb. * Revert "Add DPFServerPathFormatError" This reverts commit 0961981. * Revert back to only testing minimal version if ansys_path ends in vXYZ Signed-off-by: paul.profizi <[email protected]> --------- Signed-off-by: paul.profizi <[email protected]>
1 parent ff6d0f3 commit 6bddcba

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/ansys/dpf/core/misc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import platform
33
import glob
44
import os
5+
import re
56

67
import packaging.version
78
import pkg_resources
89
import importlib
910
from pkgutil import iter_modules
11+
from ansys.dpf.core import errors
1012
from ansys.dpf.gate._version import __ansys_version__
1113
from ansys.dpf.gate import load_api
1214

@@ -97,6 +99,20 @@ def get_ansys_path(ansys_path=None):
9799
'- when starting the server with "start_local_server(ansys_path=*/vXXX)"\n'
98100
'- or by setting it by default with the environment variable "ANSYS_DPF_PATH"'
99101
)
102+
# parse the version to an int and check for supported
103+
ansys_folder_name = str(ansys_path).split(os.sep)[-1]
104+
reobj_vXYZ = re.compile(
105+
"^v[0123456789]{3}$"
106+
)
107+
if reobj_vXYZ.match(ansys_folder_name):
108+
# vXYZ Unified Install folder
109+
ver = int(str(ansys_path)[-3:])
110+
else:
111+
ver = 222
112+
if ver < 211:
113+
raise errors.InvalidANSYSVersionError(f"Ansys v{ver} does not support DPF")
114+
if ver == 211 and is_ubuntu():
115+
raise OSError("DPF on v211 does not support Ubuntu")
100116
return ansys_path
101117

102118

src/ansys/dpf/core/server.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,6 @@ def start_local_server(
190190
use_pypim = use_pypim_by_default and is_pypim_configured()
191191
if not use_docker and not use_pypim:
192192
ansys_path = get_ansys_path(ansys_path)
193-
# parse the version to an int and check for supported
194-
try:
195-
ver = int(str(ansys_path)[-3:])
196-
if ver < 211:
197-
raise errors.InvalidANSYSVersionError(f"Ansys v{ver} does not support DPF")
198-
if ver == 211 and is_ubuntu():
199-
raise OSError("DPF on v211 does not support Ubuntu")
200-
except ValueError:
201-
pass
202193

203194
# avoid using any ports in use from existing servers
204195
used_ports = []

src/ansys/dpf/core/server_types.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,12 @@ def info(self):
427427
-------
428428
info : dictionary
429429
Dictionary with server information, including ``"server_ip"``,
430-
``"server_port"``, ``"server_process_id"``, and
431-
``"server_version"`` keys.
430+
``"server_port"``, ``"server_process_id"``, ``"server_version"`` , ``"os"``
431+
and ``"path"`` keys.
432432
"""
433-
return self._base_service.server_info
433+
server_info = self._base_service.server_info
434+
server_info["path"] = self.ansys_path
435+
return server_info
434436

435437
def _del_session(self):
436438
if self._session_instance:

0 commit comments

Comments
 (0)