# Maintainer: Marcelo Duarte https://github.com/marcelotduarte
# Maintainer: Frode Solheim <frode@fs-uae.net>
# Contributor: Duong Pham <dthpham@gmail.com>
# Contributor: Lara Maia <dev@lara.click>

_realname=cx-freeze
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-cx_Freeze"
          "${MINGW_PACKAGE_PREFIX}-python-cx_Freeze")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-cx_Freeze"
           "${MINGW_PACKAGE_PREFIX}-python-cx_Freeze")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-cx_Freeze"
          "${MINGW_PACKAGE_PREFIX}-python-cx_Freeze")
pkgver=7.0.0
pkgrel=4
pkgdesc="Creates standalone executables from Python scripts, with the same performance (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
msys2_references=(
  'pypi: cx-Freeze'
)
license=('PSF')
url="https://github.com/marcelotduarte/cx_Freeze/"
options=(!strip)
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-wheel"
  "${MINGW_PACKAGE_PREFIX}-python-cx-logging"
  "${MINGW_PACKAGE_PREFIX}-python-lief"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-wheel"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-tools"
)
checkdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-pytest"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-cov"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-datafiles"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-mock"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-timeout"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-xdist"
  "${MINGW_PACKAGE_PREFIX}-python-psutil"
)
source=(
    https://pypi.io/packages/source/c/cx_Freeze/cx_freeze-${pkgver}.tar.gz
    001-pr2357.patch
    002-pr2363.patch
    003-pr2367.patch
)
sha256sums=(
    'b03f2854a15dd1e8962660d18882a71fefba0e1b6f68337193d4a072d1fc36e6'
    'e2f33a3682057c3c843eb7a8a2f73a20c5908ed4db2ee8d72428f2ee32f6d709'
    'c1f9c150ec40f65bb86213cf01a9e70e0673a84f3600e2afa066606138a9cb8b'
    '11cb23cc61d8dcefb029c91cfbe253c66233d0f4aac6aed4b022110775d79785'
)

prepare() {
  cd "${srcdir}"/cx_Freeze-${pkgver}
  # ignore version check for setuptools
  sed -i 's/"setuptools>=.*"/"setuptools"/' pyproject.toml
  # PR 2357, 2363, 2367
  patch -p1 -i "${srcdir}"/001-pr2357.patch
  patch -p1 -i "${srcdir}"/002-pr2363.patch
  patch -p1 -i "${srcdir}"/003-pr2367.patch

  rm -Rf "${srcdir}"/python-${_realname}-${MSYSTEM}
  cp -a "${srcdir}"/cx_Freeze-${pkgver} "${srcdir}"/python-${_realname}-${MSYSTEM}
}

build() {
  cd python-${_realname}-${MSYSTEM}
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd python-${_realname}-${MSYSTEM}
  ${MINGW_PREFIX}/bin/pip install cx_Freeze -f dist --no-deps --no-index
  ${MINGW_PREFIX}/bin/pytest -nauto --cov="cx_Freeze" --cov-report=xml
}

package() {
  cd python-${_realname}-${MSYSTEM}
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl
}

