summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 09f4e2bd78faed7c01e255a2a8eac3a373cf75d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Maintainer: Pellegrino Prevete < pellegrinoprevete@gmail.com >
# Contributor: Marcell Meszaros < marcell.meszaros AT runbox.eu >
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>

_py="python2"
_pkg="requests"
pkgname="${_py}-${_pkg}"
_name="${_pkg}"
_commit='fa1b0a367abc8488542f7ce7c02a3614ad8aa09d'
pkgver=2.27.1.r5.gfa1b0a36
pkgrel=1
pkgdesc='HTTP for Humans (legacy Python 2 version)'
arch=('any')
url="https://pypi.org/project/${_pkg}"
_repourl="https://github.com/psf/${_pkg}"
license=('Apache')
makedepends=('python2-setuptools')
_depends_that_are_checkdepends=(
    'ca-certificates-utils'
    'python2-chardet'
    'python2-idna'
    'python2-urllib3'
)
_checkdepends_needed=(
  "${_py}-flask"
  "${_py}-pytest-mock"
  "${_py}-pytest-httpbin"
  # optional; enables parallel testing, but unavailable
  # "${_py}-pytest-xdist"
  "${_py}-trustme"
)
optdepends=(
  "${_py}-pysocks: SOCKS proxy support (deprecated)")
optdepends+=(
  "${_checkdepends_needed[@]/%/: needed for check() during build}")
_tardirname="${_pkg}-${_commit}"
source=(
  "python-${_pkg}-${pkgver}.tar.gz::${_repourl}/archive/${_commit}.tar.gz"
  'certs.patch')
b2sums=(
  '350b89ec150702b6b1ecb9faa3f20e79977620b828df20b625a422216ff33a040ab561ed07bb14663c5319802f7d37baafcb5752746faf702dd81b1dbb968fc7'
  'b6a7c9796a8ffedebcdbf0d2f95c40b1bbfa0beb45a3c7d5b493a459c4516533992291c720cf02e291cdbbf554dd0bf25c1312f4be41e39acd586b41911ad5b0')

_checkinstalled() {
  pacman --deptest $@
}

prepare() {
  cd "${_tardirname}"

  echo 'Patching setup.py:'
  echo '- removing unnecessary upper version constraints'
  echo "- removing certifi and charset_normalizer requirements"
  sed -e "s/,<.*'/'/" \
      -e '/certifi/d' \
      -e '/charset_normalizer/d' \
      -i 'setup.py'
  echo

  echo "Patching certs.py: use Arch's default ca-certificates.crt"
  patch --verbose \
	-p1 \
	-i "${srcdir}/certs.patch"
  echo

  echo "Changing hashbangs in *.py files to refer to 'python2'"
  sed -e "1s|#![ ]*/[a-zA-Z0-9./_ ]*python.*|#!/usr/bin/env ${_py}|" \
      -i $(find . -name '*.py')
}

build() {
  cd "${_tardirname}"
  "${_py}" setup.py build
}

check() {
  ( _checkinstalled \
        "${_checkdepends_needed[@]}" \
        "${_depends_that_are_checkdepends[@]}" > \
      /dev/null ) || \
    echo "Skipping testing: checkdepends not installed:"; \
    ( _checkinstalled \
          "${_checkdepends_needed[@]}" \
	  "${_depends_that_are_checkdepends[@]}" ) || \
      return 0

  # Seems to be a problem about pytest-httpbin:
  # pytest-httpbin server hit an exception
  # serving request: [SSL: HTTP_REQUEST] http request (_ssl.c:1129)
  # pytest-httpbin server hit an exception serving request:
  # [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:1129)

  cd "${_tardirname}"
  (
    echo '-- Using LC_ALL=C.UTF-8 locale to ensure ' \
	 'UTF-8 filesystem encoding is used in Python 2'

    ( _checkinstalled \
          "${_py}-pysocks" > \
        /dev/null ) || \
      echo '-- Disabling tests for python2-pysocks: not installed'; \
      export \
        _pytest_conditional_options=(
	  -k="not test_use_proxy_from_environment")
    echo

    export LC_ALL=C.UTF-8
    export PYTHONDONTWRITEBYTECODE=1
    export PYTHONPATH="${PWD}/build/lib:${PYTHONPATH}"
    set -x
    pytest2 tests \
        --verbose \
        --cache-clear \
        --deselect \
          'tests/test_requests.py::TestRequests::test_pyopenssl_redirect' \
        "${_pytest_conditional_options[@]}"
  )
}

package() {
  depends=(
    'python2'
    "${_depends_that_are_checkdepends[@]}"
  )
  cd "${_tardirname}"
  python2 setup.py install --root="${pkgdir}" \
	                   --prefix='/usr' \
			   --optimize=1 \
			   --skip-build
  install --verbose \
	  -Dm 644 \
	  'README.md' \
	  -t "${pkgdir}/usr/share/doc/${pkgname}"
}

# vim:set sw=2 sts=-1 et: