dev-python/pytest: arm64 stable (bug #723996)
[gentoo.git] / dev-lang / python / python-3.7.7-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.7.6"
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}/${PYVER}m"
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         )
71
72         default
73
74         sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
75                 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
76
77         eautoreconf
78 }
79
80 src_configure() {
81         local disable
82         # disable automagic bluetooth headers detection
83         use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no
84         use gdbm      || disable+=" gdbm"
85         use ncurses   || disable+=" _curses _curses_panel"
86         use readline  || disable+=" readline"
87         use sqlite    || disable+=" _sqlite3"
88         use ssl       || export PYTHON_DISABLE_SSL="1"
89         use tk        || disable+=" _tkinter"
90         use xml       || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
91         export PYTHON_DISABLE_MODULES="${disable}"
92
93         if ! use xml; then
94                 ewarn "You have configured Python without XML support."
95                 ewarn "This is NOT a recommended configuration as you"
96                 ewarn "may face problems parsing any XML documents."
97         fi
98
99         if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
100                 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
101         fi
102
103         if [[ "$(gcc-major-version)" -ge 4 ]]; then
104                 append-flags -fwrapv
105         fi
106
107         filter-flags -malign-double
108
109         # https://bugs.gentoo.org/show_bug.cgi?id=50309
110         if is-flagq -O3; then
111                 is-flagq -fstack-protector-all && replace-flags -O3 -O2
112                 use hardened && replace-flags -O3 -O2
113         fi
114
115         # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
116         tc-export CXX
117
118         # Set LDFLAGS so we link modules with -lpython3.2 correctly.
119         # Needed on FreeBSD unless Python 3.2 is already installed.
120         # Please query BSD team before removing this!
121         append-ldflags "-L."
122
123         # Fix implicit declarations on cross and prefix builds. Bug #674070.
124         use ncurses && append-cppflags -I"${ESYSROOT}"/usr/include/ncursesw
125
126         local dbmliborder
127         if use gdbm; then
128                 dbmliborder+="${dbmliborder:+:}gdbm"
129         fi
130
131         local myeconfargs=(
132                 # glibc-2.30 removes it; since we can't cleanly force-rebuild
133                 # Python on glibc upgrade, remove it proactively to give
134                 # a chance for users rebuilding python before glibc
135                 ac_cv_header_stropts_h=no
136
137                 --enable-shared
138                 $(use_enable ipv6)
139                 --infodir='${prefix}/share/info'
140                 --mandir='${prefix}/share/man'
141                 --with-computed-gotos
142                 --with-dbmliborder="${dbmliborder}"
143                 --with-libc=
144                 --enable-loadable-sqlite-extensions
145                 --without-ensurepip
146                 --with-system-expat
147                 --with-system-ffi
148         )
149
150         OPT="" econf "${myeconfargs[@]}"
151 }
152
153 src_compile() {
154         # Ensure sed works as expected
155         # https://bugs.gentoo.org/594768
156         local -x LC_ALL=C
157
158         emake CPPFLAGS= CFLAGS= LDFLAGS=
159
160         # Work around bug 329499. See also bug 413751 and 457194.
161         if has_version dev-libs/libffi[pax_kernel]; then
162                 pax-mark E python
163         else
164                 pax-mark m python
165         fi
166 }
167
168 src_test() {
169         # Tests will not work when cross compiling.
170         if tc-is-cross-compiler; then
171                 elog "Disabling tests due to crosscompiling."
172                 return
173         fi
174
175         # Skip failing tests.
176         local skipped_tests="gdb"
177
178         for test in ${skipped_tests}; do
179                 mv "${S}"/Lib/test/test_${test}.py "${T}"
180         done
181
182         # bug 660358
183         local -x COLUMNS=80
184
185         local -x PYTHONDONTWRITEBYTECODE=
186
187         emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
188         local result=$?
189
190         for test in ${skipped_tests}; do
191                 mv "${T}/test_${test}.py" "${S}"/Lib/test
192         done
193
194         elog "The following tests have been skipped:"
195         for test in ${skipped_tests}; do
196                 elog "test_${test}.py"
197         done
198
199         elog "If you would like to run them, you may:"
200         elog "cd '${EPREFIX}/usr/lib/python${PYVER}/test'"
201         elog "and run the tests separately."
202
203         if [[ ${result} -ne 0 ]]; then
204                 die "emake test failed"
205         fi
206 }
207
208 src_install() {
209         local libdir=${ED}/usr/lib/python${PYVER}
210
211         emake DESTDIR="${D}" altinstall
212
213         # Remove static library
214         rm "${ED}"/usr/$(get_libdir)/libpython*.a || die
215
216         sed \
217                 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
218                 -e "s/\(PY_LDFLAGS=\).*/\1/" \
219                 -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed"
220
221         # Fix collisions between different slots of Python.
222         rm "${ED}/usr/$(get_libdir)/libpython3.so" || die
223
224         # Cheap hack to get version with ABIFLAGS
225         local abiver=$(cd "${ED}/usr/include"; echo python*)
226         if [[ ${abiver} != python${PYVER} ]]; then
227                 # Replace python3.X with a symlink to python3.Xm
228                 rm "${ED}/usr/bin/python${PYVER}" || die
229                 dosym "${abiver}" "/usr/bin/python${PYVER}"
230                 # Create python3.X-config symlink
231                 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
232                 # Create python-3.5m.pc symlink
233                 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
234         fi
235
236         # python seems to get rebuilt in src_install (bug 569908)
237         # Work around it for now.
238         if has_version dev-libs/libffi[pax_kernel]; then
239                 pax-mark E "${ED}/usr/bin/${abiver}"
240         else
241                 pax-mark m "${ED}/usr/bin/${abiver}"
242         fi
243
244         use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
245         use tk || rm -r "${ED}/usr/bin/idle${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
246
247         use wininst || rm "${libdir}/distutils/command/"wininst-*.exe || die
248
249         dodoc Misc/{ACKS,HISTORY,NEWS}
250
251         if use examples; then
252                 docinto examples
253                 find Tools -name __pycache__ -exec rm -fr {} + || die
254                 dodoc -r Tools
255         fi
256         insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
257         local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
258                 emake --no-print-directory -s -f - 2>/dev/null)
259         newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
260
261         newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
262         newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
263         sed \
264                 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
265                 -e "s:@PYDOC@:pydoc${PYVER}:" \
266                 -i "${ED}/etc/conf.d/pydoc-${PYVER}" \
267                 "${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed"
268
269         # for python-exec
270         local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
271
272         # if not using a cross-compiler, use the fresh binary
273         if ! tc-is-cross-compiler; then
274                 local -x PYTHON=./python
275                 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
276         else
277                 vars=( PYTHON "${vars[@]}" )
278         fi
279
280         python_export "python${PYVER}" "${vars[@]}"
281         echo "EPYTHON='${EPYTHON}'" > epython.py || die
282         python_domodule epython.py
283
284         # python-exec wrapping support
285         local pymajor=${PYVER%.*}
286         mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
287         # python and pythonX
288         ln -s "../../../bin/${abiver}" \
289                 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
290         ln -s "python${pymajor}" "${D}${PYTHON_SCRIPTDIR}/python" || die
291         # python-config and pythonX-config
292         # note: we need to create a wrapper rather than symlinking it due
293         # to some random dirname(argv[0]) magic performed by python-config
294         cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
295                 #!/bin/sh
296                 exec "${abiver}-config" "\${@}"
297         EOF
298         chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
299         ln -s "python${pymajor}-config" \
300                 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
301         # 2to3, pydoc, pyvenv
302         ln -s "../../../bin/2to3-${PYVER}" \
303                 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
304         ln -s "../../../bin/pydoc${PYVER}" \
305                 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
306         ln -s "../../../bin/pyvenv-${PYVER}" \
307                 "${D}${PYTHON_SCRIPTDIR}/pyvenv" || die
308         # idle
309         if use tk; then
310                 ln -s "../../../bin/idle${PYVER}" \
311                         "${D}${PYTHON_SCRIPTDIR}/idle" || die
312         fi
313 }
314
315 pkg_preinst() {
316         if has_version "<${CATEGORY}/${PN}-${PYVER}" && ! has_version ">=${CATEGORY}/${PN}-${PYVER}_alpha"; then
317                 python_updater_warning="1"
318         fi
319 }
320
321 eselect_python_update() {
322         if [[ -z "$(eselect python show)" || \
323                         ! -f "${EROOT}/usr/bin/$(eselect python show)" ]]; then
324                 eselect python update
325         fi
326
327         if [[ -z "$(eselect python show --python${PV%%.*})" || \
328                         ! -f "${EROOT}/usr/bin/$(eselect python show --python${PV%%.*})" ]]
329         then
330                 eselect python update --python${PV%%.*}
331         fi
332 }
333
334 pkg_postinst() {
335         eselect_python_update
336
337         if [[ "${python_updater_warning}" == "1" ]]; then
338                 ewarn "You have just upgraded from an older version of Python."
339                 ewarn
340                 ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules."
341         fi
342 }
343
344 pkg_postrm() {
345         eselect_python_update
346 }