Skip to content

Commit f7208c5

Browse files
Integrate mypy into CI
Added pyproject.toml, which defines the mypy configuration. As a first step, only the codechecker_common/ folder is checked by mypy. This can be extended later. The first issue detected by mypy is that Report.report_hash could be None in several cases in the codebase. Also added installation of stub package types-psutil for mypy.
1 parent 5ce99e3 commit f7208c5

File tree

8 files changed

+51
-47
lines changed

8 files changed

+51
-47
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ jobs:
2727
- name: Run pycodestyle & pylint
2828
run: make -k pycodestyle pylint
2929

30+
type-checker:
31+
name: Type checker (mypy)
32+
33+
runs-on: ubuntu-24.04
34+
35+
steps:
36+
- uses: actions/checkout@v2
37+
- uses: actions/setup-python@v4
38+
with:
39+
python-version: '3.12'
40+
- name: Create venv-dev
41+
run: |
42+
make venv_dev
43+
- name: Run mypy
44+
run: |
45+
make mypy
46+
3047
tools:
3148
name: Tools (report-converter, etc.)
3249
runs-on: ubuntu-24.04
@@ -109,25 +126,6 @@ jobs:
109126
working-directory: analyzer
110127
run: make test_unit_cov
111128

112-
common:
113-
name: Common libraries
114-
runs-on: ubuntu-24.04
115-
116-
steps:
117-
- uses: actions/checkout@v2
118-
- uses: actions/setup-python@v4
119-
with:
120-
python-version: '3.9'
121-
122-
- name: Install requirements
123-
working-directory: codechecker_common
124-
run: |
125-
pip install -r requirements_py/dev/requirements.txt
126-
127-
- name: Run mypy tests
128-
working-directory: codechecker_common/tests
129-
run: make mypy
130-
131129
web:
132130
name: Web
133131
runs-on: ubuntu-24.04

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ pycodestyle:
179179
pycodestyle_in_env:
180180
$(ACTIVATE_DEV_VENV) && $(PYCODE_CMD)
181181

182+
mypy:
183+
$(ACTIVATE_DEV_VENV) && mypy --config-file pyproject.toml
184+
182185
test: test_analyzer test_web
183186

184187
test_in_env: test_analyzer_in_env test_web_in_env

codechecker_common/compatibility/multiprocessing.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
# pylint: disable=no-name-in-module
1414
# pylint: disable=unused-import
1515
if sys.platform in ["darwin", "win32"]:
16-
from multiprocess import \
17-
Pipe, Pool, Process, \
18-
Queue, \
19-
Value, \
16+
from multiprocess import ( # type: ignore
17+
Pipe, Pool, Process,
18+
Queue,
19+
Value,
2020
cpu_count
21-
from multiprocess.managers import SyncManager
21+
)
22+
from multiprocess.managers import SyncManager # type: ignore
2223
else:
2324
from concurrent.futures import ProcessPoolExecutor as Pool
24-
from multiprocessing import \
25-
Pipe, \
26-
Process, \
27-
Queue, \
28-
Value, \
25+
from multiprocessing import (
26+
Pipe,
27+
Process,
28+
Queue,
29+
Value,
2930
cpu_count
31+
)
3032
from multiprocessing.managers import SyncManager
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
portalocker~=3.0
22
coverage<=5.5.0
3-
mypy<=1.7.1
3+
mypy~=1.19.0
44
PyYAML~=6.0
55
types-PyYAML~=6.0
66
setuptools~=80.0

codechecker_common/review_status_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def __report_matches_rule(self, report: Report, rule: dict):
184184
report.checker_name != rule['filters']['checker_name']:
185185
return False
186186

187-
if 'report_hash' in rule['filters'] and not \
187+
if 'report_hash' in rule['filters'] and report.report_hash and not \
188188
report.report_hash.startswith(rule['filters']['report_hash']):
189189
return False
190190

@@ -211,7 +211,7 @@ def get_review_status(self, report: Report) -> SourceReviewStatus:
211211
return review_status
212212

213213
# 3. Return "unreviewed" otherwise.
214-
return SourceReviewStatus(bug_hash=report.report_hash)
214+
return SourceReviewStatus(bug_hash=report.report_hash or "")
215215

216216
def set_review_status_config(self, config_file):
217217
"""
@@ -289,7 +289,7 @@ def get_review_status_from_config(
289289
message=rule['actions']['reason']
290290
.encode(encoding='utf-8', errors='ignore')
291291
if 'reason' in rule['actions'] else b'',
292-
bug_hash=report.report_hash,
292+
bug_hash=report.report_hash or "",
293293
in_source=True)
294294

295295
return None
@@ -343,7 +343,7 @@ def get_review_status_from_source(
343343
return SourceReviewStatus(
344344
status=status,
345345
message=message.encode('utf-8'),
346-
bug_hash=report.report_hash,
346+
bug_hash=report.report_hash or "",
347347
in_source=True)
348348

349349
if len(src_comment_data) > 1:

codechecker_common/tests/Makefile

Lines changed: 0 additions & 13 deletions
This file was deleted.

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[tool.mypy]
2+
verbosity = 1
3+
show_error_codes = true
4+
5+
files = [
6+
"codechecker_common/"
7+
]
8+
9+
mypy_path = [
10+
"analyzer/",
11+
"web/",
12+
"tools/report-converter/"
13+
]

web/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ sqlalchemy~=2.0
1111
alembic~=1.5
1212
portalocker~=3.0
1313
psutil~=7.0
14+
types-psutil~=7.0
1415
multiprocess~=0.70
1516
thrift~=0.22
1617
gitpython~=3.0

0 commit comments

Comments
 (0)