# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=spyder
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=6.1.2
pkgrel=1
pkgdesc='The Scientific Python Development Environment (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url='https://www.spyder-ide.org/'
msys2_repository_url='https://github.com/spyder-ide/spyder'
msys2_references=(
  'archlinux: spyder'
  'purl: pkg:pypi/spyder'
)
license=('spdx:MIT')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-aiohttp
    ${MINGW_PACKAGE_PREFIX}-python-atomicwrites
    ${MINGW_PACKAGE_PREFIX}-python-asyncssh
    ${MINGW_PACKAGE_PREFIX}-python-bcrypt
    ${MINGW_PACKAGE_PREFIX}-python-chardet
    ${MINGW_PACKAGE_PREFIX}-python-cloudpickle
    ${MINGW_PACKAGE_PREFIX}-python-cookiecutter
    ${MINGW_PACKAGE_PREFIX}-python-diff-match-patch
    ${MINGW_PACKAGE_PREFIX}-python-importlib-metadata
    ${MINGW_PACKAGE_PREFIX}-python-intervaltree
    ${MINGW_PACKAGE_PREFIX}-python-ipython
    ${MINGW_PACKAGE_PREFIX}-python-jedi
    ${MINGW_PACKAGE_PREFIX}-python-jellyfish
    ${MINGW_PACKAGE_PREFIX}-python-jsonschema
    ${MINGW_PACKAGE_PREFIX}-python-keyring
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbconvert
    ${MINGW_PACKAGE_PREFIX}-python-numpydoc
    ${MINGW_PACKAGE_PREFIX}-python-parso
    ${MINGW_PACKAGE_PREFIX}-python-pexpect
    ${MINGW_PACKAGE_PREFIX}-python-pickleshare
    ${MINGW_PACKAGE_PREFIX}-python-psutil
    ${MINGW_PACKAGE_PREFIX}-python-pygments
    ${MINGW_PACKAGE_PREFIX}-python-pylint
    ${MINGW_PACKAGE_PREFIX}-python-pylint-venv
    ${MINGW_PACKAGE_PREFIX}-python-lsp-black
    ${MINGW_PACKAGE_PREFIX}-python-pyls-spyder
    ${MINGW_PACKAGE_PREFIX}-python-pyqt5
    ${MINGW_PACKAGE_PREFIX}-python-lsp-ruff
    ${MINGW_PACKAGE_PREFIX}-python-lsp-server
    ${MINGW_PACKAGE_PREFIX}-python-pygithub
    ${MINGW_PACKAGE_PREFIX}-python-pyzmq
    ${MINGW_PACKAGE_PREFIX}-python-pyuca
    ${MINGW_PACKAGE_PREFIX}-python-qdarkstyle
    ${MINGW_PACKAGE_PREFIX}-python-qstylizer
    ${MINGW_PACKAGE_PREFIX}-python-qtawesome
    ${MINGW_PACKAGE_PREFIX}-python-qtconsole
    ${MINGW_PACKAGE_PREFIX}-python-qtpy
    ${MINGW_PACKAGE_PREFIX}-python-rtree
    ${MINGW_PACKAGE_PREFIX}-python-setuptools
    ${MINGW_PACKAGE_PREFIX}-python-sphinx
    ${MINGW_PACKAGE_PREFIX}-python-spyder-kernels
    ${MINGW_PACKAGE_PREFIX}-python-superqt
    ${MINGW_PACKAGE_PREFIX}-python-textdistance
    ${MINGW_PACKAGE_PREFIX}-python-three-merge
    ${MINGW_PACKAGE_PREFIX}-python-watchdog
    ${MINGW_PACKAGE_PREFIX}-python-yarl
    ${MINGW_PACKAGE_PREFIX}-qtwebkit
)
optdepends=(
    ${MINGW_PACKAGE_PREFIX}-cython
    ${MINGW_PACKAGE_PREFIX}-python-matplotlib
    ${MINGW_PACKAGE_PREFIX}-python-numpy
    ${MINGW_PACKAGE_PREFIX}-python-pandas
    ${MINGW_PACKAGE_PREFIX}-python-scipy
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-packaging")
options=(!strip)
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz
        spyder-requirements-fix.patch)
sha256sums=('6e09228a17eaa881e761eb3982f22f01d43b6ab5009bb36618b6aa9cffcc978d'
            '0efee114d144c77fa7f5c74a8a2bcef6f5c5b5ed8e478e560bc8a39bae0dfadc')

prepare() {
  cd ${_realname}-${pkgver}

  patch -p1 -i "${srcdir}"/spyder-requirements-fix.patch
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

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

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
