SUMMARY="Pure python git implementation"
DESCRIPTION="Dulwich is a simple Python implementation of the Git file \
formats and protocols. All functionality is available in pure Python.\
Optional C extensions can be built for improved performance."
HOMEPAGE="https://www.dulwich.io/"
COPYRIGHT="2008-2022 Jelmer Vernooij"
LICENSE="
	Apache v2
	GNU GPL v2
	"
REVISION="1"
SOURCE_URI="https://pypi.python.org/packages/source/${portName:0:1}/dulwich/dulwich-$portVersion.tar.gz"
CHECKSUM_SHA256="dc5498b072bdc12c1effef4b6202cd2a4542bb1c6dbb4ddcfc8c6d53e08b488c"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

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

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"

PYTHON_PACKAGES=(python3 python38 python39)
PYTHON_VERSIONS=(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\n\
	urllib3_python$pythonVersion\
	\""
BUILD_REQUIRES="$BUILD_REQUIRES
	setuptools_$pythonPackage"
BUILD_PREREQUIRES="$BUILD_PREREQUIRES
	cmd:python$pythonVersion
	cmd:gcc$secondaryArchSuffix"
done

PROVIDES_python3="$PROVIDES_python3
	cmd:dul_receive_pack3 = $portVersion
	cmd:dul_upload_pack3 = $portVersion
	cmd:dulwich3 = $portVersion
	"

PROVIDES_python38="$PROVIDES_python38
	cmd:dul_receive_pack38 = $portVersion
	cmd:dul_upload_pack38 = $portVersion
	cmd:dulwich38 = $portVersion
	"

PROVIDES_python39="$PROVIDES_python39
	cmd:dul_receive_pack39 = $portVersion
	cmd:dul_upload_pack39 = $portVersion
	cmd:dulwich39 = $portVersion
	"

# TODO add the gpg python module when it's available
#TEST_REQUIRES=""

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

		#python=$portPackageLinksDir/cmd~python$pythonVersion/bin/python$pythonVersion
		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 $prefix/bin/*; do
				mv $f ${f}3
			done
		fi
		if [ $pythonPackage == python38 ]; then
			for f in $prefix/bin/*; do
				mv $f ${f}38
			done
		fi
		if [ $pythonPackage == python39 ]; then
			for f in $prefix/bin/*; do
				mv $f ${f}39
			done
		fi
		packageEntries $pythonPackage \
			$prefix/lib/python* \
			$prefix/bin
	done
}

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

		python=python$pythonVersion
		$python -m unittest dulwich.tests.test_suite
	done
}
