# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

pkgname=python-tokenize-rt
_name=${pkgname#python-}
pkgver=5.2.0
pkgrel=2
pkgdesc='Wrapper around the stdlib `tokenize` which roundtrips'
arch=('any')
url=https://github.com/asottile/tokenize-rt
license=('MIT')
depends=('python')
makedepends=('python-build' 'python-installer' 'python-setuptools'
             'python-wheel')
checkdepends=('python-pytest')
source=("$url/archive/v$pkgver/$_name-$pkgver.tar.gz")
b2sums=('a81251b6b8b336a6b1b1095e0b31456e834196fc2174958299ac293e5fc979dcdd2b4fc9c7e2e231e73fd09e116d0538dadf9436b4efdcf1390b2db9a025a4b8')

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

check() {
  cd "$_name"-$pkgver
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest
}

package() {
  cd "$_name"-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl

  # 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"/"${_name//-/_}"-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
