# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

_pkgname=build
pkgname=python-$_pkgname
pkgver=1.2.1
pkgrel=1
pkgdesc='A simple, correct Python build frontend'
arch=('any')
url='https://github.com/pypa/build'
license=('MIT')
depends=('python-packaging' 'python-pyproject-hooks')
makedepends=(
  'git' 'python-build' 'python-flit-core' 'python-installer'
  'python-sphinx' 'python-sphinx-argparse-cli' 'python-sphinx-autodoc-typehints' 'python-sphinx-furo' 'python-sphinx-issues'
)
checkdepends=(
  'python-pytest' 'python-pytest-mock' 'python-pytest-rerunfailures'
  'python-filelock' 'python-setuptools' 'python-uv' 'python-virtualenv' 'python-wheel'
)
optdepends=(
  'python-pip: to use as the Python package installer (default)'
  'python-uv: to use as the Python package installer'
  'python-virtualenv: to use virtualenv for build isolation'
)
source=("$pkgname::git+$url#tag=$pkgver?signed")
validpgpkeys=(
#  '3DCE51D60930EBA47858BA4146F633CBB0EB4BF2' # Filipe Laíns (FFY00) <lains@archlinux.org>
  '2FDEC9863E5E14C7BC429F27B9D0E45146A241E8' # Henry Schreiner <henryschreineriii@gmail.com>
)
b2sums=('891acaf857efc18c210648a681c8499a47b6fe5ba58176d026bdfeffce665de26cd17580fcace2fb5970b2f21a37127ea73c196a5a2b8510dd84f6b873217c17')

build() {
  cd $pkgname

  python -m build --wheel --skip-dependency-check --no-isolation

  PYTHONPATH=src sphinx-build -b dirhtml -v docs docs-output
}

check() {
  cd $pkgname

  PYTHONPATH=src pytest -k 'not test_verbose_output'
}

package() {
  cd $pkgname

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

  install -d "$pkgdir"/usr/share/doc/$pkgname
  cp -r docs-output/* "$pkgdir"/usr/share/doc/$pkgname

  # 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"/$_pkgname-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
