# Contributor: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: robertfoster
# Contributor: Ista Zahn <istazahn[at]gmail[dot]com>

_name=pyppeteer
pkgname=python-pyppeteer
pkgver=2.0.0
pkgrel=2
pkgdesc='Headless chrome/chromium automation library'
arch=('any')
url=https://github.com/pyppeteer/pyppeteer
license=('MIT')
depends=(
  'python-appdirs'
  'python-certifi'
  'python-pyee'
  'python-tqdm'
  'python-urllib3'
  'python-websockets'
)
makedepends=('python-build' 'python-installer' 'python-poetry-core')
source=(
  "$url/archive/$pkgver/$_name-$pkgver.tar.gz"
  '0001-importlib-metadata-unused.patch'
)
b2sums=('e9416823963b8a00962662c30319840e3ef155ff87d408dd63ebc9f27b82fde45f1da3518bbf769a939138b491a71ef070b8cf03589c0ee3d07d48b57033bf80'
        '7d6ad627faa850fa1189d35ccc187a290dd7604be3ddf7be6a98406493e5d8ebe913d00820b83b113787082b8d2eab69773549dca2c0cc3a18561405f1c96403')

prepare() {
  cd $_name-$pkgver
  patch --forward --strip=1 --input=../0001-importlib-metadata-unused.patch

  # Remove include list https://github.com/pypa/wheel/issues/92
  sed -i '/^include/,/]/d' pyproject.toml
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/$_name-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
