# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=python-referencing
pkgver=0.33.0
pkgrel=1
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'
)
_commit='16305060454f89ec04ff6f346704553cb2763f87'
source=(
  "$pkgname::git+https://github.com/python-jsonschema/referencing#commit=$_commit"
  'github.com-python-jsonschema-referencing-suite::git+https://github.com/python-jsonschema/referencing-suite'
)
b2sums=('SKIP'
        'SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

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