# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=librosa
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.11.0
pkgrel=1
pkgdesc='Python library for music and audio analysis (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url="https://librosa.org/"
msys2_repository_url="https://github.com/librosa/librosa"
msys2_references=(
  'purl: pkg:pypi/librosa'
)
license=('spdx:ISC')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-audioread"
  "${MINGW_PACKAGE_PREFIX}-python-numba"
  "${MINGW_PACKAGE_PREFIX}-python-numpy"
  "${MINGW_PACKAGE_PREFIX}-python-scipy"
  "${MINGW_PACKAGE_PREFIX}-python-scikit-learn"
  "${MINGW_PACKAGE_PREFIX}-python-joblib"
  "${MINGW_PACKAGE_PREFIX}-python-decorator"
  "${MINGW_PACKAGE_PREFIX}-python-soundfile"
  "${MINGW_PACKAGE_PREFIX}-python-pooch"
  "${MINGW_PACKAGE_PREFIX}-python-soxr"
  "${MINGW_PACKAGE_PREFIX}-python-typing_extensions"
  "${MINGW_PACKAGE_PREFIX}-python-lazy-loader"
  "${MINGW_PACKAGE_PREFIX}-python-msgpack"
  "${MINGW_PACKAGE_PREFIX}-python-standard-aifc"
  "${MINGW_PACKAGE_PREFIX}-python-standard-sunau"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
)
options=('!strip')
source=("${msys2_repository_url}/archive/${pkgver}/${_realname}-$pkgver.tar.gz")
sha256sums=('6af22600c52e5b844cf73c699b7c0905ed9fe0b9f17b230eec697bce3368dd15')

prepare() {
  cd "$srcdir"
  rm -rf python-build-${MSYSTEM} || true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "python-build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/python" -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "python-build-${MSYSTEM}"

  # Simple test according to README
  PYTHONPATH=. "${MINGW_PREFIX}/bin/python" -c 'import librosa; librosa.show_versions()'
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    "${MINGW_PREFIX}/bin/python" -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE.md "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.md"
}
