Skip to content

Commit a983d6c

Browse files
authored
Add datasources namespace API (#2203)
* Add datasources namespace API * fix version * fix version
1 parent ffa33e4 commit a983d6c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/ansys/dpf/core/data_sources.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,19 @@ def register_namespace(self, result_key: str, namespace: str):
680680
"""
681681
self._api.data_sources_register_namespace(self, result_key, namespace)
682682

683+
@version_requires("9.0")
684+
def namespace(self, result_key: str) -> str:
685+
"""
686+
Return the namespace associated to a result_key. The namespace identifies to which operator plugin a call should be delegated to.
687+
688+
Parameters
689+
----------
690+
result_key:
691+
Extension of the file, which is used as a key for choosing the correct
692+
plugin when a result is requested by an operator.
693+
"""
694+
return self._api.data_sources_get_namespace(self, result_key)
695+
683696
def __str__(self):
684697
"""Describe the entity.
685698

src/ansys/dpf/gate/data_sources_grpcapi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,8 @@ def data_sources_get_key(dataSources, index, num_path):
176176
def data_sources_get_path(dataSources, key, index):
177177
response = _get_stub(dataSources._server).List(dataSources._internal_obj)
178178
return list(response.paths[key].paths)[index]
179+
180+
@staticmethod
181+
def data_sources_get_namespace(dataSources, key):
182+
response = _get_stub(dataSources._server).List(dataSources._internal_obj)
183+
return response.namespaces[key]

tests/test_datasources.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import pytest
2626

2727
from ansys import dpf
28+
from ansys.dpf.core import examples
2829
import conftest
2930

3031
skip_always = pytest.mark.skipif(True, reason="Investigate why this is failing")
@@ -173,3 +174,14 @@ def test_register_namespace(allkindofcomplexity, server_type):
173174
with pytest.raises(Exception):
174175
op = dpf.core.operators.result.displacement(data_sources=data_sources, server=server_type)
175176
assert op.eval() is not None
177+
178+
179+
@conftest.raises_for_servers_version_under("9.0")
180+
def test_namespace(allkindofcomplexity, server_type):
181+
data_sources = dpf.core.DataSources(allkindofcomplexity, server=server_type)
182+
assert data_sources.namespace(data_sources.result_key) == "mapdl"
183+
184+
cas_h5_file = examples.download_fluent_axial_comp(server=server_type)["cas"][0]
185+
data_sources = dpf.core.DataSources(server=server_type)
186+
data_sources.set_result_file_path(cas_h5_file)
187+
assert data_sources.namespace(data_sources.result_key) == "cff"

0 commit comments

Comments
 (0)