# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Contributor: Felix Yan <felixonmars@archlinux.org>

pkgname=python-jaraco.context
pkgver=6.1.2
pkgrel=1
pkgdesc="Context managers by jaraco"
arch=('any')
url="https://github.com/jaraco/jaraco.context"
license=('MIT')
depends=('python')
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-setuptools-scm'
  'python-wheel'
)
checkdepends=(
  'python-portend'
  'python-pytest'
)
source=("git+$url.git#tag=v$pkgver")
b2sums=('abc3dbf22c32e76cf010744ed622004b12293407b89ae767aad320f3c7c6aa99b78806c66acd32d012c933fc52e9bf4ca5fd12ec72b7c6c045e938c0fb8a6b1b')

prepare() {
  cd ${pkgname#python-}
  # Undo upstream's license shenanigans, context:
  # https://github.com/coherent-oss/system/issues/22
  # https://github.com/pypa/setuptools/issues/5002
  sed -i '/coherent.licensed/d' pyproject.toml
  git show v6.0.0:LICENSE > LICENSE
}

build() {
  cd ${pkgname#python-}
  python -m build --wheel --no-isolation
}

check() {
  cd ${pkgname#python-}
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  # Deselect doctest that requires missing fixture 'ensure_git'
  test-env/bin/python -m pytest --deselect jaraco/context/__init__.py::jaraco.context.repo_context
}

package() {
  cd ${pkgname#python-}
  python -m installer --destdir "$pkgdir" dist/*.whl
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
