# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: David Runge <dvzrv@archlinux.org>

_name=pyproject-api
pkgname=python-pyproject-api
pkgver=1.8.0
pkgrel=1
pkgdesc="API to interact with the python pyproject.toml based projects"
arch=(any)
url="https://github.com/tox-dev/pyproject-api"
license=(MIT)
depends=(
  python
  python-packaging
)
makedepends=(
  python-build
  python-hatch-vcs
  python-hatchling
  python-installer
  python-wheel
)
checkdepends=(
  python-pytest
  python-pytest-mock
  python-virtualenv
)
source=($_name-$pkgver.tar.gz::$url/archive/refs/tags/$pkgver.tar.gz)
sha512sums=('dbff126fa1e2cc31fd373ff7e51053aeb633fd38f1d678c6afef55cc0b5e235c19b2d79760269912e56114375224715cfc29c8f2f881af80366fe807fe4db6c2')
b2sums=('78ff23046f10a0eb7539ba75ce6b24563834eedf1ba78fdd2db9fb4e8a947df6cdafcfcc0723dfb67251ebf09a29a41bd6583dcb58efc7f5d60e4c75a0bad5d0')

build() {
  cd $_name-$pkgver
  SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    # unclear why that fails
    --deselect tests/test_frontend.py::test_missing_backend
    # probably some setuptools weirdness
    --deselect tests/test_frontend_setuptools.py::test_setuptools_get_requires_for_build_wheel
    # metadata tests for setuptools fail: https://github.com/tox-dev/pyproject-api/issues/153
    --deselect tests/test_frontend_setuptools.py::test_setuptools_prepare_metadata_for_build_wheel
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  pytest "${pytest_options[@]}"
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
