# 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.5
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=('9f24e13d0c4c1ddd818dc86414623f02beb4a2ee7e6df82fa014756f3ea2f7b7202a655250511e29d66b8bf32170780dfeda1b95ef30c051fad832240b40430a')
b2sums=('38a0036954fec71b2878aeb2a32f437a9f787b51ab27cd773289d728371dc2cae556b8d19559dfb3cf001350d15f7256e1b2c1fcc0d0736249905a85b4b469f0')

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"
  pytest test
}

package() {
  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/licenses/LICENSE.txt \
    "$pkgdir"/usr/share/licenses/$pkgname

  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"
}

# vim: ts=2 sw=2 et:
