diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55ec5554ff..8d524508d6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,23 @@ jobs: - name: Run pycodestyle & pylint run: make -k pycodestyle pylint + type-checker: + name: Type checker (mypy) + + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v4 + with: + python-version: '3.12' + - name: Create venv-dev + run: | + make venv_dev + - name: Run mypy + run: | + make mypy + tools: name: Tools (report-converter, etc.) runs-on: ubuntu-24.04 @@ -109,25 +126,6 @@ jobs: working-directory: analyzer run: make test_unit_cov - common: - name: Common libraries - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - - name: Install requirements - working-directory: codechecker_common - run: | - pip install -r requirements_py/dev/requirements.txt - - - name: Run mypy tests - working-directory: codechecker_common/tests - run: make mypy - web: name: Web runs-on: ubuntu-24.04 diff --git a/Makefile b/Makefile index 697f5da6a6..337687651d 100644 --- a/Makefile +++ b/Makefile @@ -179,6 +179,9 @@ pycodestyle: pycodestyle_in_env: $(ACTIVATE_DEV_VENV) && $(PYCODE_CMD) +mypy: + $(ACTIVATE_DEV_VENV) && mypy --config-file pyproject.toml + test: test_analyzer test_web test_in_env: test_analyzer_in_env test_web_in_env diff --git a/codechecker_common/compatibility/multiprocessing.py b/codechecker_common/compatibility/multiprocessing.py index 754294014d..74ccfa1d4a 100644 --- a/codechecker_common/compatibility/multiprocessing.py +++ b/codechecker_common/compatibility/multiprocessing.py @@ -13,18 +13,20 @@ # pylint: disable=no-name-in-module # pylint: disable=unused-import if sys.platform in ["darwin", "win32"]: - from multiprocess import \ - Pipe, Pool, Process, \ - Queue, \ - Value, \ + from multiprocess import ( # type: ignore + Pipe, Pool, Process, + Queue, + Value, cpu_count - from multiprocess.managers import SyncManager + ) + from multiprocess.managers import SyncManager # type: ignore else: from concurrent.futures import ProcessPoolExecutor as Pool - from multiprocessing import \ - Pipe, \ - Process, \ - Queue, \ - Value, \ + from multiprocessing import ( + Pipe, + Process, + Queue, + Value, cpu_count + ) from multiprocessing.managers import SyncManager diff --git a/codechecker_common/requirements_py/dev/requirements.txt b/codechecker_common/requirements_py/dev/requirements.txt index b33bcd812c..951166bd10 100644 --- a/codechecker_common/requirements_py/dev/requirements.txt +++ b/codechecker_common/requirements_py/dev/requirements.txt @@ -1,6 +1,6 @@ portalocker~=3.0 coverage<=5.5.0 -mypy<=1.7.1 +mypy~=1.19.0 PyYAML~=6.0 types-PyYAML~=6.0 setuptools~=80.0 diff --git a/codechecker_common/review_status_handler.py b/codechecker_common/review_status_handler.py index 20c40207a3..a189b8dd82 100644 --- a/codechecker_common/review_status_handler.py +++ b/codechecker_common/review_status_handler.py @@ -184,7 +184,7 @@ def __report_matches_rule(self, report: Report, rule: dict): report.checker_name != rule['filters']['checker_name']: return False - if 'report_hash' in rule['filters'] and not \ + if 'report_hash' in rule['filters'] and report.report_hash and not \ report.report_hash.startswith(rule['filters']['report_hash']): return False @@ -211,7 +211,7 @@ def get_review_status(self, report: Report) -> SourceReviewStatus: return review_status # 3. Return "unreviewed" otherwise. - return SourceReviewStatus(bug_hash=report.report_hash) + return SourceReviewStatus(bug_hash=report.report_hash or "") def set_review_status_config(self, config_file): """ @@ -289,7 +289,7 @@ def get_review_status_from_config( message=rule['actions']['reason'] .encode(encoding='utf-8', errors='ignore') if 'reason' in rule['actions'] else b'', - bug_hash=report.report_hash, + bug_hash=report.report_hash or "", in_source=True) return None @@ -343,7 +343,7 @@ def get_review_status_from_source( return SourceReviewStatus( status=status, message=message.encode('utf-8'), - bug_hash=report.report_hash, + bug_hash=report.report_hash or "", in_source=True) if len(src_comment_data) > 1: diff --git a/codechecker_common/tests/Makefile b/codechecker_common/tests/Makefile deleted file mode 100644 index 984afc9d68..0000000000 --- a/codechecker_common/tests/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# Environment variables to run tests. - -CURRENT_DIR = ${CURDIR} -# Root of the repository. -REPO_ROOT ?= $(CURRENT_DIR)/../.. - -MYPY_CMD = mypy --ignore-missing-imports $(REPO_ROOT)/codechecker_common - -mypy: - $(MYPY_CMD) - -mypy_in_env: venv_dev - $(ACTIVATE_DEV_VENV) && $(MYPY_CMD) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..b547b1b141 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[tool.mypy] +verbosity = 1 +show_error_codes = true + +files = [ + "codechecker_common/" +] + +mypy_path = [ + "analyzer/", + "web/", + "tools/report-converter/" +] diff --git a/web/requirements.txt b/web/requirements.txt index cd21c5f769..7316363c30 100644 --- a/web/requirements.txt +++ b/web/requirements.txt @@ -11,6 +11,7 @@ sqlalchemy~=2.0 alembic~=1.5 portalocker~=3.0 psutil~=7.0 +types-psutil~=7.0 multiprocess~=0.70 thrift~=0.22 gitpython~=3.0