From 3b2127e80a6aef66828d4f679ca9164752fcef82 Mon Sep 17 00:00:00 2001 From: ClappeB-Ansys Date: Mon, 28 Jul 2025 10:27:21 +0200 Subject: [PATCH 01/11] refactor: add typing for workflow record function --- src/ansys/dpf/core/workflow.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index bf33a68ea3..ef24237c3d 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -41,6 +41,7 @@ server_meet_version_and_raise, version_requires, ) +from ansys.dpf.core.server_types import BaseServer from ansys.dpf.gate import ( data_processing_capi, data_processing_grpcapi, @@ -624,13 +625,15 @@ def record(self, identifier="", transfer_ownership=True): return self._api.work_flow_record_instance(self, identifier, transfer_ownership) @staticmethod - def get_recorded_workflow(id, server=None): + def get_recorded_workflow(id: int, server: BaseServer | None = None) -> Workflow: """Retrieve a workflow registered (with workflow.record()). Parameters ---------- id : int ID given by the method "record". + server: server.BaseServer + Server from which to get the recorded workflow. Returns ------- @@ -659,12 +662,12 @@ def get_recorded_workflow(id, server=None): return wf @property - def info(self): + def info(self) -> dict[str, list[str]]: """Dictionary with the operator names and the exposed input and output names. Returns ------- - info : dictionarry str->list str + info : dictionary str->list str Dictionary with ``"operator_names"``, ``"input_names"``, and ``"output_names"`` key. """ return { @@ -674,7 +677,7 @@ def info(self): } @property - def operator_names(self): + def operator_names(self) -> list[str]: """List of the names of operators added in the workflow. Returns @@ -688,7 +691,7 @@ def operator_names(self): return out @property - def input_names(self): + def input_names(self) -> list[str]: """List of the input names exposed in the workflow with set_input_name. Returns @@ -702,7 +705,7 @@ def input_names(self): return out @property - def output_names(self): + def output_names(self) -> list[str]: """List of the output names exposed in the workflow with set_output_name. Returns From 466c945271fde2a36de7db07d567385384a6d47c Mon Sep 17 00:00:00 2001 From: ClappeB-Ansys Date: Tue, 5 Aug 2025 15:58:55 +0200 Subject: [PATCH 02/11] feat: add WorkflowInfo typed dict --- src/ansys/dpf/core/workflow.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index ef24237c3d..cc11c66fbe 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -29,7 +29,7 @@ import os from pathlib import Path import traceback -from typing import Union +from typing import TypedDict, Union import warnings import numpy @@ -41,7 +41,7 @@ server_meet_version_and_raise, version_requires, ) -from ansys.dpf.core.server_types import BaseServer +from ansys.dpf.core.server_types import AnyServerType from ansys.dpf.gate import ( data_processing_capi, data_processing_grpcapi, @@ -57,6 +57,12 @@ LOG.setLevel("DEBUG") +class WorkflowInfo(TypedDict): + operator_names: list[str] + input_names: list[str] + output_names: list[str] + + class Workflow: """Represents a workflow. @@ -625,7 +631,7 @@ def record(self, identifier="", transfer_ownership=True): return self._api.work_flow_record_instance(self, identifier, transfer_ownership) @staticmethod - def get_recorded_workflow(id: int, server: BaseServer | None = None) -> Workflow: + def get_recorded_workflow(id: int, server: AnyServerType | None = None) -> Workflow: """Retrieve a workflow registered (with workflow.record()). Parameters @@ -662,19 +668,19 @@ def get_recorded_workflow(id: int, server: BaseServer | None = None) -> Workflow return wf @property - def info(self) -> dict[str, list[str]]: + def info(self) -> WorkflowInfo: """Dictionary with the operator names and the exposed input and output names. Returns ------- - info : dictionary str->list str - Dictionary with ``"operator_names"``, ``"input_names"``, and ``"output_names"`` key. + info : + Dictionary with ``"operator_names"``, ``"input_names"``, and ``"output_names"`` keys. """ - return { - "operator_names": self.operator_names, - "input_names": self.input_names, - "output_names": self.output_names, - } + return WorkflowInfo( + operator_names=self.operator_names, + input_names=self.input_names, + output_names=self.output_names + ) @property def operator_names(self) -> list[str]: From 4ab8c8f3306a0fc585879f80c38bb61b2898b6a8 Mon Sep 17 00:00:00 2001 From: ClappeB-Ansys Date: Tue, 5 Aug 2025 15:59:43 +0200 Subject: [PATCH 03/11] refactor: remove type duplicated type hints --- src/ansys/dpf/core/workflow.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index cc11c66fbe..ebfc75d8dc 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -636,14 +636,14 @@ def get_recorded_workflow(id: int, server: AnyServerType | None = None) -> Workf Parameters ---------- - id : int + id : ID given by the method "record". - server: server.BaseServer + server: Server from which to get the recorded workflow. Returns ------- - workflow : core.Workflow() + workflow : workflow registered in dpf's registry (server side) Examples From 50ae22d60788fedfd386200c8b49e54f843d7346 Mon Sep 17 00:00:00 2001 From: ClappeB-Ansys Date: Tue, 5 Aug 2025 16:23:01 +0200 Subject: [PATCH 04/11] refactor: add docstring to workflowinfo --- src/ansys/dpf/core/workflow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index ebfc75d8dc..43aebcfe58 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -58,6 +58,7 @@ class WorkflowInfo(TypedDict): + """Names of the workflow's operators, inputs and outputs.""" operator_names: list[str] input_names: list[str] output_names: list[str] From 93a8f1a7b8579e9e52c166f9496786536d6fd209 Mon Sep 17 00:00:00 2001 From: BrunoClappe-Ansys <138895561+BClappe@users.noreply.github.com> Date: Tue, 5 Aug 2025 16:28:05 +0200 Subject: [PATCH 05/11] refactor: remove space in typehint Co-authored-by: Paul Profizi <100710998+PProfizi@users.noreply.github.com> --- src/ansys/dpf/core/workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index 43aebcfe58..ac4fd94e4d 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -637,7 +637,7 @@ def get_recorded_workflow(id: int, server: AnyServerType | None = None) -> Workf Parameters ---------- - id : + id: ID given by the method "record". server: Server from which to get the recorded workflow. From 223ae99f97e5df2a4b1e0844b97c24bb3556454c Mon Sep 17 00:00:00 2001 From: BrunoClappe-Ansys <138895561+BClappe@users.noreply.github.com> Date: Tue, 5 Aug 2025 16:28:14 +0200 Subject: [PATCH 06/11] refactor: remove space in typehint Co-authored-by: Paul Profizi <100710998+PProfizi@users.noreply.github.com> --- src/ansys/dpf/core/workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index ac4fd94e4d..8fb472cf8f 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -644,7 +644,7 @@ def get_recorded_workflow(id: int, server: AnyServerType | None = None) -> Workf Returns ------- - workflow : + workflow: workflow registered in dpf's registry (server side) Examples From e73db3b121bc7b63434f0b5244831586dccb0bad Mon Sep 17 00:00:00 2001 From: BrunoClappe-Ansys <138895561+BClappe@users.noreply.github.com> Date: Tue, 5 Aug 2025 16:28:20 +0200 Subject: [PATCH 07/11] refactor: remove space in typehint Co-authored-by: Paul Profizi <100710998+PProfizi@users.noreply.github.com> --- src/ansys/dpf/core/workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index 8fb472cf8f..df1f2d59a1 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -674,7 +674,7 @@ def info(self) -> WorkflowInfo: Returns ------- - info : + info: Dictionary with ``"operator_names"``, ``"input_names"``, and ``"output_names"`` keys. """ return WorkflowInfo( From a0c89bdb167d1be3d9886b88474d7cadcf4f3121 Mon Sep 17 00:00:00 2001 From: ClappeB-Ansys Date: Tue, 5 Aug 2025 17:33:46 +0200 Subject: [PATCH 08/11] refactor: revert typed dict use --- src/ansys/dpf/core/workflow.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index df1f2d59a1..fe6ad00e4b 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -57,13 +57,6 @@ LOG.setLevel("DEBUG") -class WorkflowInfo(TypedDict): - """Names of the workflow's operators, inputs and outputs.""" - operator_names: list[str] - input_names: list[str] - output_names: list[str] - - class Workflow: """Represents a workflow. @@ -669,7 +662,7 @@ def get_recorded_workflow(id: int, server: AnyServerType | None = None) -> Workf return wf @property - def info(self) -> WorkflowInfo: + def info(self) -> dict[str, list[str]]: """Dictionary with the operator names and the exposed input and output names. Returns @@ -677,11 +670,11 @@ def info(self) -> WorkflowInfo: info: Dictionary with ``"operator_names"``, ``"input_names"``, and ``"output_names"`` keys. """ - return WorkflowInfo( - operator_names=self.operator_names, - input_names=self.input_names, - output_names=self.output_names - ) + return { + "operator_names": self.operator_names, + "input_names": self.input_names, + "output_names": self.output_names + } @property def operator_names(self) -> list[str]: From 81fef2f69478d185096750d9d9ad6032bc238758 Mon Sep 17 00:00:00 2001 From: ClappeB-Ansys Date: Wed, 6 Aug 2025 17:43:08 +0200 Subject: [PATCH 09/11] refactor: remove typed dict from imports --- src/ansys/dpf/core/workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index fe6ad00e4b..ea8a5badeb 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -29,7 +29,7 @@ import os from pathlib import Path import traceback -from typing import TypedDict, Union +from typing import Union import warnings import numpy From 9f0912108c51b90b19f6caf2377dd4aa1e8bad99 Mon Sep 17 00:00:00 2001 From: ClappeB-Ansys Date: Thu, 7 Aug 2025 11:04:34 +0200 Subject: [PATCH 10/11] style: change style to conform ruff formatter --- src/ansys/dpf/core/workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index ea8a5badeb..9068efdd68 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -673,7 +673,7 @@ def info(self) -> dict[str, list[str]]: return { "operator_names": self.operator_names, "input_names": self.input_names, - "output_names": self.output_names + "output_names": self.output_names, } @property From dc613f75c776bb5f3ce5931e051806a897703c88 Mon Sep 17 00:00:00 2001 From: ClappeB-Ansys Date: Thu, 7 Aug 2025 15:29:36 +0200 Subject: [PATCH 11/11] style: remove styling error from codacy --- src/ansys/dpf/core/workflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index 9068efdd68..758f029fa7 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -625,7 +625,7 @@ def record(self, identifier="", transfer_ownership=True): return self._api.work_flow_record_instance(self, identifier, transfer_ownership) @staticmethod - def get_recorded_workflow(id: int, server: AnyServerType | None = None) -> Workflow: + def get_recorded_workflow(id: int, server: AnyServerType | None = None) -> Workflow: # noqa W0622 """Retrieve a workflow registered (with workflow.record()). Parameters