From e08f77db7db7b99a742a73047b858cf165e8c263 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Mon, 4 Mar 2024 17:23:47 +0000 Subject: [PATCH 1/4] Mypy: remove --no-site-packages option --- .github/workflows/conda.yml | 3 +-- .github/workflows/cos7_testing.yml | 3 +-- .github/workflows/u18_testing.yml | 3 +-- .github/workflows/windows.yml | 3 +-- .pre-commit-config.yaml | 2 +- Makefile | 2 +- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/conda.yml b/.github/workflows/conda.yml index 3a597155ffc..a06e141bd86 100644 --- a/.github/workflows/conda.yml +++ b/.github/workflows/conda.yml @@ -92,9 +92,8 @@ jobs: - name: mypy shell: bash -l {0} - # COMPAT: applitools has some bad signatures, so use --no-site-packages run: | - mypy --ignore-missing-imports --no-site-packages mantidimaging + mypy --ignore-missing-imports mantidimaging - name: pytest timeout-minutes: 10 diff --git a/.github/workflows/cos7_testing.yml b/.github/workflows/cos7_testing.yml index 67cecbd5a51..17b84191b35 100644 --- a/.github/workflows/cos7_testing.yml +++ b/.github/workflows/cos7_testing.yml @@ -40,8 +40,7 @@ jobs: - name: mypy uses: ./.github/actions/test with: - # COMPAT: applitools has some bad signatures, so use --no-site-packages - command: mypy --ignore-missing-imports --no-site-packages mantidimaging + command: mypy --ignore-missing-imports mantidimaging label: centos7 - name: pytest diff --git a/.github/workflows/u18_testing.yml b/.github/workflows/u18_testing.yml index 3c4510f6fbf..7c9e1160af5 100644 --- a/.github/workflows/u18_testing.yml +++ b/.github/workflows/u18_testing.yml @@ -39,8 +39,7 @@ jobs: - name: mypy uses: ./.github/actions/test with: - # COMPAT: applitools has some bad signatures, so use --no-site-packages - command: mypy --ignore-missing-imports --no-site-packages mantidimaging + command: mypy --ignore-missing-imports mantidimaging label: ubuntu18 - name: pytest diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 7625d3b338a..e3b6ed8711f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -79,9 +79,8 @@ jobs: - name: mypy shell: bash -l {0} - # COMPAT: applitools has some bad signatures, so use --no-site-packages run: | - mypy --ignore-missing-imports --no-site-packages mantidimaging + mypy --ignore-missing-imports mantidimaging - name: pytest timeout-minutes: 10 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f48d4923e4c..a4139d61f34 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: hooks: - id: mypy files: ^mantidimaging/ - args: [--ignore-missing-imports, --no-site-packages] + args: [--ignore-missing-imports] - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.3.2 hooks: diff --git a/Makefile b/Makefile index bfb35461c70..9b2415ebb1f 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ test-screenshots-win: @echo "Screenshots writen to" ${TEST_RESULT_DIR} mypy: - python -m mypy --ignore-missing-imports --no-site-packages ${SOURCE_DIRS} + python -m mypy --ignore-missing-imports ${SOURCE_DIRS} yapf: python -m yapf --parallel --diff --recursive ${SOURCE_DIRS} From 665375502278627b8428f595505a8761304d8a11 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Mon, 4 Mar 2024 17:31:33 +0000 Subject: [PATCH 2/4] Add stubs for mypy --- .pre-commit-config.yaml | 1 + environment-dev.yml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4139d61f34..5f209effd08 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,6 +22,7 @@ repos: - id: mypy files: ^mantidimaging/ args: [--ignore-missing-imports] + additional_dependencies: [types-docutils, types-PyYAML, types-requests] - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.3.2 hooks: diff --git a/environment-dev.yml b/environment-dev.yml index 127bd1e56b9..df0753943f4 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -17,6 +17,9 @@ dependencies: - eyes-images==5.20.* - yapf==0.40.* - mypy==1.8 + - types-requests + - types-PyYAML + - types-docutils - pytest==7.4.* - pytest-cov==4.1.* - pytest-randomly==3.15.* From 904a3a116c4d4068a75bf64c2f9f5c44eca0d133 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Mon, 4 Mar 2024 17:37:20 +0000 Subject: [PATCH 3/4] Add work around for invalid type signature in applitools --- mantidimaging/eyes_tests/eyes_manager.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mantidimaging/eyes_tests/eyes_manager.py b/mantidimaging/eyes_tests/eyes_manager.py index f659cc60a4c..a9f3cac4cd6 100644 --- a/mantidimaging/eyes_tests/eyes_manager.py +++ b/mantidimaging/eyes_tests/eyes_manager.py @@ -6,16 +6,23 @@ import os import sys from tempfile import mkdtemp +from typing import TYPE_CHECKING, Any from unittest import mock from uuid import uuid4 from PyQt5.QtWidgets import QWidget, QApplication from PyQt5.QtTest import QTest -from applitools.common import BatchInfo, MatchLevel -from applitools.images import Eyes from mantidimaging.gui.windows.main import MainWindowView +# COMPAT: applitools has some bad signatures, so avoid importing it when type checking +# See https://github.com/mantidproject/mantidimaging/issues/2008 +if not TYPE_CHECKING: + from applitools.common import BatchInfo, MatchLevel + from applitools.images import Eyes +else: + MatchLevel = Any + # Used to disabiguate tests on the Applitools platform. set explicitly to avoid depending on the window size VIEWPORT_WIDTH = 1920 VIEWPORT_HEIGHT = 1080 From ac8fa2129152a2cc8f973eca6dc99987de042a86 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Mon, 11 Mar 2024 17:13:06 +0000 Subject: [PATCH 4/4] Release notes --- docs/release_notes/next/dev-2008-mypy-site-packages | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/release_notes/next/dev-2008-mypy-site-packages diff --git a/docs/release_notes/next/dev-2008-mypy-site-packages b/docs/release_notes/next/dev-2008-mypy-site-packages new file mode 100644 index 00000000000..6939d34696b --- /dev/null +++ b/docs/release_notes/next/dev-2008-mypy-site-packages @@ -0,0 +1 @@ +#2008: Update mypy, remove --no-site-packages, fix issues