# Maintainer : Daniel Bermond <dbermond@archlinux.org>
# Maintainer : Santiago Torres-Arias <santiago@archlinux.org>
# Contributor: Simon Boulay <simon.boulay@alkeona.net>

pkgname=python-breathe
pkgver=5.0.0a5
pkgrel=3
pkgdesc='An extension to reStructuredText and Sphinx to be able to read and render Doxygen xml output'
arch=('any')
url='https://breathe.readthedocs.org/en/latest/'
license=('BSD-3-Clause')
depends=(
    'python'
    'python-docutils'
    'python-pygments'
    'python-sphinx')
makedepends=(
    'python-build'
    'python-flit-core'
    'python-installer'
    'python-setuptools'
    'python-wheel'
    'ruff')
checkdepends=(
    'doxygen'
    'python-pytest')
source=(
  "https://github.com/michaeljones/breathe/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz"
  "$pkgname-fix-tests-boolean-attr-compare.patch"
)
sha512sums=('a1ec41b5f7483a500f1bb09cb94e68b259cbd07820518d478618415eade7fb15596cf298b75311577294c12714033a4269592184e826c4f2dc7f37eb24f1b98a'
            '2ab06c3d7c424bf9637e3ae7dbc2dd9e64a96349d4cb8540062adfcabb62bb0b5147d118b15f52712781e0219a279391aeb4e508ee305569419d7046abeb7ac5')

prepare() {
  cd "breathe-${pkgver}"
  patch -Np1 < ../${pkgname}-fix-tests-boolean-attr-compare.patch
}

build() {
  cd "breathe-${pkgver}"
  make parser
  make format-parser
  python -m build --wheel --no-isolation
}

check() {
  cd "breathe-${pkgver}"
  
  # https://github.com/breathe-doc/breathe/issues/1036#issuecomment-3054012476
  PYTHONPATH="$PWD" pytest \
    --deselect 'tests/test_examples.py::test_example[class]' \
    --deselect 'tests/test_examples.py::test_example[group]' \
    --deselect 'tests/test_examples.py::test_example[headings]'
}

package_python-breathe() {
  python -m installer --destdir="$pkgdir" "breathe-${pkgver}/dist"/*.whl
  
  local _pyver
  _pyver="$(python -c 'import sys; print("%s.%s" %sys.version_info[:2])')"
  install -d -m755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -s "../../../lib/python${_pyver}/site-packages/breathe-${pkgver}.dist-info/licenses/LICENSE" \
    "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
