# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=olefile
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.47
pkgrel=2
pkgdesc="Python library to parse, read and write Microsoft OLE2 files (formerly OleFileIO_PL) (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.decalage.info/olefile"
msys2_repository_url="https://github.com/decalage2/olefile"
msys2_references=(
  'purl: pkg:pypi/olefile'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.zip)
sha256sums=('599383381a0bf3dfbd932ca0ca6515acd174ed48870cbf7fee123d698c192c1c')

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

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${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 doc/LICENSE.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm644 README.md doc/* -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/README"
}
