Use https by default
[gentoo.git] / dev-lang / python / python-2.7.10.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI="4"
6 WANT_LIBTOOL="none"
7
8 inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
9
10 MY_P="Python-${PV}"
11 PATCHSET_VERSION="2.7.10-0"
12
13 DESCRIPTION="An interpreted, interactive, object-oriented programming language"
14 HOMEPAGE="http://www.python.org/"
15 SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz
16         https://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz"
17
18 LICENSE="PSF-2"
19 SLOT="2.7"
20 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
21 IUSE="-berkdb build doc elibc_uclibc examples gdbm hardened ipv6 +ncurses +readline sqlite +ssl +threads tk +wide-unicode wininst +xml"
22
23 # Do not add a dependency on dev-lang/python to this ebuild.
24 # If you need to apply a patch which requires python for bootstrapping, please
25 # run the bootstrap code on your dev box and include the results in the
26 # patchset. See bug 447752.
27
28 RDEPEND="app-arch/bzip2
29         >=sys-libs/zlib-1.1.3
30         virtual/libffi
31         virtual/libintl
32         !build? (
33                 berkdb? ( || (
34                         sys-libs/db:5.3
35                         sys-libs/db:5.2
36                         sys-libs/db:5.1
37                         sys-libs/db:5.0
38                         sys-libs/db:4.8
39                         sys-libs/db:4.7
40                         sys-libs/db:4.6
41                         sys-libs/db:4.5
42                         sys-libs/db:4.4
43                         sys-libs/db:4.3
44                         sys-libs/db:4.2
45                 ) )
46                 gdbm? ( sys-libs/gdbm[berkdb] )
47                 ncurses? (
48                         >=sys-libs/ncurses-5.2
49                         readline? ( >=sys-libs/readline-4.1 )
50                 )
51                 sqlite? ( >=dev-db/sqlite-3.3.8:3 )
52                 ssl? ( dev-libs/openssl )
53                 tk? (
54                         >=dev-lang/tk-8.0
55                         dev-tcltk/blt
56                         dev-tcltk/tix
57                 )
58                 xml? ( >=dev-libs/expat-2.1 )
59         )
60         !!<sys-apps/portage-2.1.9"
61 DEPEND="${RDEPEND}
62         virtual/pkgconfig
63         >=sys-devel/autoconf-2.65
64         !sys-devel/gcc[libffi]"
65 RDEPEND+=" !build? ( app-misc/mime-types )
66         doc? ( dev-python/python-docs:${SLOT} )"
67 PDEPEND="app-eselect/eselect-python
68         app-admin/python-updater"
69
70 S="${WORKDIR}/${MY_P}"
71
72 pkg_setup() {
73         if use berkdb; then
74                 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
75                 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
76                 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
77                 ewarn "is provided by dev-python/bsddb3."
78         else
79                 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
80                         ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
81                         ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
82                         ewarn "You might need to migrate your databases."
83                 fi
84         fi
85 }
86
87 src_prepare() {
88         # Ensure that internal copies of expat, libffi and zlib are not used.
89         rm -r Modules/expat || die
90         rm -r Modules/_ctypes/libffi* || die
91         rm -r Modules/zlib || die
92
93         if tc-is-cross-compiler; then
94                 local EPATCH_EXCLUDE="*_regenerate_platform-specific_modules.patch"
95         fi
96
97         EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches"
98
99         # Fix for cross-compiling.
100         epatch "${FILESDIR}/python-2.7.5-nonfatal-compileall.patch"
101         epatch "${FILESDIR}/python-2.7.9-ncurses-pkg-config.patch"
102
103         sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
104                 Lib/distutils/command/install.py \
105                 Lib/distutils/sysconfig.py \
106                 Lib/site.py \
107                 Lib/sysconfig.py \
108                 Lib/test/test_site.py \
109                 Makefile.pre.in \
110                 Modules/Setup.dist \
111                 Modules/getpath.c \
112                 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
113
114         epatch_user
115
116         eautoreconf
117 }
118
119 src_configure() {
120         if use build; then
121                 # Disable extraneous modules with extra dependencies.
122                 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
123                 export PYTHON_DISABLE_SSL="1"
124         else
125                 # dbm module can be linked against berkdb or gdbm.
126                 # Defaults to gdbm when both are enabled, #204343.
127                 local disable
128                 use berkdb   || use gdbm || disable+=" dbm"
129                 use berkdb   || disable+=" _bsddb"
130                 use gdbm     || disable+=" gdbm"
131                 use ncurses  || disable+=" _curses _curses_panel"
132                 use readline || disable+=" readline"
133                 use sqlite   || disable+=" _sqlite3"
134                 use ssl      || export PYTHON_DISABLE_SSL="1"
135                 use tk       || disable+=" _tkinter"
136                 use xml      || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
137                 export PYTHON_DISABLE_MODULES="${disable}"
138
139                 if ! use xml; then
140                         ewarn "You have configured Python without XML support."
141                         ewarn "This is NOT a recommended configuration as you"
142                         ewarn "may face problems parsing any XML documents."
143                 fi
144         fi
145
146         if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
147                 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
148         fi
149
150         if [[ "$(gcc-major-version)" -ge 4 ]]; then
151                 append-flags -fwrapv
152         fi
153
154         filter-flags -malign-double
155
156         [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
157
158         # https://bugs.gentoo.org/show_bug.cgi?id=50309
159         if is-flagq -O3; then
160                 is-flagq -fstack-protector-all && replace-flags -O3 -O2
161                 use hardened && replace-flags -O3 -O2
162         fi
163
164         if tc-is-cross-compiler; then
165                 # Force some tests that try to poke fs paths.
166                 export ac_cv_file__dev_ptc=no
167                 export ac_cv_file__dev_ptmx=yes
168         fi
169
170         # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
171         tc-export CXX
172         # The configure script fails to use pkg-config correctly.
173         # http://bugs.python.org/issue15506
174         export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
175
176         # Set LDFLAGS so we link modules with -lpython2.7 correctly.
177         # Needed on FreeBSD unless Python 2.7 is already installed.
178         # Please query BSD team before removing this!
179         append-ldflags "-L."
180
181         local dbmliborder
182         if use gdbm; then
183                 dbmliborder+="${dbmliborder:+:}gdbm"
184         fi
185         if use berkdb; then
186                 dbmliborder+="${dbmliborder:+:}bdb"
187         fi
188
189         BUILD_DIR="${WORKDIR}/${CHOST}"
190         mkdir -p "${BUILD_DIR}" || die
191         cd "${BUILD_DIR}" || die
192
193         ECONF_SOURCE="${S}" OPT="" \
194         econf \
195                 --with-fpectl \
196                 --enable-shared \
197                 $(use_enable ipv6) \
198                 $(use_with threads) \
199                 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
200                 --infodir='${prefix}/share/info' \
201                 --mandir='${prefix}/share/man' \
202                 --with-dbmliborder="${dbmliborder}" \
203                 --with-libc="" \
204                 --enable-loadable-sqlite-extensions \
205                 --with-system-expat \
206                 --with-system-ffi \
207                 --without-ensurepip
208
209         if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
210                 eerror "configure has detected that the sem_open function is broken."
211                 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
212                 die "Broken sem_open function (bug 496328)"
213         fi
214 }
215
216 src_compile() {
217         # Avoid invoking pgen for cross-compiles.
218         touch Include/graminit.h Python/graminit.c
219
220         cd "${BUILD_DIR}" || die
221         emake
222
223         # Work around bug 329499. See also bug 413751 and 457194.
224         if has_version dev-libs/libffi[pax_kernel]; then
225                 pax-mark E python
226         else
227                 pax-mark m python
228         fi
229 }
230
231 src_test() {
232         # Tests will not work when cross compiling.
233         if tc-is-cross-compiler; then
234                 elog "Disabling tests due to crosscompiling."
235                 return
236         fi
237
238         cd "${BUILD_DIR}" || die
239
240         # Skip failing tests.
241         local skipped_tests="distutils gdb"
242
243         for test in ${skipped_tests}; do
244                 mv "${S}"/Lib/test/test_${test}.py "${T}"
245         done
246
247         # Rerun failed tests in verbose mode (regrtest -w).
248         emake test EXTRATESTOPTS="-w" < /dev/tty
249         local result="$?"
250
251         for test in ${skipped_tests}; do
252                 mv "${T}/test_${test}.py" "${S}"/Lib/test
253         done
254
255         elog "The following tests have been skipped:"
256         for test in ${skipped_tests}; do
257                 elog "test_${test}.py"
258         done
259
260         elog "If you would like to run them, you may:"
261         elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
262         elog "and run the tests separately."
263
264         if [[ "${result}" -ne 0 ]]; then
265                 die "emake test failed"
266         fi
267 }
268
269 src_install() {
270         local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
271
272         cd "${BUILD_DIR}" || die
273         emake DESTDIR="${D}" altinstall
274
275         sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
276
277         # Backwards compat with Gentoo divergence.
278         dosym python${SLOT}-config /usr/bin/python-config-${SLOT}
279
280         # Fix collisions between different slots of Python.
281         mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
282         mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
283         mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
284         rm -f "${ED}usr/bin/smtpd.py"
285
286         if use build; then
287                 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test}
288         else
289                 use berkdb || rm -r "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*} || die
290                 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
291                 use tk || rm -r "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk} || die
292                 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
293         fi
294
295         use threads || rm -r "${libdir}/multiprocessing" || die
296         use wininst || rm -r "${libdir}/distutils/command/"wininst-*.exe || die
297
298         dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
299
300         if use examples; then
301                 insinto /usr/share/doc/${PF}/examples
302                 doins -r "${S}"/Tools
303         fi
304         insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
305         local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
306                 emake --no-print-directory -s -f - 2>/dev/null)
307         newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
308
309         newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
310         newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
311         sed \
312                 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
313                 -e "s:@PYDOC@:pydoc${SLOT}:" \
314                 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
315
316         # for python-exec
317         python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
318
319         # if not using a cross-compiler, use the fresh binary
320         if ! tc-is-cross-compiler; then
321                 local PYTHON=./python
322                 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
323         fi
324
325         echo "EPYTHON='${EPYTHON}'" > epython.py
326         python_domodule epython.py
327 }
328
329 pkg_preinst() {
330         if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; then
331                 python_updater_warning="1"
332         fi
333 }
334
335 eselect_python_update() {
336         if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
337                 eselect python update
338         fi
339
340         if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
341                 eselect python update --python${PV%%.*}
342         fi
343 }
344
345 pkg_postinst() {
346         eselect_python_update
347
348         if [[ "${python_updater_warning}" == "1" ]]; then
349                 ewarn "You have just upgraded from an older version of Python."
350                 ewarn "You should switch active version of Python ${PV%%.*} and run"
351                 ewarn "'python-updater [options]' to rebuild Python modules."
352         fi
353 }
354
355 pkg_postrm() {
356         eselect_python_update
357 }