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

_with_rust="yes"
if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then
  # rust doesn't support aarch64-pc-windows-gnu (msys2/CLANG-packages#28)
  # and it apparently hardcodes libgcc (msys2/CLANG-packages#29), so disable
  # it in all clang prefixes
  _with_rust="no"
fi

_realname=cryptography
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.4.7
pkgrel=1
pkgdesc="A package designed to expose cryptographic recipes and primitives to Python developers (mingw-w64)"
url='https://pypi.org/project/cryptography/'
license=('Apache')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-python-cffi"
         "${MINGW_PACKAGE_PREFIX}-python-idna")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
if [ "${_with_rust}" == "yes" ]; then
  makedepends+=("${MINGW_PACKAGE_PREFIX}-python-setuptools-rust")
else
  export CRYPTOGRAPHY_DONT_BUILD_RUST=1
fi
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
              #"${MINGW_PACKAGE_PREFIX}-python-iso8601"
              "${MINGW_PACKAGE_PREFIX}-python-pretend"
              #"${MINGW_PACKAGE_PREFIX}-python-cryptography-vectors"
              "${MINGW_PACKAGE_PREFIX}-python-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python-pytz")
source=(https://pypi.io/packages/source/c/cryptography/${_realname}-${pkgver}.tar.gz
        0002-move-setuptools-rust-import.patch)
sha256sums=('3d10de8116d25649631977cb37da6cbdd2d6fa0e0281d014a5b7d337255ca713'
            '7374d57ae28eefe78394f2d6d983adf7d216c040c3b4bac8e83e4f5132c51fa2')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # don't fail for lack of setuptools-rust if not building rust
  patch -Np1 -i "${srcdir}"/0002-move-setuptools-rust-import.patch
}

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

  ${MINGW_PREFIX}/bin/python setup.py build
}

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

  # ${MINGW_PREFIX}/bin/python setup.py pytest
}

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

  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

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