From 6bddcba9aef97e1dfd9909bff0fa94ef54436923 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Tue, 30 Jan 2024 17:00:56 +0100 Subject: [PATCH] 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 * Fix case of ansys_path being a Path and not a str Signed-off-by: paul.profizi * Add DPFServerPathFormatError Signed-off-by: paul.profizi * Move the ansys_path format checks to core\misc.py\get_ansys_path Signed-off-by: paul.profizi * Fix regex patterns compilation Signed-off-by: paul.profizi * Update BaseServer.info Signed-off-by: paul.profizi * Update test_launcher.py tests Signed-off-by: paul.profizi * Revert "Update test_launcher.py tests" This reverts commit cf360fbb56f279871bf3e0af4c5fd0d168e8a50f. * Revert "Add DPFServerPathFormatError" This reverts commit 096198155a3fb9df7635ae4dd1476666a0f23c44. * Revert back to only testing minimal version if ansys_path ends in vXYZ Signed-off-by: paul.profizi --------- Signed-off-by: paul.profizi --- src/ansys/dpf/core/misc.py | 16 ++++++++++++++++ src/ansys/dpf/core/server.py | 9 --------- src/ansys/dpf/core/server_types.py | 8 +++++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/ansys/dpf/core/misc.py b/src/ansys/dpf/core/misc.py index 74fb39544d..affa458bcc 100644 --- a/src/ansys/dpf/core/misc.py +++ b/src/ansys/dpf/core/misc.py @@ -2,11 +2,13 @@ import platform import glob import os +import re import packaging.version import pkg_resources import importlib from pkgutil import iter_modules +from ansys.dpf.core import errors from ansys.dpf.gate._version import __ansys_version__ from ansys.dpf.gate import load_api @@ -97,6 +99,20 @@ def get_ansys_path(ansys_path=None): '- when starting the server with "start_local_server(ansys_path=*/vXXX)"\n' '- or by setting it by default with the environment variable "ANSYS_DPF_PATH"' ) + # parse the version to an int and check for supported + ansys_folder_name = str(ansys_path).split(os.sep)[-1] + reobj_vXYZ = re.compile( + "^v[0123456789]{3}$" + ) + if reobj_vXYZ.match(ansys_folder_name): + # vXYZ Unified Install folder + ver = int(str(ansys_path)[-3:]) + else: + ver = 222 + if ver < 211: + raise errors.InvalidANSYSVersionError(f"Ansys v{ver} does not support DPF") + if ver == 211 and is_ubuntu(): + raise OSError("DPF on v211 does not support Ubuntu") return ansys_path diff --git a/src/ansys/dpf/core/server.py b/src/ansys/dpf/core/server.py index 65c5b6f170..b4580424a5 100644 --- a/src/ansys/dpf/core/server.py +++ b/src/ansys/dpf/core/server.py @@ -190,15 +190,6 @@ def start_local_server( use_pypim = use_pypim_by_default and is_pypim_configured() if not use_docker and not use_pypim: ansys_path = get_ansys_path(ansys_path) - # parse the version to an int and check for supported - try: - ver = int(str(ansys_path)[-3:]) - if ver < 211: - raise errors.InvalidANSYSVersionError(f"Ansys v{ver} does not support DPF") - if ver == 211 and is_ubuntu(): - raise OSError("DPF on v211 does not support Ubuntu") - except ValueError: - pass # avoid using any ports in use from existing servers used_ports = [] diff --git a/src/ansys/dpf/core/server_types.py b/src/ansys/dpf/core/server_types.py index 9f966391c9..88d541383d 100644 --- a/src/ansys/dpf/core/server_types.py +++ b/src/ansys/dpf/core/server_types.py @@ -427,10 +427,12 @@ def info(self): ------- info : dictionary Dictionary with server information, including ``"server_ip"``, - ``"server_port"``, ``"server_process_id"``, and - ``"server_version"`` keys. + ``"server_port"``, ``"server_process_id"``, ``"server_version"`` , ``"os"`` + and ``"path"`` keys. """ - return self._base_service.server_info + server_info = self._base_service.server_info + server_info["path"] = self.ansys_path + return server_info def _del_session(self): if self._session_instance: