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

_name=pyproject-api
pkgname=python-pyproject-api
pkgver=1.10.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=('930c32fbbc32724df30b9212c3b7c58839f83bf82502d4c10dca50f8c4a0bd9ee067c6f78865f46919a06514f58f4fac594d6dae7f501efd9398cce4f89d8969')
b2sums=('10243c16f5cf16d1538c4a6d1939d9108e6a34ba153b2c76a1c4663cf0f80affd6c0840d85e47ec10ce43a00f76d50a0caf211097fa5e363ff1e9a39dbd187bc')

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