# Contributor: Fabian Affolter <fabian@affolter-engineering.ch>
# Maintainer: Fabian Affolter <fabian@affolter-engineering.ch>
pkgname=py-unidecode
_pkgname=Unidecode
pkgver=0.04.21
pkgrel=0
pkgdesc="A Python ASCII transliterations of Unicode text"
url="https://pypi.python.org/pypi/Unidecode"
arch="noarch"
license="GPL-2.0-or-later"
depends="py3-${pkgname#py-}"
makedepends="python2-dev python3-dev py-setuptools"
subpackages="py2-${pkgname#py-}:_py2 py3-${pkgname#py-}:_py3"
source="https://files.pythonhosted.org/packages/source/${_pkgname:0:1}/$_pkgname/$_pkgname-$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	cd "$builddir"
	python2 setup.py build
	python3 setup.py build
}

package() {
	mkdir -p "$pkgdir"

	mkdir -p "$pkgdir"/usr/bin
	ln -s unidecode-3 "$pkgdir"/usr/bin/unidecode
}

_py2() {
	replaces="$pkgname"
	_py python2
}

_py3() {
	_py python3
}

_py() {
	local python="$1"
	local pyver="${1:6:1}"
	pkgdesc="$pkgdesc (for $python)"
	depends="$depends $python"
	install_if="$pkgname=$pkgver-r$pkgrel $python"

	cd "$builddir"
	$python setup.py install --prefix=/usr --root="$subpkgdir"

	# Add version suffix to executable files.
	local path; for path in "$subpkgdir"/usr/bin/*; do
		mv "$path" "$path-$pyver" || return 1
	done
}

sha512sums="33fc546b3eefc4ba5feee90d584e49ccd81dd0ae00671f7e44f43cc3dc8a458b86ed6dbfacba6dac7539112408137fc1db6329cc42f31ee250755d841c7c29c2  Unidecode-0.04.21.tar.gz"
