name: test-python
on:
  pull_request:
    branches: [ "*" ]
  workflow_call:
  workflow_dispatch:

jobs:
  test_python:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target: [x86_64]
        python-version:
          - "3.10"
          - "3.11"
          - "3.12"
          - "3.13"
          - "3.14"

        # This makes sure that we test with the minimum supported versions
        # of python packages to confirm that the lower bounds on deps are real.
        sync-args: [--locked]
        include:
         - target: x86_64
           python-version: "3.10.0"
           sync-args: --resolution=lowest-direct
      
    steps:
    - uses: actions/checkout@v3
    - name: Install uv
      uses: astral-sh/setup-uv@v7
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install
      run: |
        sudo apt update
        sudo apt install -y gmsh
        uv sync --extra mesh --group dev ${{ matrix.sync-args }}

    - name: Format
      run: |
        uv run --no-sync ruff check ./src
        uv run --no-sync ruff format ./src --check

    - name: Static typing
      run: uv run --no-sync ty check ./src

    - name: Test
      run: uv run --no-sync pytest .

  test_platforms:
    runs-on: ${{ matrix.platform.runner }}
    strategy:
      matrix:
        platform:
          # - runner: windows-latest
          - runner: ubuntu-latest  # Tests wheel install on linux
        #   - runner: ubuntu-24.04-arm  # aarch64
          - runner: macos-15-intel  # x86_64
          - runner: macos-15  # aarch64
    steps:
    - uses: actions/checkout@v6

    - name: Install uv
      uses: astral-sh/setup-uv@v7
      with:
        python-version: "3.10"

    - name: Test
      run: |
        if [ "$RUNNER_OS" = "Linux" ]; then
          sudo apt update
          sudo apt install -y gmsh
        elif [ "$RUNNER_OS" = "macOS" ]; then
          brew install gmsh
        else
          echo "Unsupported runner OS: $RUNNER_OS" >&2
          exit 1
        fi
        uv sync --locked --no-editable --extra mesh --group dev
        uv run --no-sync python -m pytest .