name: Test pip

on:
  push:
    branches: [ master ]
    paths-ignore: 'doc/**'
  pull_request:
    branches: [ master ]
    paths-ignore: 'doc/**'

jobs:
  testpip:
    name: "Pip build test + Python examples test"
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-24.04]
        python-version: [3.12]
    steps:
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Clone w/ submodules
        uses: actions/checkout@v4
        with:
          submodules: recursive
      - name: Update pip and setup venv
        run: |
          python -m pip install --upgrade pip
          python -m venv ~/env
          source ~/env/bin/activate
          pip install numpy scipy pybind11-stubgen
      - name: Debug info Python
        run: |
          source ~/env/bin/activate
          which python
          python --version
          pip --version
      - name: Build and install Arbor using pip + build flags
        run: |
          source ~/env/bin/activate
          CMAKE_ARGS="-DARB_VECTORIZE=ON -DARB_ARCH=native" pip -vvv install .
      - name: Check that build flags match
        run: |
          source ~/env/bin/activate
          python -c "import arbor; print(arbor.config())" | grep -q "'arch': 'native'"
      - name: Run Python tests
        run: |
          source ~/env/bin/activate
          python -m unittest discover -v -s python
      - name: Run Python examples
        run: |
          source ~/env/bin/activate
          scripts/run_python_examples.sh
      - name: Test executables
        run: |
          source ~/env/bin/activate
          scripts/test_executables.sh
