SUMMARY="Universal Character Encoding Detector"
DESCRIPTION="Python module for character encoding auto-detection."
HOMEPAGE="https://github.com/chardet/chardet"
COPYRIGHT="2011-2022 Mark Pilgrim, Dan Blanchard"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://pypi.io/packages/source/${portName:0:1}/$portName/${portName}-$portVersion.tar.gz"
CHECKSUM_SHA256="0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"

ARCHITECTURES="any"

PROVIDES="
	$portName = $portVersion
	"
REQUIRES="
	haiku
	"

BUILD_REQUIRES="
	haiku_devel
	"

PYTHON_PACKAGES=(python python3 python38 python39)
PYTHON_VERSIONS=(2.7 3.7 3.8 3.9)
for i in "${!PYTHON_PACKAGES[@]}"; do
pythonPackage=${PYTHON_PACKAGES[i]}
pythonVersion=${PYTHON_VERSIONS[$i]}
eval "PROVIDES_${pythonPackage}=\"\
	${portName}_$pythonPackage = $portVersion\
	\"; \
REQUIRES_$pythonPackage=\"\
	haiku\n\
	cmd:python$pythonVersion\
	\""
BUILD_REQUIRES="$BUILD_REQUIRES
	setuptools_$pythonPackage"
BUILD_PREREQUIRES="$BUILD_PREREQUIRES
	cmd:python$pythonVersion"
done

PROVIDES_python="$PROVIDES_python
	cmd:chardetect
	"
PROVIDES_python3="$PROVIDES_python3
	cmd:chardetect3
	"
PROVIDES_python38="$PROVIDES_python38
	cmd:chardetect3.8
	"
PROVIDES_python39="$PROVIDES_python39
	cmd:chardetect3.9
	"

INSTALL()
{
	for i in "${!PYTHON_PACKAGES[@]}"; do
		pythonPackage=${PYTHON_PACKAGES[i]}
		pythonVersion=${PYTHON_VERSIONS[$i]}

		python=python$pythonVersion
		installLocation=$prefix/lib/$python/vendor-packages/
		export PYTHONPATH=$installLocation:$PYTHONPATH
		mkdir -p $installLocation
		rm -rf build
		$python setup.py build install \
			--root=/ --prefix=$prefix

		if [ $pythonPackage = python3 ]; then
			for f in $binDir/*; do
				mv $f ${f}3
			done
		fi

		if [ $pythonPackage = python38 ]; then
			for f in $binDir/*; do
				mv $f ${f}3.8
			done
		fi

		if [ $pythonPackage = python39 ]; then
			for f in $binDir/*; do
				mv $f ${f}3.9
			done
		fi

		packageEntries  $pythonPackage \
			$prefix/lib/python* \
			$binDir
	done
}
