dev-python/pytest: arm64 stable (bug #723996)
[gentoo.git] / dev-lang / python / python-3.8.2-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="7"
5 WANT_LIBTOOL="none"
6
7 inherit autotools flag-o-matic pax-utils python-utils-r1 toolchain-funcs
8
9 MY_P="Python-${PV}"
10 PYVER=$(ver_cut 1-2)
11 PATCHSET="python-gentoo-patches-3.8.1-r2"
12
13 DESCRIPTION="An interpreted, interactive, object-oriented programming language"
14 HOMEPAGE="https://www.python.org/"
15 SRC_URI="https://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz
16         https://dev.gentoo.org/~mgorny/dist/python/${PATCHSET}.tar.xz"
17 S="${WORKDIR}/${MY_P}"
18
19 LICENSE="PSF-2"
20 SLOT="${PYVER}"
21 KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~m68k ~mips ~ppc ppc64 ~riscv ~s390 ~sparc x86"
22 IUSE="bluetooth build examples gdbm hardened ipv6 libressl +ncurses +readline sqlite +ssl test tk wininst +xml"
23 RESTRICT="!test? ( test )"
24
25 # Do not add a dependency on dev-lang/python to this ebuild.
26 # If you need to apply a patch which requires python for bootstrapping, please
27 # run the bootstrap code on your dev box and include the results in the
28 # patchset. See bug 447752.
29
30 RDEPEND="app-arch/bzip2:=
31         app-arch/xz-utils:=
32         dev-libs/libffi:=
33         sys-apps/util-linux:=
34         >=sys-libs/zlib-1.1.3:=
35         virtual/libcrypt:=
36         virtual/libintl
37         gdbm? ( sys-libs/gdbm:=[berkdb] )
38         ncurses? ( >=sys-libs/ncurses-5.2:= )
39         readline? ( >=sys-libs/readline-4.1:= )
40         sqlite? ( >=dev-db/sqlite-3.3.8:3= )
41         ssl? (
42                 !libressl? ( dev-libs/openssl:= )
43                 libressl? ( dev-libs/libressl:= )
44         )
45         tk? (
46                 >=dev-lang/tcl-8.0:=
47                 >=dev-lang/tk-8.0:=
48                 dev-tcltk/blt:=
49                 dev-tcltk/tix
50         )
51         xml? ( >=dev-libs/expat-2.1:= )"
52 # bluetooth requires headers from bluez
53 DEPEND="${RDEPEND}
54         bluetooth? ( net-wireless/bluez )
55         test? ( app-arch/xz-utils[extra-filters(+)] )
56         virtual/pkgconfig
57         !sys-devel/gcc[libffi(-)]"
58 RDEPEND+=" !build? ( app-misc/mime-types )"
59 PDEPEND=">=app-eselect/eselect-python-20140125-r1"
60
61 src_prepare() {
62         # Ensure that internal copies of expat, libffi and zlib are not used.
63         rm -fr Modules/expat || die
64         rm -fr Modules/_ctypes/libffi* || die
65         rm -fr Modules/zlib || die
66
67         local PATCHES=(
68                 "${WORKDIR}/${PATCHSET}"
69                 "${FILESDIR}/test.support.unlink-ignore-PermissionError.patch"
70                 # add module importing numpy to blacklist
71                 "${FILESDIR}/test-__all__-numpy.patch"
72         )
73
74         default
75
76         sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
77                 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
78
79         eautoreconf
80 }
81
82 src_configure() {
83         local disable
84         # disable automagic bluetooth headers detection
85         use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no
86         use gdbm      || disable+=" gdbm"
87         use ncurses   || disable+=" _curses _curses_panel"
88         use readline  || disable+=" readline"
89         use sqlite    || disable+=" _sqlite3"
90         use ssl       || export PYTHON_DISABLE_SSL="1"
91         use tk        || disable+=" _tkinter"
92         use xml       || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
93         export PYTHON_DISABLE_MODULES="${disable}"
94
95         if ! use xml; then
96                 ewarn "You have configured Python without XML support."
97                 ewarn "This is NOT a recommended configuration as you"
98                 ewarn "may face problems parsing any XML documents."
99         fi
100
101         if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
102                 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
103         fi
104
105         if [[ "$(gcc-major-version)" -ge 4 ]]; then
106                 append-flags -fwrapv
107         fi
108
109         filter-flags -malign-double
110
111         # https://bugs.gentoo.org/show_bug.cgi?id=50309
112         if is-flagq -O3; then
113                 is-flagq -fstack-protector-all && replace-flags -O3 -O2
114                 use hardened && replace-flags -O3 -O2
115         fi
116
117         # https://bugs.gentoo.org/700012
118         if is-flagq -flto || is-flagq '-flto=*'; then
119                 append-cflags $(test-flags-CC -ffat-lto-objects)
120         fi
121
122         # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
123         tc-export CXX
124
125         # Set LDFLAGS so we link modules with -lpython3.2 correctly.
126         # Needed on FreeBSD unless Python 3.2 is already installed.
127         # Please query BSD team before removing this!
128         append-ldflags "-L."
129
130         # Fix implicit declarations on cross and prefix builds. Bug #674070.
131         use ncurses && append-cppflags -I"${ESYSROOT}"/usr/include/ncursesw
132
133         local dbmliborder
134         if use gdbm; then
135                 dbmliborder+="${dbmliborder:+:}gdbm"
136         fi
137
138         local myeconfargs=(
139                 # glibc-2.30 removes it; since we can't cleanly force-rebuild
140                 # Python on glibc upgrade, remove it proactively to give
141                 # a chance for users rebuilding python before glibc
142                 ac_cv_header_stropts_h=no
143
144                 --enable-shared
145                 $(use_enable ipv6)
146                 --infodir='${prefix}/share/info'
147                 --mandir='${prefix}/share/man'
148                 --with-computed-gotos
149                 --with-dbmliborder="${dbmliborder}"
150                 --with-libc=
151                 --enable-loadable-sqlite-extensions
152                 --without-ensurepip
153                 --with-system-expat
154                 --with-system-ffi
155         )
156
157         OPT="" econf "${myeconfargs[@]}"
158 }
159
160 src_compile() {
161         # Ensure sed works as expected
162         # https://bugs.gentoo.org/594768
163         local -x LC_ALL=C
164
165         emake CPPFLAGS= CFLAGS= LDFLAGS=
166
167         # Work around bug 329499. See also bug 413751 and 457194.
168         if has_version dev-libs/libffi[pax_kernel]; then
169                 pax-mark E python
170         else
171                 pax-mark m python
172         fi
173 }
174
175 src_test() {
176         # Tests will not work when cross compiling.
177         if tc-is-cross-compiler; then
178                 elog "Disabling tests due to crosscompiling."
179                 return
180         fi
181
182         # Skip failing tests.
183         local skipped_tests="gdb"
184
185         for test in ${skipped_tests}; do
186                 mv "${S}"/Lib/test/test_${test}.py "${T}"
187         done
188
189         # bug 660358
190         local -x COLUMNS=80
191
192         local -x PYTHONDONTWRITEBYTECODE=
193
194         emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
195         local result=$?
196
197         for test in ${skipped_tests}; do
198                 mv "${T}/test_${test}.py" "${S}"/Lib/test
199         done
200
201         elog "The following tests have been skipped:"
202         for test in ${skipped_tests}; do
203                 elog "test_${test}.py"
204         done
205
206         elog "If you would like to run them, you may:"
207         elog "cd '${EPREFIX}/usr/lib/python${PYVER}/test'"
208         elog "and run the tests separately."
209
210         if [[ ${result} -ne 0 ]]; then
211                 die "emake test failed"
212         fi
213 }
214
215 src_install() {
216         local libdir=${ED}/usr/lib/python${PYVER}
217
218         emake DESTDIR="${D}" altinstall
219
220         # Remove static library
221         rm "${ED}"/usr/$(get_libdir)/libpython*.a || die
222
223         sed \
224                 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
225                 -e "s/\(PY_LDFLAGS=\).*/\1/" \
226                 -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed"
227
228         # Fix collisions between different slots of Python.
229         rm "${ED}/usr/$(get_libdir)/libpython3.so" || die
230
231         # Cheap hack to get version with ABIFLAGS
232         local abiver=$(cd "${ED}/usr/include"; echo python*)
233         if [[ ${abiver} != python${PYVER} ]]; then
234                 # Replace python3.X with a symlink to python3.Xm
235                 rm "${ED}/usr/bin/python${PYVER}" || die
236                 dosym "${abiver}" "/usr/bin/python${PYVER}"
237                 # Create python3.X-config symlink
238                 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
239                 # Create python-3.5m.pc symlink
240                 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
241         fi
242
243         # python seems to get rebuilt in src_install (bug 569908)
244         # Work around it for now.
245         if has_version dev-libs/libffi[pax_kernel]; then
246                 pax-mark E "${ED}/usr/bin/${abiver}"
247         else
248                 pax-mark m "${ED}/usr/bin/${abiver}"
249         fi
250
251         use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
252         use tk || rm -r "${ED}/usr/bin/idle${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
253
254         use wininst || rm "${libdir}/distutils/command/"wininst-*.exe || die
255
256         dodoc Misc/{ACKS,HISTORY,NEWS}
257
258         if use examples; then
259                 docinto examples
260                 find Tools -name __pycache__ -exec rm -fr {} + || die
261                 dodoc -r Tools
262         fi
263         insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
264         local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
265                 emake --no-print-directory -s -f - 2>/dev/null)
266         newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
267
268         newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
269         newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
270         sed \
271                 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
272                 -e "s:@PYDOC@:pydoc${PYVER}:" \
273                 -i "${ED}/etc/conf.d/pydoc-${PYVER}" \
274                 "${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed"
275
276         # for python-exec
277         local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
278
279         # if not using a cross-compiler, use the fresh binary
280         if ! tc-is-cross-compiler; then
281                 local -x PYTHON=./python
282                 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
283         else
284                 vars=( PYTHON "${vars[@]}" )
285         fi
286
287         python_export "python${PYVER}" "${vars[@]}"
288         echo "EPYTHON='${EPYTHON}'" > epython.py || die
289         python_domodule epython.py
290
291         # python-exec wrapping support
292         local pymajor=${PYVER%.*}
293         mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
294         # python and pythonX
295         ln -s "../../../bin/${abiver}" \
296                 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
297         ln -s "python${pymajor}" "${D}${PYTHON_SCRIPTDIR}/python" || die
298         # python-config and pythonX-config
299         # note: we need to create a wrapper rather than symlinking it due
300         # to some random dirname(argv[0]) magic performed by python-config
301         cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
302                 #!/bin/sh
303                 exec "${abiver}-config" "\${@}"
304         EOF
305         chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
306         ln -s "python${pymajor}-config" \
307                 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
308         # 2to3, pydoc
309         ln -s "../../../bin/2to3-${PYVER}" \
310                 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
311         ln -s "../../../bin/pydoc${PYVER}" \
312                 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
313         # idle
314         if use tk; then
315                 ln -s "../../../bin/idle${PYVER}" \
316                         "${D}${PYTHON_SCRIPTDIR}/idle" || die
317         fi
318 }
319
320 pkg_preinst() {
321         if has_version "<${CATEGORY}/${PN}-${PYVER}" && ! has_version ">=${CATEGORY}/${PN}-${PYVER}_alpha"; then
322                 python_updater_warning="1"
323         fi
324 }
325
326 eselect_python_update() {
327         if [[ -z "$(eselect python show)" || \
328                         ! -f "${EROOT}/usr/bin/$(eselect python show)" ]]; then
329                 eselect python update
330         fi
331
332         if [[ -z "$(eselect python show --python${PV%%.*})" || \
333                         ! -f "${EROOT}/usr/bin/$(eselect python show --python${PV%%.*})" ]]
334         then
335                 eselect python update --python${PV%%.*}
336         fi
337 }
338
339 pkg_postinst() {
340         eselect_python_update
341
342         if [[ "${python_updater_warning}" == "1" ]]; then
343                 ewarn "You have just upgraded from an older version of Python."
344                 ewarn
345                 ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules."
346         fi
347 }
348
349 pkg_postrm() {
350         eselect_python_update
351 }