Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/ansys/dpf/core/server_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -264,6 +266,29 @@
"""
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)

Check warning on line 290 in src/ansys/dpf/core/server_context.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/server_context.py#L290

Added line #L290 was not covered by tests

def __str__(self):
"""Return string representation of the ServerContext instance."""
return (
Expand Down
32 changes: 32 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
46 changes: 46 additions & 0 deletions tests/testfiles/DpfCustomDefinedTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<Dpf version="1.0">
<DefaultPlugins>
<Linux>
<grpc>
<Path>$(ANSYS_ROOT_FOLDER)/dpf/bin/linx64/libAns.Dpf.Grpc.so</Path>
<Loader>LoadOperators</Loader>
</grpc>
<native>
<Path>$(ANSYS_ROOT_FOLDER)/dpf/bin/linx64/libAns.Dpf.Native.so</Path>
<Loader>LoadOperators</Loader>
</native>
</Linux>
<Windows>
<grpc>
<Path>$(ANSYS_ROOT_FOLDER)\dpf\bin\winx64\Ans.Dpf.Grpc.dll</Path>
<Loader>LoadOperators</Loader>
</grpc>
<native>
<Path>$(ANSYS_ROOT_FOLDER)\dpf\bin\winx64\Ans.Dpf.Native.dll</Path>
<Loader>LoadOperators</Loader>
</native>
</Windows>
</DefaultPlugins>
<SearchPath>
<Linux>
<Path>$(ANSYS_ROOT_FOLDER)/dpf/bin/linx64</Path>
</Linux>
<Windows>
<Debug>
<Path>$(ANSYS_ROOT_FOLDER)\dpf\bin\winx64</Path>
</Debug>
<Release>
<Path>$(ANSYS_ROOT_FOLDER)\dpf\bin\winx64</Path>
</Release>
</Windows>
</SearchPath>
<Environment>
<Windows>
<ANSYS_DPF_ACCEPT_LA>Y</ANSYS_DPF_ACCEPT_LA>
</Windows>
<Linux>
<ANSYS_DPF_ACCEPT_LA>Y</ANSYS_DPF_ACCEPT_LA>
</Linux>
</Environment>
</Dpf>
Loading