Skip to content

Commit be96003

Browse files
authored
Remove priority to AWPROOT+__ansys_version__ (#972)
* Update core.misc.get_ansys_path as discussed * Refactor server_types.py/_get_dll_path to actually use core.misc.get_ansys_path and ensure the logic is the same * Refactor test_launcher.py/test_launch_server_full_path to use core.misc.get_ansys_path() * Refactor get_server_type_from_config to also use get_ansys_path() * Revert change to ServerFactory.get_server_type_from_config
1 parent 679341d commit be96003

File tree

4 files changed

+8
-23
lines changed

4 files changed

+8
-23
lines changed

src/ansys/dpf/core/misc.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def is_ubuntu():
6262

6363

6464
def get_ansys_path(ansys_path=None):
65-
"""Give input path back if given, else look for ANSYS_DPF_PATH, then AWP_ROOT+__ansys_version__,
66-
then calls for find_ansys as a last resort.
65+
"""Give input path back if given, else look for ANSYS_DPF_PATH,
66+
then among AWP_ROOT and installed ansys-dpf-server modules to take the latest available.
6767
6868
Parameters
6969
----------
@@ -80,9 +80,7 @@ def get_ansys_path(ansys_path=None):
8080
# First check the environment variable for a custom path
8181
if ansys_path is None:
8282
ansys_path = os.environ.get("ANSYS_DPF_PATH")
83-
# Then check for usual installation folders with AWP_ROOT and find_ansys
84-
if ansys_path is None:
85-
ansys_path = os.environ.get("AWP_ROOT" + __ansys_version__)
83+
# Then check for usual installation folders with AWP_ROOT and installed modules
8684
if ansys_path is None:
8785
ansys_path = find_ansys()
8886
# If still no install has been found, throw an exception

src/ansys/dpf/core/server_factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,15 +595,15 @@ def get_server_type_from_config(
595595
# If no SERVER_CONFIGURATION is yet defined, set one with default values
596596
is_server_old = False
597597
if ansys_path is not None:
598-
if not "ansys_dpf_server" in ansys_path:
598+
if "ansys_dpf_server" not in ansys_path:
599599
is_server_old = _find_outdated_ansys_version(ansys_path)
600600
config = get_default_server_config(is_server_old, docker_config)
601601
if config.protocol == CommunicationProtocols.gRPC and config.legacy:
602602
return LegacyGrpcServer
603603
elif config.protocol == CommunicationProtocols.gRPC and not config.legacy:
604-
from ansys.dpf.core.misc import __ansys_version__
605-
606604
if ansys_path is None:
605+
from ansys.dpf.core.misc import __ansys_version__
606+
607607
ansys_path = os.environ.get("AWP_ROOT" + str(__ansys_version__), None)
608608
if ansys_path is not None:
609609
sub_folders = os.path.join(ansys_path, _get_path_in_install())

src/ansys/dpf/core/server_types.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
server_to_ansys_grpc_dpf_version,
2525
server_to_ansys_version,
2626
)
27-
from ansys.dpf.core.misc import __ansys_version__
2827
from ansys.dpf.core import server_context
2928
from ansys.dpf.gate import load_api, data_processing_grpcapi
3029

@@ -42,17 +41,7 @@
4241
def _get_dll_path(name, ansys_path=None):
4342
"""Helper function to get the right dll path for Linux or Windows"""
4443
ISPOSIX = os.name == "posix"
45-
if ansys_path is None:
46-
ansys_path = os.environ.get("ANSYS_DPF_PATH")
47-
if ansys_path is None:
48-
awp_root = "AWP_ROOT" + str(__ansys_version__)
49-
ANSYS_INSTALL = os.environ.get(awp_root, None)
50-
if ANSYS_INSTALL is None:
51-
ANSYS_INSTALL = core.misc.find_ansys()
52-
else:
53-
ANSYS_INSTALL = ansys_path
54-
if ANSYS_INSTALL is None:
55-
raise ImportError(f"Could not find ansys installation path using {awp_root}.")
44+
ANSYS_INSTALL = core.misc.get_ansys_path(ansys_path)
5645
api_path = load_api._get_path_in_install()
5746
if api_path is None:
5847
raise ImportError(f"Could not find API path in install.")

tests/test_launcher.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ def test_start_local_wrong_ansys_path(self, server_config):
168168

169169
@pytest.mark.skipif(running_docker, reason="Not made to work on docker")
170170
def test_launch_server_full_path(self, server_config):
171-
ansys_path = os.environ.get(
172-
"AWP_ROOT" + core.misc.__ansys_version__, core.misc.find_ansys()
173-
)
171+
ansys_path = core.misc.get_ansys_path()
174172
if os.name == "nt":
175173
path = os.path.join(ansys_path, "aisol", "bin", "winx64")
176174
else:

0 commit comments

Comments
 (0)