# 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=4
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
  0001-jedi-set-3.14-as-supported-environment.patch
)
b2sums=('6d9da16b255a847e8b60e993a1f3907730bfce2918fc4796d0bafa30d5242bb91a567d19a6ae06ad51d562ea5a491a3d7d1740e423b48bc61e8c2fd080fd1de3'
        'SKIP'
        'SKIP'
        '64188f7bfdf2d0a9ef2a9cb43458514ea8ba541423567f8de6cb56e5679a684b1b41fbc526a5f3ef1600294856babfe76363dd21a5808a64828dca25e8723b66')

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

  # https://github.com/davidhalter/jedi/issues/2064
  patch -Np1 -i ${srcdir}/0001-jedi-set-3.14-as-supported-environment.patch
}

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
  # test_find_system_environments, test_string_annotation, test_compiled_signature_annotation_string fail with Python 3.14
  # https://github.com/davidhalter/jedi/issues/2064
  # https://github.com/davidhalter/jedi/issues/2022
  pytest test -k "not test_completion[pytest] \
                  and not test_find_system_environments \
                  and not test_import \
                  and not test_string_annotation \
                  and not test_compiled_signature_annotation_string \
                  and not test_complete_expanduser"
}

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:
