# Maintainer: Johannes Löthberg <johannes@kyriasis.com>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Sébastien Luttringer
# Contributor: Angel Velasquez <angvp@archlinux.org>
# Contributor: Fabio Volpe <volpefabio@gmail.com>

pkgname=python-sphinx
_name=${pkgname#python-}
pkgver=9.1.0
pkgrel=1
pkgdesc='Python documentation generator'
arch=(any)
url=http://www.sphinx-doc.org/
license=(BSD-2-Clause)
depends=(
  python-babel
  python-docutils
  python-imagesize
  python-jinja
  python-packaging
  python-pygments
  python-requests
  python-roman-numerals-py
  python-snowballstemmer
  python-sphinx-alabaster-theme
  python-sphinxcontrib-{{apple,dev,html}help,jsmath,qthelp,serializinghtml}
)
makedepends=(
  git
  python-build
  python-flit-core
  python-installer
)
checkdepends=(
  cython
  imagemagick
  librsvg
  python-defusedxml
  python-psutil
  python-pytest
  python-pytest-xdist
  python-setuptools
  python-typing_extensions
  texlive-{fontsextra,fontsrecommended,latexextra,luatex,xetex}
)
optdepends=(
  'imagemagick: for ext.imgconverter'
  'texlive-fontsextra: for the default admonition title icons in PDF output'
  'texlive-latexextra: for generation of PDF documentation'
)
source=("git+https://github.com/$_name-doc/$_name.git#tag=v$pkgver")
b2sums=('725daf78cbde4d81034927bd50530d426dd6a119416d8984568e252b8b5e546ba8f4e5bba61a303e38e723af75cd38114b37605f1a1b22882f0ae85302fc58f3')

build() {
  cd "$_name"
  python -m build --wheel --skip-dependency-check --no-isolation

  mkdir -p tempinstall
  bsdtar -xf dist/*.whl -C tempinstall
  PYTHONPATH="$PWD/tempinstall" make -C doc man
}

check() {
  cd "$_name"
  # TODO remove test deselection with 9.0.0
  LC_ALL="en_US.UTF-8" python -X dev -X warn_default_encoding -m pytest -vx
}

package() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/"$_name"-$pkgver.dist-info/licenses/LICENSE.rst \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.rst

  cd "$_name"
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dt "$pkgdir"/usr/share/man/man1 doc/_build/man/"$_name"-*.1
}
