diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ac65fe26..24239c54 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,10 +27,14 @@ jobs: cache: pip - name: Install dependencies run: | - python -m pip install -U pip + python -m pip install -U pip python -m pip install -e '.[dev]' - name: Check run: ./check.sh + - name: Verify code is unchanged by checks + # Override the default "success()" test: even if check.sh fails, we may still want to log the diffs. + if: ${{ !cancelled() }} + run: git --no-pager diff --exit-code --color documentation: name: Documentation @@ -50,39 +54,63 @@ jobs: sphinx-build -d docs docs/source docs_out --color -W -bhtml tests: - name: "${{ matrix.os.emoji }} ${{ matrix.python.name }}" + name: ${{ matrix.os.emoji }} CPython ${{ matrix.python }}${{ matrix.pytorch && ' +Torch' || '' }}${{ matrix.tensorflow && ' +TF' || '' }} runs-on: ${{ matrix.os.runs-on }} strategy: fail-fast: false matrix: os: - emoji: 🐧 - name: linux - runs-on: [ubuntu-latest] + runs-on: ubuntu-latest - emoji: 🍎 - name: macos - runs-on: [macos-latest] + runs-on: macos-latest + - emoji: 🍎🔵 + runs-on: macos-26-intel - emoji: 🪟 - name: windows - runs-on: [windows-latest] - python: - - name: CPython 3.10 - runs-on: "3.10" - - name: CPython 3.11 - runs-on: "3.11" - - name: CPython 3.12 - runs-on: "3.12" - - name: CPython 3.13 - runs-on: "3.13" - - name: CPython 3.14 - runs-on: "3.14" - - name: CPython 3.15 - runs-on: "3.15-dev" + runs-on: windows-latest + - emoji: 🪟💪 + runs-on: windows-11-arm + python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"] + exclude: + # Python 3.10 doesn't support Windows ARM64. + - os: { runs-on: "windows-11-arm" } + python: "3.10" + # We use the include: section to manage the tensorflow and pytorch tags. + include: + # Add default tensorflow and pytorch "true" tags for all jobs; we'll change them as needed in the + # subsequent rules. (These are processed in order.) + - tensorflow: true + pytorch: true + # Windows ARM64 only supports PyTorch up to Python 3.13. + - os: { runs-on: "windows-11-arm" } + python: "3.14" + pytorch: false + - os: { runs-on: "windows-11-arm" } + python: "3.15" + pytorch: false + # TensorFlow doesn't support Windows ARM64. + - os: { runs-on: "windows-11-arm" } + tensorflow: false + # TensorFlow doesn't support Python 3.15. + - python: "3.15" + tensorflow: false + # The PyTorch version supported by macOS (2.2.2) on Intel doesn't support at least one of the features we + # use (get_default_device). + - os: { runs-on: "macos-26-intel" } + pytorch: false + # macOS on Intel doesn't TensorFlow after 3.12. + - os: { runs-on: "macos-26-intel" } + python: "3.13" + tensorflow: false + - os: { runs-on: "macos-26-intel" } + python: "3.14" + tensorflow: false + steps: - uses: actions/checkout@v7 - uses: actions/setup-python@v7 with: - python-version: ${{ matrix.python.runs-on }} + python-version: ${{ matrix.python }} cache: pip check-latest: true - name: Install dependencies @@ -90,24 +118,17 @@ jobs: python -m pip install -U pip python -m pip install -e '.[dev,tests]' - # We don't include PyTorch or TensorFlow in the dependencies. This is partly because they are large and not - # needed for most users. But it's mostly because the right way to install them depends a lot on the user's - # needs (such as GPU support) and OS. - - # The PyPI versions of PyTorch for Linux include CUDA for Linux, so we use an index with a CPU-only version there. - # For the other OSs, the PyPI versions are CPU-only. - - name: Install PyTorch (Linux CPU) - if: matrix.os.name == 'linux' + # Install PyTorch and TensorFlow. + # + # We don't include PyTorch or TensorFlow in the pyproject-mananged dependencies. This is partly because they + # are large and not needed for most users. But it's mostly because the right way to install them depends a lot + # on the user's needs (such as GPU support) and OS. + - name: Install PyTorch + if: matrix.pytorch run: python -m pip install torch --index-url https://download.pytorch.org/whl/cpu - - name: Install PyTorch (macOS/Windows) - if: matrix.os.name != 'linux' && matrix.python.runs-on != '3.15-dev' - run: python -m pip install torch - # TensorFlow stable (as of this June 2026) only supports up to Python 3.12; see - # https://www.tensorflow.org/install/pip#software_requirements - - name: Install TensorFlow (Python 3.10-3.12) - if: contains(fromJSON('["3.10", "3.11", "3.12"]'), matrix.python.runs-on) + - name: Install TensorFlow + if: matrix.tensorflow run: python -m pip install tensorflow - - name: Tests timeout-minutes: 10 run: python -m pytest diff --git a/pyproject.toml b/pyproject.toml index e8777bc8..76fc58f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,8 +85,8 @@ docs = [ "sphinx-new-tab-link==0.8.2 ; python_version >= '3.12'", ] tests = [ - "numpy==2.4.3 ; python_version >= '3.12'", - "pillow==12.3.0 ; python_version >= '3.12'", + "numpy==2.5.5 ; python_version >= '3.12'", + "pillow==13.0.0 ; python_version >= '3.12'", "pytest==9.2.0", "pytest-cov==7.1.0", "pytest-rerunfailures==16.7", diff --git a/src/mss/screenshot.py b/src/mss/screenshot.py index 3fa4c69e..27a593a4 100644 --- a/src/mss/screenshot.py +++ b/src/mss/screenshot.py @@ -246,7 +246,7 @@ def to_numpy( import numpy as np # noqa: PLC0415 - rv = np.frombuffer(self._raw, dtype=np.uint8).reshape((self.height, self.width, 4)) + rv: np.ndarray = np.frombuffer(self._raw, dtype=np.uint8).reshape((self.height, self.width, 4)) if channels == "BGRA": pass diff --git a/src/tests/test_buffer.py b/src/tests/test_buffer.py index 651469ec..824475aa 100644 --- a/src/tests/test_buffer.py +++ b/src/tests/test_buffer.py @@ -168,7 +168,7 @@ def finalizer() -> None: # \- array_shaped # \- img base = finalizing_buffer(data, finalizer) - array = np.frombuffer(base, dtype=np.uint8) + array: np.ndarray[tuple[int], np.dtype[np.uint8]] = np.frombuffer(base, dtype=np.uint8) array_shaped = array.reshape((320, 200, 4)) mv = memoryview(array) img = Image.frombuffer("RGBA", (320, 200), array_shaped, "raw", "RGBA", 0, 1)