SUMMARY="A HTTP library for Python"
DESCRIPTION="Requests is a HTTP library, written in Python, made for humans."
HOMEPAGE="http://python-requests.org/
	http://pypi.python.org/pypi/requests"
COPYRIGHT="2022 Kenneth Reitz"
LICENSE="Apache v2"
REVISION="1"
SOURCE_URI="https://pypi.io/packages/source/${portName:0:1}/$portName/$portName-$portVersion.tar.gz"
CHECKSUM_SHA256="68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61"
SOURCE_FILENAME="requests-$portVersion.tar.gz"

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\
	ca_root_certificates\n\
	chardet_$pythonPackage\n\
	idna_$pythonPackage\n\
	urllib3_$pythonPackage\n\
	cmd:python$pythonVersion\
	\""
BUILD_REQUIRES="$BUILD_REQUIRES
	setuptools_$pythonPackage"
BUILD_PREREQUIRES="$BUILD_PREREQUIRES
	cmd:python$pythonVersion"
done

REPLACES_python="
	python_requests
	"

INSTALL()
{
	sed -i -e '/certifi/d' -e "s/,<.*'/'/" setup.py
	cp requests/certs.py certs.py.in
	for i in "${!PYTHON_PACKAGES[@]}"; do
		pythonPackage=${PYTHON_PACKAGES[i]}
		pythonVersion=${PYTHON_VERSIONS[$i]}
		pythonPackageName=${portName}_$pythonPackage-$portFullVersion
		pythonLinksDir=$(dirname $portPackageLinksDir)/$pythonPackageName
		certificatePath=$pythonLinksDir/ca_root_certificates/$relativeDataRootDir/ssl/CARootCertificates.pem
		whereDef="def where(): return \"$certificatePath\""

		sed -e 's|from certifi import where|'"$whereDef"'|' \
			certs.py.in > requests/certs.py

		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

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