From d5bfed4718c2a94e32eb0a68a74bba9eea1dc667 Mon Sep 17 00:00:00 2001 From: PProfizi Date: Fri, 20 Jun 2025 10:46:12 +0200 Subject: [PATCH 1/7] feat(server): Add ServerContext.xml_path setter to allow setting the xml_path for a "dpf.AvailableServerContexts.custom_defined" context. --- src/ansys/dpf/core/server_context.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/ansys/dpf/core/server_context.py b/src/ansys/dpf/core/server_context.py index 16c115a558..9afbb67d47 100644 --- a/src/ansys/dpf/core/server_context.py +++ b/src/ansys/dpf/core/server_context.py @@ -35,6 +35,8 @@ ANSYS_DPF_SERVER_CONTEXT=ENTRY and ANSYS_DPF_SERVER_CONTEXT=PREMIUM can be used. """ +from __future__ import annotations + from enum import Enum import os import warnings @@ -264,6 +266,29 @@ def xml_path(self): """ return self._xml_path + @xml_path.setter + def xml_path(self, xml_path: str | os.PathLike): + r"""Set the path to the xml file defining default plugins to load at server start. + + Parameters + ---------- + xml_path: + Path to the XML file to use at server start. Useful to target a custom XML file. + + Examples + -------- + Create a ServerContext targeting a custom XML file. + + >>> import ansys.dpf.core as dpf + >>> # Create a custom server context + >>> custom_server_context = dpf.AvailableServerContexts.custom_defined + >>> # Set the XML path + >>> custom_server_context.xml_path = r'\path\to\file' + >>> # Start a DPF server using this context + >>> # server = dpf.start_local_server(context=custom_server_context) + """ + self._xml_path = str(xml_path) + def __str__(self): """Return string representation of the ServerContext instance.""" return ( From ee29bd93f66eec4f3adc5ea7aea8a035f29e5b06 Mon Sep 17 00:00:00 2001 From: PProfizi Date: Fri, 20 Jun 2025 15:55:01 +0200 Subject: [PATCH 2/7] Add test and fix docstring --- src/ansys/dpf/core/server_context.py | 2 +- tests/test_server.py | 10 ++++++ tests/testfiles/DpfCustomDefinedTest.xml | 46 ++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/testfiles/DpfCustomDefinedTest.xml diff --git a/src/ansys/dpf/core/server_context.py b/src/ansys/dpf/core/server_context.py index 9afbb67d47..fd787ba598 100644 --- a/src/ansys/dpf/core/server_context.py +++ b/src/ansys/dpf/core/server_context.py @@ -281,7 +281,7 @@ def xml_path(self, xml_path: str | os.PathLike): >>> import ansys.dpf.core as dpf >>> # Create a custom server context - >>> custom_server_context = dpf.AvailableServerContexts.custom_defined + >>> custom_server_context = dpf.AvailableServerContexts.no_context >>> # Set the XML path >>> custom_server_context.xml_path = r'\path\to\file' >>> # Start a DPF server using this context diff --git a/tests/test_server.py b/tests/test_server.py index b7ff9a4459..ab325472ee 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -180,6 +180,16 @@ def test_server_plugins(self, server_config): assert "native" in server_plugins.keys() +@raises_for_servers_version_under("7.0") +def test_server_plugins(remote_config_server_type, testfiles_dir): + from pathlib import Path + + context = dpf.core.AvailableServerContexts.no_context + context.xml_path = Path(testfiles_dir) / "DpfCustomDefinedTest.xml" + server_plugins = start_local_server(config=remote_config_server_type, context=context).plugins + assert sorted(list(server_plugins.keys())) == ["grpc", "native"] + + @pytest.mark.skipif( os.name == "posix" or running_docker, reason="lin issue: 2 processes can be run with same port", diff --git a/tests/testfiles/DpfCustomDefinedTest.xml b/tests/testfiles/DpfCustomDefinedTest.xml new file mode 100644 index 0000000000..05d9175388 --- /dev/null +++ b/tests/testfiles/DpfCustomDefinedTest.xml @@ -0,0 +1,46 @@ + + + + + + $(ANSYS_ROOT_FOLDER)/dpf/bin/linx64/libAns.Dpf.Grpc.so + LoadOperators + + + $(ANSYS_ROOT_FOLDER)/dpf/bin/linx64/libAns.Dpf.Native.so + LoadOperators + + + + + $(ANSYS_ROOT_FOLDER)\dpf\bin\winx64\Ans.Dpf.Grpc.dll + LoadOperators + + + $(ANSYS_ROOT_FOLDER)\dpf\bin\winx64\Ans.Dpf.Native.dll + LoadOperators + + + + + + $(ANSYS_ROOT_FOLDER)/dpf/bin/linx64 + + + + $(ANSYS_ROOT_FOLDER)\dpf\bin\winx64 + + + $(ANSYS_ROOT_FOLDER)\dpf\bin\winx64 + + + + + + Y + + + Y + + + \ No newline at end of file From bbfd764d421a5c605688c5286332474eaacc300d Mon Sep 17 00:00:00 2001 From: PProfizi Date: Fri, 4 Jul 2025 09:31:20 +0200 Subject: [PATCH 3/7] Update test ref for DPF<25R2 --- tests/test_server.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/test_server.py b/tests/test_server.py index ab325472ee..d6d20d54ba 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -44,6 +44,7 @@ from ansys.dpf.core.server_factory import CommunicationProtocols, ServerConfig from conftest import ( SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0, + SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, raises_for_servers_version_under, remove_none_available_config, running_docker, @@ -187,7 +188,33 @@ def test_server_plugins(remote_config_server_type, testfiles_dir): context = dpf.core.AvailableServerContexts.no_context context.xml_path = Path(testfiles_dir) / "DpfCustomDefinedTest.xml" server_plugins = start_local_server(config=remote_config_server_type, context=context).plugins - assert sorted(list(server_plugins.keys())) == ["grpc", "native"] + if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0: + ref = ["grpc", "native"] + else: # Use of custom xml not working for DPF < 25R2 + ref = [ + "cff", + "cgns", + "compression", + "fem_utils", + "flow_diagram", + "grpc", + "hdf5", + "live_post", + "lsDyna", + "mapdl_plugin", + "math", + "mechanical", + "mechanical_results", + "mesh_operators", + "multiphysics_mapper", + "native", + "point_cloud_search", + "prime", + "python_loader", + "rbd", + "vtk", + ] + assert sorted(list(server_plugins.keys())) == ref @pytest.mark.skipif( From ea7648698aaa7cbe547229add4ad08ffea41ada9 Mon Sep 17 00:00:00 2001 From: PProfizi Date: Fri, 4 Jul 2025 10:01:25 +0200 Subject: [PATCH 4/7] Update test ref for Docker --- tests/test_server.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_server.py b/tests/test_server.py index d6d20d54ba..08f97b83ad 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -190,6 +190,24 @@ def test_server_plugins(remote_config_server_type, testfiles_dir): server_plugins = start_local_server(config=remote_config_server_type, context=context).plugins if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0: ref = ["grpc", "native"] + elif running_docker: # Use of custom xml not working either on Docker + ref = [ + "cff", + "cngs", + "compression", + "documentation", + "fem_utils", + "grpc", + "hdf5", + "live_post", + "lsDyna", + "mapdl_plugin", + "math", + "mechanical_results", + "mesh_plugin", + "native", + "vtk", + ] else: # Use of custom xml not working for DPF < 25R2 ref = [ "cff", From 7f7e36e11134f4effce781eea695f9813aa11ffe Mon Sep 17 00:00:00 2001 From: PProfizi Date: Fri, 4 Jul 2025 10:02:16 +0200 Subject: [PATCH 5/7] Rename the test --- tests/test_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_server.py b/tests/test_server.py index 08f97b83ad..b61e02e90d 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -182,7 +182,7 @@ def test_server_plugins(self, server_config): @raises_for_servers_version_under("7.0") -def test_server_plugins(remote_config_server_type, testfiles_dir): +def test_server_context_custom_xml(remote_config_server_type, testfiles_dir): from pathlib import Path context = dpf.core.AvailableServerContexts.no_context From 8e3a83fe617442df8c18c6522a1d5c2d15cd0a08 Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Fri, 4 Jul 2025 13:36:12 +0200 Subject: [PATCH 6/7] Skip test for DPF < 25R2 --- tests/test_server.py | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/tests/test_server.py b/tests/test_server.py index b61e02e90d..3cc3638d88 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -181,16 +181,15 @@ def test_server_plugins(self, server_config): assert "native" in server_plugins.keys() -@raises_for_servers_version_under("7.0") +@pytest.mark.skipif(not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, reason="not working properly before 25R2") def test_server_context_custom_xml(remote_config_server_type, testfiles_dir): from pathlib import Path context = dpf.core.AvailableServerContexts.no_context context.xml_path = Path(testfiles_dir) / "DpfCustomDefinedTest.xml" server_plugins = start_local_server(config=remote_config_server_type, context=context).plugins - if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0: - ref = ["grpc", "native"] - elif running_docker: # Use of custom xml not working either on Docker + ref = ["grpc", "native"] + if running_docker: # Use of custom xml not working either on Docker ref = [ "cff", "cngs", @@ -208,30 +207,6 @@ def test_server_context_custom_xml(remote_config_server_type, testfiles_dir): "native", "vtk", ] - else: # Use of custom xml not working for DPF < 25R2 - ref = [ - "cff", - "cgns", - "compression", - "fem_utils", - "flow_diagram", - "grpc", - "hdf5", - "live_post", - "lsDyna", - "mapdl_plugin", - "math", - "mechanical", - "mechanical_results", - "mesh_operators", - "multiphysics_mapper", - "native", - "point_cloud_search", - "prime", - "python_loader", - "rbd", - "vtk", - ] assert sorted(list(server_plugins.keys())) == ref From 5943a883f27da343f8afa985b5fceb059c6700fb Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Fri, 4 Jul 2025 14:06:46 +0200 Subject: [PATCH 7/7] Fix Style Check --- tests/test_server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_server.py b/tests/test_server.py index 3cc3638d88..ba867611b1 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -181,7 +181,9 @@ def test_server_plugins(self, server_config): assert "native" in server_plugins.keys() -@pytest.mark.skipif(not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, reason="not working properly before 25R2") +@pytest.mark.skipif( + not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0, reason="not working properly before 25R2" +) def test_server_context_custom_xml(remote_config_server_type, testfiles_dir): from pathlib import Path