# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=libsass
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.23.0
pkgrel=3
pkgdesc='Sass for Python: A straightforward binding of libsass for Python (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/sass/libsass-python'
msys2_references=(
  'pypi: libsass'
)
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-libsass")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer")
options=('!strip')
source=("${_realname}-python-$pkgver.tar.gz::${url}/archive/${pkgver}.tar.gz"
        '0001-libsass-python-0.22.0-setup-msystem.patch')
sha256sums=('4bff7819756f52f6e4592f03f205104d1ca431088d9452aed5042f89a36f9873'
            '1d80f8ff2eda63958e2bb39028d98f8cdacb503882ae7d03c4a7a6b5cdbab9a9')

prepare() {
  cp -r "${_realname}-python-${pkgver}" "python-build-${MSYSTEM}"
  cd "python-build-${MSYSTEM}"

  patch -p1 -i "${srcdir}/0001-libsass-python-0.22.0-setup-msystem.patch"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

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

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

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

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