pkgname=julia-git-pycall-src
pkgver=1.96.4
_commit=e54c4ee3962f423a4c77fbc8afc20f5fb66296c3
pkgrel=7
pkgdesc="PyCall.jl"
url="https://github.com/JuliaPy/PyCall.jl.git"
arch=(aarch64 armv7h x86_64)
license=('MIT')
makedepends=(git julia-pkg-scripts julia-git-conda-src julia-git-json-src
             julia-git-parsers-src julia-git-versionparsing-src)
depends=(julia-git python)
source=("git+https://github.com/JuliaPy/PyCall.jl.git#commit=$_commit"
        0001-Acquire-GIL-around-every-Python-API-call.patch
        0002-Add-deferred-release-queue-for-PyObject-finalizers.patch
        0003-Wrap-GIL-acquire-release-in-ReentrantLock.patch)
sha256sums=('5660913663e8c7f1151b6e6fc4a55e8e4f15794a8f583ac384ebed593f08abb1'
            'f23e159810bb13391bed3693d4a98a44f2bfae342a4136149359a077e9b322e1'
            '2bf5b0db502f9760a8bcc33897a5e798466d707f6ff9a7afe65dfaf8416e321e'
            '2230c658c61c9b8e7612115af923c701ebe6910434ce4dc7857407254a137aff')

prepare() {
  cd PyCall.jl

  patch -Np1 --no-backup-if-mismatch < ../0001-Acquire-GIL-around-every-Python-API-call.patch
  patch -Np1 --no-backup-if-mismatch < ../0002-Add-deferred-release-queue-for-PyObject-finalizers.patch
  patch -Np1 --no-backup-if-mismatch < ../0003-Wrap-GIL-acquire-release-in-ReentrantLock.patch
}

build() {
  cd PyCall.jl/deps

  JULIA_DEPOT_PATH="${srcdir}/.julia" julia --startup-file=no build.jl
}

package() {
  cd PyCall.jl

  JULIA_INSTALL_SRCPKG=1 . /usr/lib/julia/julia-install-pkg.sh PyCall "${pkgdir}" "${pkgname}" julia-git

  pymin_ver=$(python -c 'import sys; print(sys.version_info.minor)')
  ((pynext_min=pymin_ver + 1))
  depends+=("python>=3.${pymin_ver}.0" "python<3.${pynext_min}.0")
}
