# Packager = Tuxcore <dev@tuxcore.org> 
_name=urllib3
pkgname=python-urllib3
pkgver=1.26.20
pkgrel=4
pkgdesc="HTTP library with thread-safe connection pooling and file post support"
arch=("any")
url="https://github.com/urllib3/urllib3"
license=("MIT")
depends=('python')
makedepends=(
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
checkdepends=(
  'python-brotli'
  'python-certifi'
  'python-cryptography'
  'python-dateutil'
  'python-flaky'
  'python-gcp-devrel-py-tools'
  'python-idna'
  'python-pyopenssl'
  'python-pysocks'
  'python-pytest'
  'python-pytest-freezer'
  'python-pytest-timeout'
  'python-tornado'
  'python-trustme'
)
optdepends=(
  'python-brotli: Brotli support'
  'python-certifi: security support'
  'python-cryptography: security support'
  'python-idna: security support'
  'python-pyopenssl: security support'
  'python-pysocks: SOCKS support'
)
source=("$url/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('63c4263c5e61adf28344e79b6c864c70e555b715a93e735aca5b6e169f041f3e4518961993c86c83dd13bcb149f7dd77b6e90140cf4aa2310c14fcaa0a52179b')

prepare() {
  # remove python-mock requirement
  find $_name-$pkgver -type f -iname "*.py" -exec sed 's/import mock/from unittest import mock/; s/from mock/from unittest.mock/' -i {} +
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    --deselect=test/contrib/test_pyopenssl.py::TestClientCerts::test_missing_client_certs_raises_error
    --deselect=test/contrib/test_pyopenssl.py::TestHTTPS::test_client_no_intermediate
    --deselect=test/contrib/test_pyopenssl.py::TestHTTPS_TLSv1_3::test_client_no_intermediate
    --deselect=test/contrib/test_pyopenssl.py::TestSSL::test_ssl_read_timeout
    --deselect=test/with_dummyserver/test_socketlevel.py::TestSSL::test_ssl_read_timeout
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  pytest "${pytest_options[@]}"
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE.txt
}
