name: "Python binding"
description: "Binding a python binding"
inputs:
  build_flavor:
    description: "Python package name"
    required: true
  numpy_build:
    description: "NumPy build dependecy"
    required: true
  numpy_dep:
    description: "NumPy runtime dependecy"
    required: true
  local_cflags:
    description: "CFLAGS for Python package"
    required: false
    default: ""
  local_ldflags:
    description: "LDFLAGS for Python package"
    required: false
    default: ""
  local_libs:
    description: "LIBS for Python package"
    required: false
    default: ""
  target:
    description: "TARGET value"
    required: false
    default: "host"
  chroot:
    description: "RASPBIAN value"
    required: false
    default: ""
runs:
  using: "composite"
  steps:
    - run: |
        python3 --version
        pip3 --version
        python3 -m pip install virtualenv
        python3 -m virtualenv deepspeech-build
      shell: bash
    - run: |
        mkdir -p wheels
      shell: bash
    - run: |
        set -xe

        PROJECT_NAME="deepspeech"
        if [ "${{ inputs.build_flavor }}" = "tflite" ]; then
          PROJECT_NAME="deepspeech-tflite"
        fi

        OS=$(uname)
        if [ "${OS}" = "Linux" ]; then
          source deepspeech-build/bin/activate
        fi

        NUMPY_BUILD_VERSION="${{ inputs.numpy_build }}" \
        NUMPY_DEP_VERSION="${{ inputs.numpy_dep }}" \
        EXTRA_CFLAGS=${{ inputs.local_cflags }} \
        EXTRA_LDFLAGS=${{ inputs.local_ldflags }} \
        EXTRA_LIBS=${{ inputs.local_libs }} \
          make -C native_client/python/ \
            TARGET=${{ inputs.target }} \
            RASPBIAN=${{ inputs.chroot }} \
            SETUP_FLAGS="--project_name ${PROJECT_NAME}" \
            bindings-clean bindings

        if [ "${OS}" = "Linux" ]; then
          deactivate
        fi
      shell: bash
    - run: |
        cp native_client/python/dist/*.whl wheels
      shell: bash
    - run: |
        make -C native_client/python/ bindings-clean
      shell: bash
