# Maintainer: David Runge <dvzrv@archlinux.org>

_name=pyproject-api
pkgname=python-pyproject-api
pkgver=1.6.1
pkgrel=2
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=('18f52273766056de36c499fa62dd2b9228110feff149f5471d16d4569c015648c3113e51fa3925146f55096132ac96bd325e44592bb491b1f885148b2cbdeb38')
b2sums=('de6ea7ddbc203b822a07ebd93da94d4e0a6aaca4ac50eaf725cdb59b29d7379917654a9037314e5666cb22cbe5d65a4095e543491196744c1b6c314127185aba')

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
    # wants python2
    --deselect tests/test_frontend.py::test_can_build_on_python_2
    # probably some setuptools weirdness
    --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/"
}
