!yamlscript/v0

python-preamble-job =::
  runs-on: ${{matrix.config.os}}
  strategy:
    fail-fast: false
    matrix:
      config:
        - {pythonv: '3.13', os: ubuntu-latest}
        - {pythonv: '3.13', os: macos-13}
python-preamble-job-win =::
  runs-on: ${{matrix.config.os}}
  strategy:
    fail-fast: false
    matrix:
      config:
        - {pythonv: '3.13', os: windows-latest, vsenvarch: x64}


setup-env-win =::
  - name: setup env (Visual Studio)
    uses: TheMrMilchmann/setup-msvc-dev@v3
    with:
      arch: ${{matrix.config.vsenvarch}}


python-preamble-steps =::
  - name: install python ${{matrix.config.pythonv}}
    uses: actions/setup-python@v5
    with:
      python-version: ${{matrix.config.pythonv}}
  - name: deps
    run: |
      if [[ "${{matrix.config.os}}" == macos* ]] ; then
         brew install swig
      elif [[ "${{matrix.config.os}}" == windows* ]] ; then
         choco install swig
      fi
      pip install build deprecation pytest
      pip install -r requirements.txt


defn python-wheel-steps(name create-wheel-cmd)::
  - name:: "------------------- $name"
    run: |
      rm -rf build/ dist/ || echo "no files found"
      pip uninstall -y -v rapidyaml || echo "was not installed"
  - name:: "create wheel with $create-wheel-cmd"
    run:: |
      $create-wheel-cmd
  - name: install wheel
    run: pip install dist/*.whl
  - name: test with pytest
    run: python -m pytest -vvv api/python/tests


python-wheel-tests =::
  - :: python-wheel-steps('using setup.py'   'python setup.py bdist_wheel -v')
  - :: python-wheel-steps('using pip'        'pip wheel -w dist/ .')
  - :: python-wheel-steps('using pypa/build' 'python -m build --wheel')


python-bare-tests =::
  - name: configure
    run: |
      cmake -B build/py \
         -D CMAKE_BUILD_TYPE=Release \
         -D BUILD_SHARED_LIBS=ON \
         -D RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS=ON \
         -D RYML_BUILD_API=ON \
         -D RYML_API_TESTS=ON \
         -D RYML_BUILD_TESTS=ON
  - name: build
    run: |
      cmake --build build/py -j -v --config Release --target ryml-api-python3
      cp -fv api/python/ryml/__init__.py build/py/api/python3/.
      ls -lFpAR build/py/api/python3/
  - name: test with ctest
    run: |
      export PYTHONPATH=`pwd`/build/py/api/python3:$PYTHONPATH
      cmake --build build/py -j -v --config Release --target ryml-api-test-python3
  - name: test with pytest
    run: |
      export PYTHONPATH=`pwd`/build/py/api/python3:$PYTHONPATH
      python -m pytest -vvv api/python/tests


---
!yamlscript/v0:

:use common: :all
:: workflow-setup()

jobs:

  #----------------------------------------------------
  # verify that we can explicitly run the python API
  # without creating or installing a wheel
  pybare:
    :: setup-job('api' 'pybare')
    name: pybare/${{matrix.config.pythonv}}/${{matrix.config.os}}
    :: python-preamble-job
    steps:
    - :: checkout-action
    - :: python-preamble-steps
    - :: python-bare-tests

  #----------------------------------------------------
  # run tests with built+installed wheels
  pywheel:
    :: setup-job('api' 'pywheel')
    name: pywheel/${{matrix.config.pythonv}}/${{matrix.config.os}}
    :: python-preamble-job
    env:
       CMAKE_FLAGS: -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILES=ON
    steps:
    - :: checkout-action
    - :: python-preamble-steps
    - :: python-wheel-tests
  pywheelwin:
    :: setup-job('api' 'pywheel_win')
    name: pywheel/${{matrix.config.pythonv}}/${{matrix.config.os}}
    :: python-preamble-job-win
    env:
       CMAKE_FLAGS: -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILES=ON
    steps:
    - :: checkout-action
    - :: python-preamble-steps
    - :: setup-env-win
    - :: python-wheel-tests
