Skip to content

Commit f6d57a4

Browse files
authored
Add mypy check (#195)
* Add mypy check * Update mypy path in pipeline.yml * mypy relate fixes
1 parent 1f8c2ef commit f6d57a4

10 files changed

Lines changed: 49 additions & 22 deletions

File tree

‎.github/workflows/pipeline.yml‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ jobs:
1919
options: "--check --diff"
2020
src: ./example_workflows/quantum_espresso/qe_xml_parser/src/qe_xml_parser
2121

22+
mypy:
23+
needs: [black]
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Setup Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.13"
30+
architecture: x64
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
- name: Install mypy
34+
run: pip install mypy
35+
- name: Test
36+
run: mypy --ignore-missing-imports src/python_workflow_definition
37+
2238
pip_check:
2339
runs-on: ubuntu-latest
2440
steps:
@@ -227,4 +243,4 @@ jobs:
227243
- name: Upload coverage reports to Codecov
228244
uses: codecov/codecov-action@v5
229245
with:
230-
token: ${{ secrets.CODECOV_TOKEN }}
246+
token: ${{ secrets.CODECOV_TOKEN }}

‎src/python_workflow_definition/aiida.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import traceback
22
from dataclasses import replace
33
from importlib import import_module
4+
from typing import Any
45

56
from aiida import orm
67
from aiida_pythonjob.data.serializer import general_serializer
@@ -90,8 +91,8 @@ def load_workflow_json(file_name: str) -> WorkGraph:
9091
return wg
9192

9293

93-
def write_workflow_json(wg: WorkGraph, file_name: str) -> dict:
94-
data = {NODES_LABEL: [], EDGES_LABEL: []}
94+
def write_workflow_json(wg: WorkGraph, file_name: str) -> None:
95+
data: dict[str, Any] = {NODES_LABEL: [], EDGES_LABEL: []}
9596
node_name_mapping = {}
9697
data_node_name_mapping = {}
9798
i = 0

‎src/python_workflow_definition/cwl/__init__.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import pickle
33
from pathlib import Path
4+
from typing import Any
45

56
from yaml import CDumper as Dumper
67
from yaml import dump
@@ -86,7 +87,7 @@ def _write_function_cwl(workflow, directory_path: str = "."):
8687
export_path.mkdir(parents=True, exist_ok=True)
8788

8889
for i in function_nodes_dict.keys():
89-
template = {
90+
template: dict[str, Any] = {
9091
"cwlVersion": "v1.2",
9192
"class": "CommandLineTool",
9293
"baseCommand": "python",
@@ -154,7 +155,7 @@ def _write_workflow_config(workflow, directory_path: str = "."):
154155

155156

156157
def _write_workflow(workflow, directory_path: str = "."):
157-
workflow_template = {
158+
workflow_template: dict[str, Any] = {
158159
"cwlVersion": "v1.2",
159160
"class": "Workflow",
160161
"inputs": {},

‎src/python_workflow_definition/executorlib.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from concurrent.futures import Executor
22
from importlib import import_module
33
from inspect import isfunction
4+
from typing import Any
45

56
from python_workflow_definition.models import PythonWorkflowDefinitionWorkflow
67
from python_workflow_definition.purepython import group_edges, resort_total_lst
@@ -58,7 +59,7 @@ def load_workflow_json(file_name: str, exe: Executor):
5859
total_lst = group_edges(edges_new_lst)
5960
total_new_lst = resort_total_lst(total_lst=total_lst, nodes_dict=nodes_new_dict)
6061

61-
result_dict = {}
62+
result_dict: dict[Any, Any] = {}
6263
last_key = None
6364
for lst in total_new_lst:
6465
node = nodes_new_dict[lst[0]]

‎src/python_workflow_definition/jobflow.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from importlib import import_module
22
from inspect import isfunction
3+
from typing import Any
34

45
import numpy as np
56
from jobflow import Flow, job
@@ -39,7 +40,7 @@ def _get_nodes_dict(function_dict: dict):
3940

4041

4142
def _get_edge_from_dict(
42-
target: str, key: str, value_dict: dict, nodes_mapping_dict: dict
43+
target: int, key: str, value_dict: dict, nodes_mapping_dict: dict
4344
) -> dict:
4445
if len(value_dict["attributes"]) == 1:
4546
return {
@@ -199,8 +200,8 @@ def _resort_total_lst(total_dict: dict, nodes_dict: dict) -> dict:
199200
nodes_without_dep_lst = [
200201
k for k in nodes_dict.keys() if k not in nodes_with_dep_lst
201202
]
202-
ordered_lst = []
203-
total_new_dict = {}
203+
ordered_lst: list = []
204+
total_new_dict: dict[Any, dict] = {}
204205
while len(total_new_dict) < len(total_dict):
205206
for ind in sorted(total_dict.keys()):
206207
connect = total_dict[ind]
@@ -215,7 +216,7 @@ def _resort_total_lst(total_dict: dict, nodes_dict: dict) -> dict:
215216

216217

217218
def _group_edges(edges_lst: list) -> dict:
218-
total_dict = {}
219+
total_dict: dict[Any, dict] = {}
219220
for ed_major in edges_lst:
220221
target_id = ed_major[TARGET_LABEL]
221222
tmp_lst = []
@@ -240,7 +241,7 @@ def get_attr_helper(obj, source_handle):
240241
else:
241242
return getattr(getattr(obj, "output"), source_handle)
242243

243-
memory_dict = {}
244+
memory_dict: dict[Any, Any] = {}
244245
for k in total_dict.keys():
245246
v = nodes_dict[k]
246247
if isfunction(v):

‎src/python_workflow_definition/plot.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any
2+
13
import networkx as nx
24
from IPython.display import SVG, display
35

@@ -25,7 +27,7 @@ def plot(file_name: str):
2527

2628
for edge_tuple in total_lst:
2729
target_node, edge_dict = edge_tuple
28-
edge_label_dict = {}
30+
edge_label_dict: dict[Any, list] = {}
2931
for k, v in edge_dict.items():
3032
if v[SOURCE_LABEL] not in edge_label_dict:
3133
edge_label_dict[v[SOURCE_LABEL]] = []

‎src/python_workflow_definition/purepython.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from importlib import import_module
22
from inspect import isfunction
3+
from typing import Any
34

45
from python_workflow_definition.models import PythonWorkflowDefinitionWorkflow
56
from python_workflow_definition.shared import (
@@ -23,7 +24,8 @@ def resort_total_lst(total_lst: list, nodes_dict: dict) -> list:
2324
nodes_without_dep_lst = [
2425
k for k in nodes_dict.keys() if k not in nodes_with_dep_lst
2526
]
26-
ordered_lst, total_new_lst = [], []
27+
ordered_lst: list = []
28+
total_new_lst: list[list] = []
2729
while len(total_new_lst) < len(total_lst):
2830
for ind, connect in total_lst:
2931
if ind not in ordered_lst:
@@ -86,7 +88,7 @@ def load_workflow_json(file_name: str):
8688
total_lst = group_edges(edges_new_lst)
8789
total_new_lst = resort_total_lst(total_lst=total_lst, nodes_dict=nodes_new_dict)
8890

89-
result_dict = {}
91+
result_dict: dict[Any, Any] = {}
9092
last_key = None
9193
for lst in total_new_lst:
9294
node = nodes_new_dict[lst[0]]

‎src/python_workflow_definition/pyiron_base.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from importlib import import_module
22
from inspect import isfunction
3-
from typing import Optional
3+
from typing import Any, Optional
44

55
import numpy as np
66
from pyiron_base import Project, job
@@ -30,7 +30,8 @@ def _resort_total_lst(total_lst: list, nodes_dict: dict) -> list:
3030
nodes_without_dep_lst = [
3131
k for k in nodes_dict.keys() if k not in nodes_with_dep_lst
3232
]
33-
ordered_lst, total_new_lst = [], []
33+
ordered_lst: list = []
34+
total_new_lst: list[list] = []
3435
while len(total_new_lst) < len(total_lst):
3536
for ind, connect in total_lst:
3637
if ind not in ordered_lst:
@@ -74,7 +75,7 @@ def _get_source(
7475
def _get_delayed_object_dict(
7576
total_lst: list, nodes_dict: dict, source_handle_dict: dict, pyiron_project: Project
7677
) -> dict:
77-
delayed_object_dict = {}
78+
delayed_object_dict: dict[Any, DelayedObject] = {}
7879
for item in total_lst:
7980
key, input_dict = item
8081
kwargs = {
@@ -134,8 +135,9 @@ def _get_unique_objects(nodes_dict: dict):
134135
)
135136
delayed_object_dict[k]._python_function = get_dict
136137
delayed_object_dict[k]._input = v
137-
unique_lst = []
138-
delayed_object_updated_dict, match_dict = {}, {}
138+
unique_lst: list = []
139+
delayed_object_updated_dict: dict[Any, DelayedObject] = {}
140+
match_dict: dict[Any, Any] = {}
139141
for dobj in delayed_object_dict.keys():
140142
match = False
141143
for obj in unique_lst:

‎src/python_workflow_definition/pyiron_workflow.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ def write_workflow_json(graph_as_dict: dict, file_name: str = "workflow.json"):
189189
elif edge[TARGET_LABEL] not in remap_get_list_dict.values():
190190
edge_get_list_updated_lst.append(edge)
191191

192-
target_dict = {}
192+
target_dict: dict[Any, list] = {}
193193
for edge in edge_get_list_updated_lst:
194194
for k in pyiron_workflow_modules.keys():
195195
if k == edge[TARGET_LABEL]:
196196
if k not in target_dict:
197197
target_dict[k] = []
198198
target_dict[k].append(edge)
199199

200-
source_dict = {}
200+
source_dict: dict[Any, list] = {}
201201
for edge in edge_get_list_updated_lst:
202202
for k in pyiron_workflow_modules.keys():
203203
if k == edge[SOURCE_LABEL]:

‎src/python_workflow_definition/shared.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections import Counter
2+
from typing import Any
23

34
NODES_LABEL = "nodes"
45
EDGES_LABEL = "edges"
@@ -31,7 +32,7 @@ def get_kwargs(lst: list) -> dict:
3132

3233

3334
def get_source_handles(edges_lst: list) -> dict:
34-
source_handle_dict = {}
35+
source_handle_dict: dict[Any, list] = {}
3536
for ed in edges_lst:
3637
if ed[SOURCE_LABEL] not in source_handle_dict.keys():
3738
source_handle_dict[ed[SOURCE_LABEL]] = []

0 commit comments

Comments
 (0)