name: Python package

on: [push]

env:
  UV_LINK_MODE: "symlink"

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
        include:
          - python-version: "3.8"
            numpy-version: "<2.0"
            torch-version: "disable"
            torch-pip: "torch==1.13.1+cpu torchvision==0.14.1+cpu --index-url https://download.pytorch.org/whl/cpu"

          - python-version: "3.12"
            numpy-version: ">=2.0"
    steps:
      - uses: actions/checkout@v4

      - name: Install uv
        uses: astral-sh/setup-uv@v5
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install specific numpy version
        if: matrix.numpy-version != ''
        run: uv pip install "numpy${{ matrix.numpy-version }}"

      - name: Install w/specific PyTorch version
        if: ( matrix.torch-version != '' ) && ( matrix.torch-version != 'disable' )
        run: uv sync --extra video --extra dev --extra ${{ matrix.torch-version }}

      - name: Install w/CPU PyTorch version
        if: matrix.torch-version != 'disable'
        run: uv sync --extra video --extra dev --extra cpu
      
      - name: Install w/o PyTorch
        if: matrix.torch-version == 'disable'
        run: uv sync --extra video --extra dev

      - name: Install PyTorch w/Pip
        if: matrix.torch-pip != ''
        run: uv pip install ${{ matrix.torch-pip }}

      # We intentionally run again since some envs force specific numpy versions in this way.
      - name: Install specific numpy version
        if: matrix.numpy-version != ''
        run: uv pip install "numpy${{ matrix.numpy-version }}"

      - name: Install opencv headless
        run: uv pip uninstall opencv-python && uv pip install opencv-python-headless

      - name: Test with pytest
        run: uv run pytest

      # - name: Test with Black
      #   run: uv run black --check .