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

_realname=flake8
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.9.2
pkgrel=2
pkgdesc="The modular source code checker: pep8, pyflakes and co"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://flake8.pycqa.org"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-pyflakes"
         "${MINGW_PACKAGE_PREFIX}-python-mccabe"
         "${MINGW_PACKAGE_PREFIX}-python-pycodestyle")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-pytest-runner")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-mock")
source=("${_realname}-$pkgver.tar.gz"::"https://github.com/PyCQA/flake8/archive/${pkgver}.tar.gz")
sha512sums=('d4be223020a1ff47bd831667f2380a1b0aabdf783c34276b93873d6cbb0ac17cd0d7be26e819018660f622198a6d05edc5797ee81996214a98fcdb9f81e46365')

prepare() {
  # disable overly restrictive dependency pinning
  sed -i -e 's/, *< *[0-9=.]*//' flake8-${pkgver}/setup.py

  rm -rf python-build-${CARCH}| true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  msg "Python test for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py pytest
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --root="${pkgdir}" --prefix=${MINGW_PREFIX} --optimize=1
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-${_realname}/LICENSE

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
