# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=flit
pkgbase=mingw-w64-python-${_realname}
pkgname=(${MINGW_PACKAGE_PREFIX}-python-$_realname)
pkgver=3.12.0
pkgrel=1
pkgdesc='Simplified packaging of Python modules (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_repository_url='https://github.com/pypa/flit/'
msys2_references=(
  'purl: pkg:pypi/flit'
)
url='https://flit.pypa.io/'
license=('spdx:BSD-3-Clause')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-flit-core"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
  "${MINGW_PACKAGE_PREFIX}-python-tomli-w"
  "${MINGW_PACKAGE_PREFIX}-python-docutils"
)
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-coverage"
              "${MINGW_PACKAGE_PREFIX}-python-responses"
              "${MINGW_PACKAGE_PREFIX}-python-testpath"
              "${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-cov")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-pygments-github-lexers"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx_rtd_theme"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-sphinxcontrib-github-alt")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('1c80f34dd96992e7758b40423d2809f48f640ca285d0b7821825e50745ec3740')

prepare() {
  cd "${_realname}-${pkgver}"
  rm -f tests/test_sdist.py
  cd "flit_core"

  python build_dists.py
}

build() {
  cd "${_realname}-${pkgver}"

  PYTHONPATH=flit_core python -m flit build --format wheel

  cd doc
  make dirhtml man
}

check() {
  cd "${_realname}-${pkgver}"

  # 9 failed, 172 passed, 5 skipped, 1 warning in 13.73s
  PYTHONPATH=flit_core ${MINGW_PREFIX}/bin/python -m pytest  --cov=flit --cov=flit_core/flit_core || true
}

package() {
  cd "${_realname}-${pkgver}"

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

  install -Dm 644 LICENSE "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE

  mkdir -p "$pkgdir${MINGW_PREFIX}"/share/doc/${_realname}
  cp -r doc/_build/dirhtml/* "$pkgdir${MINGW_PREFIX}"/share/doc/${_realname}
  
  mkdir -p "$pkgdir${MINGW_PREFIX}"/share/man/man1
  cp -r doc/_build/man/*.1 "$pkgdir${MINGW_PREFIX}"/share/man/man1
}
