# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=commitizen
pkgver=2.18.0
pkgrel=1
pkgdesc="A tool for enforcing descriptive commit messages and version/changelog management"
arch=('any')
url="https://github.com/commitizen-tools/commitizen"
license=('MIT')
depends=(
  'python'
  'python-questionary'
  'python-decli'
  'python-colorama'
  'python-termcolor'
  'python-packaging'
  'python-tomlkit'
  'python-jinja'
  'python-pyaml'
  'python-argcomplete'
  'python-prompt_toolkit'
)
makedepends=('python-pip' 'python-poetry')
#checkdepends=('python-pytest' 'python-pytest-mock' 'python-pytest-freezegun' 'python-pytest-regressions' 'git')
optdepends=()
#checkdepends=(
#  'python-pytest'
#  'python-pytest-mock'
#)
source=("$pkgname-$pkgver.tar.gz::$url/archive//v$pkgver.tar.gz")
b2sums=('a68369276f5c3521bfddc1af438feabccd236e84f2e5161ba523b41c12fc2ede79ab0713925633093b53b16637e720649d2169989dbc66254e36e70371e14e0b')

#prepare() {
  #cd "$pkgname-$pkgver"
  # Skip test that checks the root folder of the repo but as we download the tar ball
  # it would detect aur as its root
  #sed -i'' 's/test_find_git_project_root/skip_find_git_project_root/' tests/test_conf.py
#}

#check() {
#  cd "$pkgname-$pkgver"
#  pytest tests/
#}

build() {
  cd "$pkgname-$pkgver"
  poetry build --format wheel
}

package() {
  cd "$pkgname-$pkgver"

  PIP_CONFIG_FILE=/dev/null pip \
    install \
    --isolated \
    --root="$pkgdir" \
    --ignore-installed \
    --no-deps \
    dist/*.whl

  # delete direct_url.json
  # TODO: figure out $pkgdir in bytecode
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  rm -vf "$pkgdir$site_packages/$pkgname-$pkgver.dist-info/direct_url.json"

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