# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: "pytest: Test Python code"

on:
  push:
    # Only run the code tests if the code actually changed.
    # N.B. paths filters are not evaluated for pushes of tags.
    paths: 
      - 'src/**'
      - 'test/**'
  pull_request:
    branches: [ "main" ]
  workflow_call:
    # Makes the workflow re-usable, callable from other workflows.
    # Mainly for running tests before publishing to PyPi.

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

    steps:
    - uses: actions/checkout@v4
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v6
      with:
        python-version: ${{ matrix.python-version }}
        cache: 'pip' # It takes a minute or so to download the stuff, so we can cache to speed up.
    - name: Install dependencies
      # Make sure we get the CPU-only version of Torch, to save on compile-time.
      run: |
        python -m pip install --upgrade pip setuptools
        python -m pip install flake8 pytest pytest-cov
        python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
        python -m pip install -e .
    - name: Lint with flake8
      run: |
        # stop the build if there are Python syntax errors or undefined names
        flake8 . --count --select=E9,F63,F7,F821,F822,F823 --show-source --statistics
        # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
    - name: Test with pytest
      run: |
        pytest
