Skip to content

Commit bf2923a

Browse files
Merge pull request #6 from amd/feature/mypy-precommit
Feature/mypy precommit
2 parents 3a0b75c + 184ec1d commit bf2923a

File tree

8 files changed

+156
-14
lines changed

8 files changed

+156
-14
lines changed

.github/workflows/code_quality_checks.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ jobs:
1313

1414
steps:
1515
- uses: actions/checkout@v3
16-
- uses: pre-commit/[email protected]
17-
16+
- name: setup environment
17+
run: |
18+
./dev-setup.sh
19+
- name: run pre-commit hooks
20+
run: |
21+
pre-commit run --all-files --show-diff-on-failure --color=always
1822
- name: Print message on failure
1923
if: failure()
2024
run: |

.mypy.ini

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
[mypy]
2+
# Global mypy configuration
3+
4+
[mypy-nodescraper.base.regexanalyzer]
5+
ignore_errors = True
6+
7+
[mypy-nodescraper.cli.cli]
8+
ignore_errors = True
9+
10+
[mypy-nodescraper.cli.dynamicparserbuilder]
11+
ignore_errors = True
12+
13+
[mypy-nodescraper.cli.helper]
14+
ignore_errors = True
15+
16+
[mypy-nodescraper.cli.inputargtypes]
17+
ignore_errors = True
18+
19+
[mypy-nodescraper.configbuilder]
20+
ignore_errors = True
21+
22+
[mypy-nodescraper.configregistry]
23+
ignore_errors = True
24+
25+
[mypy-nodescraper.enums.eventpriority]
26+
ignore_errors = True
27+
28+
[mypy-nodescraper.enums.systeminteraction]
29+
ignore_errors = True
30+
31+
[mypy-nodescraper.interfaces.connectionmanager]
32+
ignore_errors = True
33+
34+
[mypy-nodescraper.interfaces.datacollectortask]
35+
ignore_errors = True
36+
37+
[mypy-nodescraper.interfaces.dataplugin]
38+
ignore_errors = True
39+
40+
[mypy-nodescraper.interfaces.task]
41+
ignore_errors = True
42+
43+
[mypy-nodescraper.models.analyzerargs]
44+
ignore_errors = True
45+
46+
[mypy-nodescraper.models.datamodel]
47+
ignore_errors = True
48+
49+
[mypy-nodescraper.pluginexecutor]
50+
ignore_errors = True
51+
52+
[mypy-nodescraper.plugins.inband.bios.analyzer_args]
53+
ignore_errors = True
54+
55+
[mypy-nodescraper.plugins.inband.cmdline.cmdline_analyzer]
56+
ignore_errors = True
57+
58+
[mypy-nodescraper.plugins.inband.dimm.dimm_collector]
59+
ignore_errors = True
60+
61+
[mypy-nodescraper.plugins.inband.dkms.analyzer_args]
62+
ignore_errors = True
63+
64+
[mypy-nodescraper.plugins.inband.dmesg.dmesg_analyzer]
65+
ignore_errors = True
66+
67+
[mypy-nodescraper.plugins.inband.dmesg.dmesgdata]
68+
ignore_errors = True
69+
70+
[mypy-nodescraper.plugins.inband.memory.memory_collector]
71+
ignore_errors = True
72+
73+
[mypy-nodescraper.plugins.inband.os.os_collector]
74+
ignore_errors = True
75+
76+
[mypy-nodescraper.plugins.inband.package.analyzer_args]
77+
ignore_errors = True
78+
79+
[mypy-nodescraper.plugins.inband.process.analyzer_args]
80+
ignore_errors = True
81+
82+
[mypy-nodescraper.plugins.inband.process.process_collector]
83+
ignore_errors = True
84+
85+
[mypy-nodescraper.plugins.inband.rocm.rocm_plugin]
86+
ignore_errors = True
87+
88+
[mypy-nodescraper.taskresulthooks.filesystemloghook]
89+
ignore_errors = True
90+
91+
[mypy-nodescraper.typeutils]
92+
ignore_errors = True
93+
94+
[mypy-nodescraper.utils]
95+
ignore_errors = True
96+
97+
[mypy-test.unit.conftest]
98+
ignore_errors = True
99+
100+
[mypy-test.unit.framework.common.shared_utils]
101+
ignore_errors = True
102+
103+
[mypy-test.unit.framework.test_cli_helper]
104+
ignore_errors = True
105+
106+
[mypy-test.unit.framework.test_dataplugin]
107+
ignore_errors = True
108+
109+
[mypy-test.unit.framework.test_plugin_executor]
110+
ignore_errors = True
111+
112+
[mypy-nodescraper.models.collectorargs]
113+
ignore_errors = True
114+
115+
[mypy-nodescraper.plugins.inband.kernel_module.*]
116+
ignore_errors = True
117+
118+
[mypy-nodescraper.plugins.inband.nvme.nvme_collector]
119+
ignore_errors = True
120+
121+
[mypy-test.unit.framework.test_cli]
122+
ignore_errors = True

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ repos:
1515
rev: 25.1.0
1616
hooks:
1717
- id: black
18+
- repo: https://github.com/pre-commit/mirrors-mypy
19+
rev: v1.15.0
20+
hooks:
21+
- id: mypy
22+
args: [--install-types, --non-interactive, --explicit-package-bases, --allow-redefinition]
23+
language: system

nodescraper/interfaces/dataanalyzertask.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,19 @@ def __init_subclass__(cls, **kwargs: dict[str, Any]) -> None:
119119
raise TypeError(f"No data model set for {cls.__name__}")
120120

121121
if hasattr(cls, "analyze_data"):
122-
cls.analyze_data = analyze_decorator(cls.analyze_data)
122+
setattr(cls, "analyze_data", analyze_decorator(cls.analyze_data)) # noqa
123123

124124
@abc.abstractmethod
125125
def analyze_data(
126126
self,
127127
data: TDataModel,
128-
args: Optional[TAnalyzeArg | dict],
128+
args: Optional[TAnalyzeArg],
129129
) -> TaskResult:
130130
"""Analyze the provided data and return a TaskResult
131131
132132
Args:
133133
data (TDataModel): data to analyze
134-
args (Optional[TAnalyzeArg | dict]): Optional arguments for analysis, can be a model or dict
134+
args (Optional[TAnalyzeArg]): Optional arguments for analysis. Dicts will be handled in the decorator"
135135
136136
Returns:
137137
TaskResult: Task result containing the analysis outcome

nodescraper/interfaces/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def max_event_priority_level(self, input_value: str | EventPriority):
8383
elif isinstance(input_value, int):
8484
value = EventPriority(input_value)
8585
elif isinstance(input_value, EventPriority):
86-
value: EventPriority = input_value
86+
value: EventPriority = input_value # type:ignore
8787
else:
8888
raise ValueError(f"Invalid type for max_event_priority_level: {type(input_value)}")
8989

nodescraper/models/event.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def validate_timestamp(cls, timestamp: datetime.datetime) -> datetime.datetime:
7373
if timestamp.tzinfo is None or timestamp.tzinfo.utcoffset(timestamp) is None:
7474
raise ValueError("datetime must be timezone aware")
7575

76-
if timestamp.utcoffset() is not None and timestamp.utcoffset().total_seconds() != 0:
76+
utc_offset = timestamp.utcoffset()
77+
if utc_offset is not None and utc_offset.total_seconds() != 0:
7778
timestamp = timestamp.astimezone(datetime.timezone.utc)
7879

7980
return timestamp
@@ -90,7 +91,7 @@ def validate_category(cls, category: str | Enum) -> str:
9091
if isinstance(category, Enum):
9192
category = category.value
9293

93-
category = category.strip().upper()
94+
category = str(category).strip().upper()
9495
category = re.sub(r"[\s-]", "_", category)
9596
return category
9697

nodescraper/resultcollators/tablesummary.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def collate_results(
4040
connection_results (list[TaskResult]): list of connection results to collate
4141
"""
4242

43-
def gen_str_table(headers: list[str], rows: list[str]):
43+
def gen_str_table(headers: list[str], rows: list[list[str | None]]):
4444
column_widths = [len(header) for header in headers]
4545
for row in rows:
4646
for i, cell in enumerate(row):
@@ -59,16 +59,24 @@ def gen_row(row):
5959
tables = ""
6060
if connection_results:
6161
rows = []
62-
for result in connection_results:
63-
rows.append([result.task, result.status.name, result.message])
62+
for connection_result in connection_results:
63+
rows.append(
64+
[
65+
connection_result.task,
66+
connection_result.status.name,
67+
connection_result.message,
68+
]
69+
)
6470

6571
table = gen_str_table(["Connection", "Status", "Message"], rows)
6672
tables += f"\n\n{table}"
6773

6874
if plugin_results:
6975
rows = []
70-
for result in plugin_results:
71-
rows.append([result.source, result.status.name, result.message])
76+
for plugin_result in plugin_results:
77+
rows.append(
78+
[plugin_result.source, plugin_result.status.name, plugin_result.message]
79+
)
7280

7381
table = gen_str_table(["Plugin", "Status", "Message"], rows)
7482
tables += f"\n\n{table}"

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ dev = [
2727
"ruff",
2828
"pre-commit",
2929
"pytest",
30-
"pytest-cov"
30+
"pytest-cov",
31+
"mypy"
3132
]
3233

3334
[project.urls]

0 commit comments

Comments
 (0)