SUMMARY="Python Build Reasonableness"
DESCRIPTION="PBR is a library that injects some useful and sensible default \
behaviors into your setuptools run.

PBR is only mildly configurable. The basic idea is that there’s a decent way \
to run things and if you do, you should reap the rewards, because then it’s \
simple and repeatable."
HOMEPAGE="https://docs.openstack.org/pbr/latest/
	https://pypi.org/project/pbr/
	https://github.com/openstack-dev/pbr"
COPYRIGHT="2013-2018 OpenStack Contributors"
LICENSE="Apache v2"
REVISION="1"
SOURCE_URI="https://files.pythonhosted.org/packages/source/p/pbr/pbr-$portVersion.tar.gz"
CHECKSUM_SHA256="5fad80b613c402d5b7df7bd84812548b2a61e9977387a80a5fc5c396492b13c9"

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
		\""
	eval "REQUIRES_$pythonPackage=\"
		haiku
		cmd:python$pythonVersion
		\""
BUILD_REQUIRES="$BUILD_REQUIRES
	setuptools_$pythonPackage"
BUILD_PREREQUIRES="$BUILD_PREREQUIRES
	cmd:python$pythonVersion"
done
PROVIDES_python+="
	cmd:pbr2
	"
PROVIDES_python3+="
	cmd:pbr
	"
PROVIDES_python38+="
	cmd:pbr38
	"
PROVIDES_python39+="
	cmd:pbr39
	"

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

		rm -rf "$sourceDir"-$pythonPackage
		cp -a "$sourceDir" "$sourceDir"-$pythonPackage
		cd "$sourceDir"-$pythonPackage

		python=python$pythonVersion
		$python setup.py build
	done
}

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

		cd "$sourceDir"-$pythonPackage

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

		if [ "$pythonPackage" = python ]; then
			mv "$binDir"/pbr "$binDir"/pbr2
		fi
		if [ "$pythonPackage" = python38 ]; then
			mv "$binDir"/pbr "$binDir"/pbr38
		fi
		if [ "$pythonPackage" = python39 ]; then
			mv "$binDir"/pbr "$binDir"/pbr39
		fi

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