Skip to content

Commit

Permalink
any to and from workflow (#1839)
Browse files Browse the repository at this point in the history
* any to and from workflow

* retro
  • Loading branch information
cbellot000 authored Nov 18, 2024
1 parent f9d1e2b commit b954c63
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/ansys/dpf/core/any.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def _type_to_new_from_get_as_method(self, obj):
data_tree,
custom_type_field,
collection,
workflow,
)

if issubclass(obj, int):
Expand Down Expand Up @@ -185,6 +186,11 @@ def _type_to_new_from_get_as_method(self, obj):
self._api.any_new_from_any_collection,
self._api.any_get_as_any_collection,
)
elif issubclass(obj, workflow.Workflow):
return (
self._api.any_new_from_workflow,
self._api.any_get_as_workflow,
)
elif issubclass(obj, dpf_vector.DPFVectorInt):
return (
self._api.any_new_from_int_collection,
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/dpf/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def has_local_server():
return dpf.core.SERVER is not None


def _global_server():
def _global_server() -> BaseServer:
"""Retrieve the global server if it exists.
If the global server has not been specified, check the expected server type in
Expand Down
10 changes: 10 additions & 0 deletions src/ansys/dpf/gate/any_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def _type_to_message_type():
data_tree,
custom_type_field,
collection_base,
workflow,
)

return [(int, base_pb2.Type.INT),
Expand All @@ -54,6 +55,7 @@ def _type_to_message_type():
(generic_data_container.GenericDataContainer, base_pb2.Type.GENERIC_DATA_CONTAINER),
(scoping.Scoping, base_pb2.Type.SCOPING),
(data_tree.DataTree, base_pb2.Type.DATA_TREE),
(workflow.Workflow, base_pb2.Type.WORKFLOW),
(collection_base.CollectionBase, base_pb2.Type.COLLECTION, base_pb2.Type.ANY),
(dpf_vector.DPFVectorInt, base_pb2.Type.COLLECTION, base_pb2.Type.INT),
]
Expand Down Expand Up @@ -139,6 +141,10 @@ def any_get_as_any_collection(any):
def any_get_as_int_collection(any):
return AnyGRPCAPI._get_as(any).collection

@staticmethod
def any_get_as_workflow(any):
return AnyGRPCAPI._get_as(any).workflow

@staticmethod
def _new_from(any, client=None):
from ansys.grpc.dpf import dpf_any_pb2
Expand Down Expand Up @@ -220,3 +226,7 @@ def any_new_from_scoping(any):
@staticmethod
def any_new_from_data_tree(any):
return AnyGRPCAPI._new_from(any, any._server)

@staticmethod
def any_new_from_workflow(any):
return AnyGRPCAPI._new_from(any, any._server)
12 changes: 12 additions & 0 deletions tests/test_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,15 @@ def test_cast_scoping_any(server_type):
new_entity = any_dpf.cast()

assert entity.location == new_entity.location


@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
reason="for_each not implemented below 8.0",
)
def test_cast_workflow_any(server_type):
entity = dpf.Workflow(server=server_type)
any_dpf = dpf.Any.new_from(entity)
new_entity = any_dpf.cast()

assert new_entity.input_names == []

0 comments on commit b954c63

Please sign in to comment.