# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=python-apipkg
pkgver=3.0.2
_commit=9d3f894a53da084961aeb7e298c38f7d889b1cfc
pkgrel=4
pkgdesc="Namespace control and lazy-import mechanism"
arch=('any')
license=('MIT')
url="https://github.com/pytest-dev/apipkg"
depends=('python')
makedepends=('git' 'python-build' 'python-installer' 'python-hatchling' 'python-hatch-vcs')
checkdepends=('python-pytest')
source=("git+https://github.com/pytest-dev/apipkg.git#commit=$_commit")
sha512sums=('SKIP')

build() {
  cd apipkg
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    # NOTE: these tests are likely broken because of circular deps with python-py
    --deselect test_apipkg.py::test_chdir_with_relative_imports_support_lazy_loading
    --deselect test_apipkg.py::test_get_distribution_version
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd apipkg
  python -m installer --destdir=test_dir dist/*.whl
  PYTHONPATH="test_dir/$site_packages" \
    pytest -vv "${pytest_options[@]}"
}

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