# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Maxim Baz <archlinux at maximbaz dot com>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: James Zhu <jameszhu@berkeley.edu>

pkgname=python-black
pkgver=24.10.0
pkgrel=3
pkgdesc='Uncompromising Python code formatter'
arch=(any)
url='https://github.com/psf/black'
license=('MIT')
depends=(
  'python'
  'python-click'
  'python-mypy_extensions'
  'python-packaging'
  'python-pathspec'
  'python-platformdirs'
)
makedepends=(
  'git'
  'python-build'
  'python-hatch-fancy-pypi-readme'
  'python-hatch-vcs'
  'python-hatchling'
  'python-installer'
)
checkdepends=(
  'ipython'
  'python-aiohttp'
  'python-parameterized'
  'python-pytest'
  'python-tokenize-rt'
)
optdepends=(
  'ipython: for Jupyter notebook support'
  'python-tokenize-rt: for Jupyter notebook support'
  'python-aiohttp: for the blackd HTTP server'
  'python-colorama: for colored diffs'
)
source=("$pkgname::git+$url#tag=$pkgver")
sha512sums=('7905c16108722c31a89729185366137ea5e062451dee11147b47c892b44bbe7b4974ea44e90f9cf79c19b022191a037b3ddd4c0d99c8b08b268380dc82c563af')
b2sums=('d6ca6d7f3d0e6067a1fad45f5da5413a062a2930256e9f82c44f1324be956ca503154c06bfe2a10bc9b4e14208d9235ed4b4da6b9812fda3aae47341537d0b40')

build() {
  cd "$pkgname"

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

check() {
  cd "$pkgname"

  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  # https://github.com/psf/black/issues/3251#issuecomment-1236413890
  ulimit -n 2048
  PATH="$PWD/test-env/bin:$PATH" test-env/bin/python -m pytest
}

package() {
  cd "$pkgname"

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

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE

  # vim plugin
  install -Dm644 -t "$pkgdir/usr/share/vim/vimfiles/plugin" plugin/black.vim
  install -Dm644 -t "$pkgdir/usr/share/vim/vimfiles/autoload" autoload/black.vim
}

# vim:set ts=2 sw=2 et:
