# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Jelle van der Waa <jelle@archlinux.org>
# Contributor: Danilo Bargen <gezuru@gmail.com>
# Contributor: Simon Conseil <contact+aur at saimon dot org>
# Contributor: Jesus Alvarez

pkgname=python-jedi
pkgver=0.19.2
pkgrel=1
pkgdesc="Awesome autocompletion for python"
arch=('any')
url="https://github.com/davidhalter/jedi"
license=('MIT')
depends=('python' 'python-parso')
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
  'python-sphinx'
  'python-sphinx_rtd_theme'
)
checkdepends=('python-pytest' 'python-parso')
source=(
  "git+https://github.com/davidhalter/jedi.git#tag=v$pkgver"
  git+https://github.com/davidhalter/typeshed.git
  git+https://github.com/davidhalter/django-stubs.git
)
b2sums=('6d9da16b255a847e8b60e993a1f3907730bfce2918fc4796d0bafa30d5242bb91a567d19a6ae06ad51d562ea5a491a3d7d1740e423b48bc61e8c2fd080fd1de3'
        'SKIP'
        'SKIP')

pkgver() {
  cd jedi
  git describe --tags --match 'v*' | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd jedi
  git submodule init
  git config submodule."jedi/third_party/typeshed".url "$srcdir/typeshed"
  git config submodule."jedi/third_party/django-stubs".url "$srcdir/django-stubs"
  git -c protocol.file.allow=always submodule update --recursive
}

build() {
  cd jedi
  python -m build --wheel --skip-dependency-check --no-isolation
  sphinx-build -b text docs docs/_build/text
  sphinx-build -b man docs docs/_build/man
}

check() {
  cd jedi
  # skip pytest 6 test issues https://github.com/davidhalter/jedi/issues/1660
  # these are also skipped in upstream's Travis CI
  HOME=/tmp pytest test -k 'not test_completion[pytest'
}

package() {
  cd jedi
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm 644 CHANGELOG.rst README.rst docs/_build/text/*.txt -t "$pkgdir/usr/share/doc/$pkgname"
  install -Dm 644 docs/_build/man/jedi.1 "$pkgdir/usr/share/man/man1/$pkgname.1"

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

# vim: ts=2 sw=2 et:
