# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=python-jsonschema
pkgver=4.23.0
pkgrel=1
pkgdesc='An implementation of JSON Schema validation for Python'
arch=('any')
url='https://github.com/python-jsonschema/jsonschema'
license=('MIT')
depends=(
  'python'
  'python-attrs'
  'python-referencing'
  'python-jsonschema-specifications'
)
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-wheel'
  'python-hatchling'
  'python-hatch-vcs'
  'python-hatch-fancy-pypi-readme'
)
checkdepends=(
  'python-pip'
  'python-twisted'
  'python-isoduration'
  'python-fqdn'
  'python-idna'
  'python-jsonpointer'
  'python-rfc3339-validator'
  'python-rfc3987'
  'python-uri-template'
  'python-webcolors'
)
optdepends=(
  'python-isoduration: for duration format'
  'python-fqdn: for hostname format'
  'python-idna: for idn-hostname format'
  'python-jsonpointer: for json-pointer & relative-json-pointer format'
  'python-rfc3339-validator: for date-time format'
  'python-rfc3987: for iri, iri-reference, uri & uri-reference format'
  'python-uri-template: for uri-template format'
  'python-webcolors: for color format'
)
source=("$pkgname::git+$url#tag=v$pkgver")
sha512sums=('0bff4113408fe14d591ee1ea501587bbec7d52df0d50b9d8e4bedfca9003f934c8c474015f1806f76ab1c6e37a9c22db5aea94d0d5ef889ad02c6d86a62cf19e')
b2sums=('03b9165737b058b1d84be08c5ea11131f69ea77c4c6788eb816689339f7cdf4416cbf8ffc15690ef8917181d94711ad9a55fe5edf11202381002f6a091e4abea')

build() {
  cd "$pkgname"

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

check() {
  cd "$pkgname"

  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  # install to temporary directory
  python -m installer --destdir="$PWD/tmp_install" dist/*.whl

  PYTHONPATH="$PWD/tmp_install$site_packages" \
    JSON_SCHEMA_TEST_SUITE=json trial jsonschema
}

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