From f7046ac713737a23758c2e12b0578ce221e7f886 Mon Sep 17 00:00:00 2001 From: cbellot Date: Thu, 3 Apr 2025 11:22:16 +0200 Subject: [PATCH 1/3] Add datasources namespace API --- src/ansys/dpf/core/data_sources.py | 12 ++++++++++++ src/ansys/dpf/gate/data_sources_grpcapi.py | 5 +++++ tests/test_datasources.py | 11 +++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/ansys/dpf/core/data_sources.py b/src/ansys/dpf/core/data_sources.py index a78856c7878..c8fe3ce1102 100644 --- a/src/ansys/dpf/core/data_sources.py +++ b/src/ansys/dpf/core/data_sources.py @@ -680,6 +680,18 @@ def register_namespace(self, result_key: str, namespace: str): """ self._api.data_sources_register_namespace(self, result_key, namespace) + def namespace(self, result_key: str) -> str: + """ + Return the namespace associated to a result_key. The namespace identifies to which operator plugin a call should be delegated to. + + Parameters + ---------- + result_key: + Extension of the file, which is used as a key for choosing the correct + plugin when a result is requested by an operator. + """ + return self._api.data_sources_get_namespace(self, result_key) + def __str__(self): """Describe the entity. diff --git a/src/ansys/dpf/gate/data_sources_grpcapi.py b/src/ansys/dpf/gate/data_sources_grpcapi.py index 5958cc5eb6b..3a5f40d6c9b 100644 --- a/src/ansys/dpf/gate/data_sources_grpcapi.py +++ b/src/ansys/dpf/gate/data_sources_grpcapi.py @@ -176,3 +176,8 @@ def data_sources_get_key(dataSources, index, num_path): def data_sources_get_path(dataSources, key, index): response = _get_stub(dataSources._server).List(dataSources._internal_obj) return list(response.paths[key].paths)[index] + + @staticmethod + def data_sources_get_namespace(dataSources, key): + response = _get_stub(dataSources._server).List(dataSources._internal_obj) + return response.namespaces[key] \ No newline at end of file diff --git a/tests/test_datasources.py b/tests/test_datasources.py index 162b55cd418..9c9d7c59d20 100644 --- a/tests/test_datasources.py +++ b/tests/test_datasources.py @@ -25,6 +25,7 @@ import pytest from ansys import dpf +from ansys.dpf.core import examples import conftest skip_always = pytest.mark.skipif(True, reason="Investigate why this is failing") @@ -173,3 +174,13 @@ def test_register_namespace(allkindofcomplexity, server_type): with pytest.raises(Exception): op = dpf.core.operators.result.displacement(data_sources=data_sources, server=server_type) assert op.eval() is not None + + +def test_namespace(allkindofcomplexity, server_type): + data_sources = dpf.core.DataSources(allkindofcomplexity, server=server_type) + assert data_sources.namespace(data_sources.result_key) == "mapdl" + + cas_h5_file = examples.download_fluent_axial_comp(server=server_type)["cas"][0] + data_sources = dpf.core.DataSources(server=server_type) + data_sources.set_result_file_path(cas_h5_file) + assert data_sources.namespace(data_sources.result_key) == "cff" From 3347c7831bab4e99bef7c72249c68c08201e4be8 Mon Sep 17 00:00:00 2001 From: cbellot Date: Thu, 3 Apr 2025 11:41:20 +0200 Subject: [PATCH 2/3] fix version --- src/ansys/dpf/core/data_sources.py | 1 + tests/test_datasources.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/ansys/dpf/core/data_sources.py b/src/ansys/dpf/core/data_sources.py index c8fe3ce1102..25ae7cd7f3e 100644 --- a/src/ansys/dpf/core/data_sources.py +++ b/src/ansys/dpf/core/data_sources.py @@ -680,6 +680,7 @@ def register_namespace(self, result_key: str, namespace: str): """ self._api.data_sources_register_namespace(self, result_key, namespace) + @version_requires("7.0") def namespace(self, result_key: str) -> str: """ Return the namespace associated to a result_key. The namespace identifies to which operator plugin a call should be delegated to. diff --git a/tests/test_datasources.py b/tests/test_datasources.py index 9c9d7c59d20..4732446cba3 100644 --- a/tests/test_datasources.py +++ b/tests/test_datasources.py @@ -176,6 +176,7 @@ def test_register_namespace(allkindofcomplexity, server_type): assert op.eval() is not None +@conftest.raises_for_servers_version_under("7.0") def test_namespace(allkindofcomplexity, server_type): data_sources = dpf.core.DataSources(allkindofcomplexity, server=server_type) assert data_sources.namespace(data_sources.result_key) == "mapdl" From efd507794afb77c1303872aff24efe0e9794ac93 Mon Sep 17 00:00:00 2001 From: cbellot Date: Thu, 3 Apr 2025 11:43:58 +0200 Subject: [PATCH 3/3] fix version --- src/ansys/dpf/core/data_sources.py | 2 +- tests/test_datasources.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/core/data_sources.py b/src/ansys/dpf/core/data_sources.py index 25ae7cd7f3e..fb51f0a3db0 100644 --- a/src/ansys/dpf/core/data_sources.py +++ b/src/ansys/dpf/core/data_sources.py @@ -680,7 +680,7 @@ def register_namespace(self, result_key: str, namespace: str): """ self._api.data_sources_register_namespace(self, result_key, namespace) - @version_requires("7.0") + @version_requires("9.0") def namespace(self, result_key: str) -> str: """ Return the namespace associated to a result_key. The namespace identifies to which operator plugin a call should be delegated to. diff --git a/tests/test_datasources.py b/tests/test_datasources.py index 4732446cba3..8ec533c08ba 100644 --- a/tests/test_datasources.py +++ b/tests/test_datasources.py @@ -176,7 +176,7 @@ def test_register_namespace(allkindofcomplexity, server_type): assert op.eval() is not None -@conftest.raises_for_servers_version_under("7.0") +@conftest.raises_for_servers_version_under("9.0") def test_namespace(allkindofcomplexity, server_type): data_sources = dpf.core.DataSources(allkindofcomplexity, server=server_type) assert data_sources.namespace(data_sources.result_key) == "mapdl"