# 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=8.2.3
pkgrel=4
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=('f567b7278d1df03bc08436a6bab6af35735ef1c528bf47c7028f6645d530cc6bdf9b2580880161cf3104aed0315da7daa1696297937f8741a5bcde71528bdd19')

prepare() {
  sed -e 's|,<0.22||' -i $_name/pyproject.toml # Remove docutils version constraint
}

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 \
    -k "not test_latex_labels \
    and not test_autodoc_special_members \
    and not test_sphinx_directive_parse_content_to_nodes \
    and not test_sphinx_directive_parse_text_to_nodes \
    and not test_autosummary_generate_content_for_module_imported_members \
    and not test_is_invalid_builtin_class"
}

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
}
