# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Jelle van der Waa <jelle@archlinux.org>
# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Maintainer: Sébastien Luttringer

pkgname=python-psutil
pkgver=6.1.0
pkgrel=1
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
pkgdesc='A cross-platform process and system utilities module for Python'
url='https://github.com/giampaolo/psutil'
license=('BSD-3-Clause')
depends=(
  'glibc'
  'python'
)
makedepends=(
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
checkdepends=(
  'net-tools'
  'procps-ng'
  'python-pytest'
)
source=(
  "$pkgname-$pkgver.tar.gz::$url/archive/release-$pkgver.tar.gz"
  "dont-package-tests.patch"
)
sha512sums=('7dc755c62ad4607b3f34dd60701be86836f9226ac305387205a9dbf2837b6fded6d71f4919323a4e6b77308f9851db560f1bebedb2ae9a9e5fc59ee3adbc4538'
            'bc902748c8de706a2196f8a19801314f11035c17c8ad406330ba54f821c3ba9144c49d9b7e305d56500576993162c6d148f7db9cf0c61d4fd23b4d85adb3d461')

prepare() {
  cd psutil-release-$pkgver
  patch -Np1 -i ../dont-package-tests.patch
}

build() {
  cd psutil-release-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd psutil-release-$pkgver
  python -m installer --destdir=tmp_install dist/*.whl
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  cp -r psutil/tests "$PWD/tmp_install/$site_packages/psutil"
  cd "$PWD/tmp_install/$site_packages"
  # Deselect tests failing in a chroot - not sure why.
  pytest \
    --config-file=/dev/null \
    --rootdir="$PWD" \
    --deselect psutil/tests/test_connections.py::TestSystemWideConnections::test_multi_sockets_procs \
    --deselect psutil/tests/test_linux.py::TestRootFsDeviceFinder::test_against_findmnt \
    --deselect psutil/tests/test_linux.py::TestRootFsDeviceFinder::test_comparisons \
    --deselect psutil/tests/test_linux.py::TestRootFsDeviceFinder::test_disk_partitions_mocked \
    --deselect psutil/tests/test_linux.py::TestSystemNetIfAddrs::test_ips \
    --deselect psutil/tests/test_system.py::TestMiscAPIs::test_users
}

package() {
  cd psutil-release-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}

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