# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Eli Schwartz <eschwartz@archlinux.org>

pkgname=python-distlib
pkgver=0.4.0
pkgrel=1
pkgdesc='Low-level functions that relate to packaging and distribution of Python software'
arch=(any)
url='https://distlib.readthedocs.io'
license=(PSF-2.0)
depends=(python)
makedepends=(
  git
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(python-tests)
source=("$pkgname::git+https://github.com/pypa/distlib.git#tag=$pkgver")
sha512sums=('90b3116dc80f925bf12680c18ced465fab01a20f59977cdb1fe14ea57e90722794a671b30ae394796ec4d418055f3a5156ef8078299fb184bbbe9c96e5e40acd')
b2sums=('c33d9a20a947daf9ee4ed55c9c8e4785dfc246e8626bba23c3aa36fc2f7c3c342be32d8157131a6e381c12bfa69cf34e8ec2124b1ff3b5d1155b62fecdf5361e')

prepare() {
  cd "$pkgname"

  # do not bundle executables of unknown provenance
  rm distlib/*.exe
}

build() {
  cd "$pkgname"

  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  python -m installer --destdir="$PWD/tmp_install" dist/*.whl
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  export PYTHONPATH="$PWD/tmp_install$site_packages"

  # if it's not relevant, why does it exist?
  # https://github.com/pypa/distlib/commit/93baffeaa1773796d802bb761607a6466790dcba
  export SKIP_EXT_PACKAGE_DATA=1

  python tests/test_all.py
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl
}
