# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Jelle van der Waa <jelle@vdwaa.nl>

# Check compatibility with jedi on potential version bumps
_pkgbase=parso
pkgname=python-parso
pkgver=0.8.4
pkgrel=1
epoch=1
pkgdesc="Python parser that supports error recovery and round-trip parsing for different Python versions"
arch=('any')
url="https://github.com/davidhalter/parso"
license=('MIT')
depends=('python')
makedepends=(
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-sphinx'
  'python-wheel'
)
checkdepends=('python-pytest')
source=("https://github.com/davidhalter/parso/archive/v$pkgver/$_pkgbase-$pkgver.tar.gz")
sha512sums=('da96f0ab6cfbcf2a54ee73262a672bb4d9720aa91fd884a8c17165d597eece97569b7ee87fd7ea1c0be663c0cb2930a66a03b4e305070f59f346485817607db3')
b2sums=('5a8a81f64b20b52cd3349b7bc059621733debfaf5cc271f3e89423d63e4af67391f7740c34b450b2a91fafe34b8986926e8f7c4ca0b8600eafd0171c01e664b0')

build() {
  cd "$_pkgbase-$pkgver"
  python -m build --wheel --skip-dependency-check --no-isolation
  sphinx-build -b text docs docs/_build/text
  sphinx-build -b man docs docs/_build/man
}

check() {
  cd "$_pkgbase-$pkgver"
  # test_python_excetion_matches broke with 3.10 due to exception formatting changes.
  # https://github.com/davidhalter/parso/issues/192
  pytest test -k 'not test_python_exception_matches'
}

package() {
  cd "$_pkgbase-$pkgver"
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm 644 CHANGELOG.rst README.rst docs/_build/text/*.txt -t "$pkgdir/usr/share/doc/$pkgname"
  install -Dm 644 docs/_build/man/parso.1 "$pkgdir/usr/share/man/man1/$pkgname.1"

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/$_pkgbase-$pkgver.dist-info/LICENSE.txt \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.txt
}

# vim: ts=2 sw=2 et:
