# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=python-referencing
pkgver=0.35.1
pkgrel=3
pkgdesc='An implementation-agnostic implementation of JSON reference resolution'
arch=(any)
url='https://referencing.readthedocs.io'
license=('MIT')
depends=('python' 'python-attrs' 'python-rpds-py')
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-hatchling'
  'python-hatch-vcs'
)
checkdepends=(
  'python-pytest'
  'python-pytest-subtests'
  'python-jsonschema'
)
source=(
  "$pkgname::git+https://github.com/python-jsonschema/referencing#tag=v$pkgver"
  'github.com-python-jsonschema-referencing-suite::git+https://github.com/python-jsonschema/referencing-suite'
)
sha512sums=('c62e162e5e8f880f2dfbe944e17e664ceb4a266c2fccfcdc6cc236f6da604a97b7a74940e383aac41f4acf091fcb775264e6df4a208bba88c0ed3b7f07c1d5e2'
            'SKIP')
b2sums=('a626c35b9963f0771e615047c5da5edfe6bf4af9c395a6cb919c374ce446ff81f75ec7783d567371dcbc47c1f8d1bf7deeece3c83267c3160c9899806c0db41f'
        'SKIP')

prepare() {
  cd "$pkgname"

  # prepare git submodules
  git submodule init
  git config submodule.suite.url "$srcdir/github.com-python-jsonschema-referencing-suite"
  git -c protocol.file.allow=always submodule update
}

build() {
  cd "$pkgname"

  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  pytest -v
}

package() {
  cd "$pkgname"

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