diff --git a/src/ansys/dpf/core/server_context.py b/src/ansys/dpf/core/server_context.py index 16c115a558..fd787ba598 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.no_context + >>> # 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 ( diff --git a/tests/test_server.py b/tests/test_server.py index b7ff9a4459..ba867611b1 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, @@ -180,6 +181,37 @@ 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" +) +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 + ref = ["grpc", "native"] + if 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", + ] + assert sorted(list(server_plugins.keys())) == ref + + @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