# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

_pyname=gi_docgen
_realname=gi-docgen
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2025.5
pkgrel=1
pkgdesc='Documentation tool for GObject-based libraries (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gnome.pages.gitlab.gnome.org/gi-docgen/'
msys2_repository_url='https://gitlab.gnome.org/GNOME/gi-docgen/'
msys2_changelog_url='https://gitlab.gnome.org/GNOME/gi-docgen/-/blob/main/CHANGES.md'
msys2_references=(
  'archlinux: gi-docgen'
  'gentoo: dev-util/gi-docgen'
  'purl: pkg:pypi/gi-docgen'
)
license=('spdx: Apache-2.0 OR GPL-3.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-jinja"
  "${MINGW_PACKAGE_PREFIX}-python-markdown"
  "${MINGW_PACKAGE_PREFIX}-python-markupsafe"
  "${MINGW_PACKAGE_PREFIX}-python-pygments"
  "${MINGW_PACKAGE_PREFIX}-python-typogrify"
  "${MINGW_PACKAGE_PREFIX}-python-packaging"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-sphinx"
  "${MINGW_PACKAGE_PREFIX}-python-sphinx_rtd_theme"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
checkdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-flake8"
)
options=('!strip')
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('7fb2b5370d99849e52e74e9e584b7eeb5b5a3a95493d6752c88c0d251777f4bf')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_pyname}-$pkgver" "python-build-${MSYSTEM}"
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
  make -C docs
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/flake8 --show-source
}

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

  install -Dm644 LICENSES/Apache-2.0.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/Apache-2.0.txt"
  install -Dm644 LICENSES/GPL-3.0-or-later.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/GPL-3.0-or-later.txt"

  mkdir -p "$pkgdir${MINGW_PREFIX}/share/doc/${_realname}"
  cp -r docs/_build/* "$pkgdir${MINGW_PREFIX}/share/doc/${_realname}"
}
