# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Daniel M. Capella <polyze@archlinux.org>
# Contributor: eolianoe <eolianoe At GoogleMAIL DoT com>

pkgname=python-atomicwrites
pkgver=1.4.1
pkgrel=5
pkgdesc="Atomic file writes on POSIX"
arch=(any)
url="https://github.com/untitaker/python-atomicwrites"
license=('MIT')
depends=('python')
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
checkdepends=('python-pytest')
source=("git+$url.git#tag=$pkgver")
b2sums=('f68f329a809720b64a5d86c2faac9898bbedbccd9052f621da75dc32e74ccb8b00985862453f3b10c6e14335eac3c02ba1f7e6500f7d58e4bc226199796c880e')

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

check() {
  cd "${pkgname}"
  export PYTHONPATH="build:${PYTHONPATH}"
  pytest -v
}

package() {
  cd "${pkgname}"
  python -m installer --destdir="${pkgdir}" dist/*.whl
  install -vDm 644 README.rst -t "${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#python-}-${pkgver}.dist-info/LICENSE" \
    "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
