*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / dev-python / pymongo / pymongo-3.4.0.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 PYTHON_COMPAT=( python2_7 python3_6 )
7
8 inherit check-reqs distutils-r1
9
10 DESCRIPTION="Python driver for MongoDB"
11 HOMEPAGE="https://github.com/mongodb/mongo-python-driver https://pypi.org/project/pymongo/"
12 SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
13
14 LICENSE="Apache-2.0"
15 SLOT="0"
16 KEYWORDS="amd64 ~hppa x86"
17 IUSE="doc kerberos test"
18 RESTRICT="!test? ( test )"
19
20 RDEPEND="
21         kerberos? ( dev-python/pykerberos[${PYTHON_USEDEP}] )
22 "
23 DEPEND="
24         ${RDEPEND}
25         dev-python/setuptools[${PYTHON_USEDEP}]
26         doc? ( dev-python/sphinx[${PYTHON_USEDEP}] )
27         test? (
28                 dev-python/nose[${PYTHON_USEDEP}]
29                 >=dev-db/mongodb-2.6.0
30         )
31 "
32 DISTUTILS_IN_SOURCE_BUILD=1
33
34 reqcheck() {
35         if use test; then
36                 # During the tests, database size reaches 1.5G.
37                 local CHECKREQS_DISK_BUILD=1536M
38
39                 check-reqs_${1}
40         fi
41 }
42
43 pkg_pretend() {
44         reqcheck pkg_pretend
45 }
46
47 pkg_setup() {
48         reqcheck pkg_setup
49 }
50
51 python_compile_all() {
52         if use doc; then
53                 mkdir html || die
54                 sphinx-build doc html || die
55         fi
56 }
57
58 python_test() {
59         # Yes, we need TCP/IP for that...
60         local DB_IP=127.0.0.1
61         local DB_PORT=27000
62
63         export DB_IP DB_PORT
64
65         local dbpath=${TMPDIR}/mongo.db
66         local logpath=${TMPDIR}/mongod.log
67
68         # Now, the hard part: we need to find a free port for mongod.
69         # We're just trying to run it random port numbers and check the log
70         # for bind errors. It shall be noted that 'mongod --fork' does not
71         # return failure when it fails to bind.
72
73         mkdir -p "${dbpath}" || die
74         while true; do
75                 ebegin "Trying to start mongod on port ${DB_PORT}"
76
77                 LC_ALL=C \
78                 mongod --dbpath "${dbpath}" --smallfiles --nojournal \
79                         --bind_ip ${DB_IP} --port ${DB_PORT} \
80                         --unixSocketPrefix "${TMPDIR}" \
81                         --logpath "${logpath}" --fork \
82                 && sleep 2
83
84                 # Now we need to check if the server actually started...
85                 if [[ ${?} -eq 0 && -S "${TMPDIR}"/mongodb-${DB_PORT}.sock ]]; then
86                         # yay!
87                         eend 0
88                         break
89                 elif grep -q 'Address already in use' "${logpath}"; then
90                         # ay, someone took our port!
91                         eend 1
92                         : $(( DB_PORT += 1 ))
93                         continue
94                 else
95                         eend 1
96                         eerror "Unable to start mongod for tests. See the server log:"
97                         eerror "        ${logpath}"
98                         die "Unable to start mongod for tests."
99                 fi
100         done
101
102         local failed
103         #https://jira.mongodb.org/browse/PYTHON-521, py2.[6-7] has intermittent failure with gevent
104         pushd "${BUILD_DIR}"/../ > /dev/null
105         if [[ "${EPYTHON}" == python3* ]]; then
106                 2to3 --no-diffs -w test
107         fi
108         DB_PORT2=$(( DB_PORT + 1 )) DB_PORT3=$(( DB_PORT + 2 )) esetup.py test || failed=1
109
110         mongod --dbpath "${dbpath}" --shutdown || die
111
112         [[ ${failed} ]] && die "Tests fail with ${EPYTHON}"
113
114         rm -rf "${dbpath}" || die
115 }
116
117 python_install_all() {
118         use doc && local HTML_DOCS=( html/. )
119
120         distutils-r1_python_install_all
121 }