File python3-base.spec of Package python3-base

# spec file for package python3-base
# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

# !!!!
# this is the master spec file, but changes should be submitted
# against python3, not python3-base
# see PACKAGING-NOTES for details
# !!!!

Name:           python3-base
BuildRequires:  automake
BuildRequires:  fdupes
BuildRequires:  libbz2-devel
BuildRequires:  lzma-devel
BuildRequires:  pkg-config
BuildRequires:  timezone
BuildRequires:  xz
BuildRequires:  zlib-devel
Summary:        Python3 Interpreter
License:        Python-2.0
Group:          Development/Languages/Python
Version:        3.3.3
Release:        0
%define         tarversion %{version}
%define         tarname    Python-%{tarversion}

# python 3.1 didn't have a separate python-base, so it is wrongly
# not a conflict to have python3-3.1 and python3-base > 3.1
Obsoletes:      python3 < 3.2
# no Provides, because python3 is obviously provided by package python3

Source1:        baselibs.conf
Source2:        README.SUSE
Source3:        python3start
Source5:        python3.csh

Source99:       PACKAGING-NOTES
# this is documentation for packagers, put here to silence Factory source_validator


# implement "--record-rpm" option for distutils installations
Patch01:        Python-3.0b1-record-rpm.patch
# support lib-vs-lib64 distinction
Patch02:        Python-3.3.0b2-multilib.patch
# securing usage of readlink/realpath in PySys_SetArgv
Patch03:        python-2.6b1-canonicalize2.patch
# support finding packages in /usr/local, install to /usr/local by default
Patch04:        python-3.3.0b1-localpath.patch
# replace DATE, TIME and COMPILER by fixed definitions to aid reproducible builds
Patch06:        python-3.3.0b1-fix_date_time_compiler.patch
# fix wrong include path in curses-panel module
Patch07:        python-3.3.0b1-curses-panel.patch
# POSIX_FADV_WILLNEED throws EINVAL. Use a different constant in test
Patch09:        python-3.3.0b1-test-posix_fadvise.patch
# Add missing bits for aarch64 in libffi
Patch10:        ctypes-libffi-aarch64.patch
# Disable SO_REUSEPORT constant in tests, because it's not supported on older kernels
Patch11:        python-3.3.2-no-REUSEPORT.patch
# Disable global and distutils sysconfig comparison test, we deviate from the default depending on optflags
Patch12:        python-3.3.3-skip-distutils-test_sysconfig_module.patch
# Add support for ppc64le (ELFv2) to libffi copy for ctypes
Patch13:        libffi-ppc64le.diff

BuildRoot:      %{_tmppath}/%{name}-%{version}-build


# the versions are autogenerated from
# based on the current source tarball
%define         python_version  3.3

%define         python_version_abitag   33
%define         python_version_soname   3_3

%define         sitedir         %{_libdir}/python%{python_version}

# three possible ABI kinds: m - pymalloc, d - debug build
# see PEP 3149
%define         abi_kind m
# python ABI version - used in some file names
%define         python_abi %{python_version}%{abi_kind}
# soname ABI tag defined in PEP 3149
%define         abi_tag %{python_version_abitag}%{abi_kind}

%define         so_version %{python_version_soname}%{abi_kind}1_0

%define dynlib() %{sitedir}/lib-dynload/%{1}.cpython-%{abi_tag}.so

Python is an interpreted, object-oriented programming language, and is
often compared to Tcl, Perl, Scheme, or Java.  You can find an overview
of Python in the documentation and tutorials included in the python-doc
(HTML) or python-doc-pdf (PDF) packages.

If you want to install third party modules using distutils, you need to
install python-devel package.

    Guido van Rossum <>

%package -n python3-tools
Requires:       %{name} = %{version}
Summary:        Python Utility and Demonstration Scripts
Group:          Development/Languages/Python
Obsoletes:      python3-demo < %{version}
Provides:       python3-demo = %{version}

%description -n python3-tools
A number of scripts that are useful for building, testing or extending Python,
and a set of demonstration programs.

%package -n python3-idle
Requires:       %{name} = %{version}
Requires:       python3-tk
Summary:        An Integrated Development Environment for Python
Group:          Development/Languages/Python

%description -n python3-idle
IDLE is a Tkinter based integrated development environment for Python.
It features a multi-window text editor with multiple undo, Python
colorizing, and many other things, as well as a Python shell window and
a debugger.

%package -n python3-devel
Requires:       %{name} = %{version}
Provides:       python3-2to3 = %{version}
Obsoletes:      python3-2to3 < %{version}
Summary:        Include Files and Libraries Mandatory for Building Python Modules
Group:          Development/Languages/Python

%description -n python3-devel
The Python programming language's interpreter can be extended with
dynamically loaded extensions and can be embedded in other programs.

This package contains header files, a static library, and development
tools for building Python modules, extending the Python interpreter or
embedding Python in applications.

This also includes the Python distutils, which were in the Python
package up to version 2.2.2.

%package -n python3-testsuite
Requires:       python3 = %{version}
Requires:       python3-tk = %{version}
Summary:        Unit tests for Python and its standard library
Group:          Development/Languages/Python

%description -n python3-testsuite
Unit tests that are useful for verifying integrity and functionality
of the installed Python interpreter and standard library.
They are a documented part of stdlib, as a module 'test'.

%package -n libpython%{so_version}
Summary:        Python Interpreter shared library
Group:          Development/Languages/Python

%description -n libpython%{so_version}
Python is an interpreted, object-oriented programming language, and is
often compared to Tcl, Perl, Scheme, or Java.  You can find an overview
of Python in the documentation and tutorials included in the python-doc
(HTML) or python-doc-pdf (PDF) packages.

This package contains libpython3.2 shared library for embedding in
other applications.

%setup -q -n %{tarname}


%patch01 -p1
%patch02 -p1
#- canonicalize disabled, needs testing whether the exploit still works
%patch06 -p1
%patch09 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p0

# drop Autoconf version requirement
sed -i 's/^AC_PREREQ/dnl AC_PREREQ/'


# use rpm_opt_flags
export OPT="%{optflags} -DOPENSSL_LOAD_CONF"

touch -r %{S:0}

autoreconf -fi
# prevent make from trying to rebuild asdl stuff, which requires existing python installation
touch Parser/asdl* Python/Python-ast.c Include/Python-ast.h

%if 0%{?sles_version}
sed -e 's/-fprofile-correction//' -i

./configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir} \
    --mandir=%{_mandir} \
    --docdir=%{_docdir}/python \
    --enable-ipv6 \
    --with-fpectl \

    make %{?_smp_mflags} profile-opt

# SUSE's gdb breaks test_gdb by producing spurious output (zypper suggestions)
# test_socket fails because of name resolution failure, that is expected
EXCLUDE="-x test_gdb -x test_socket"
# test_ctypes breaks on ARM - even on real machines
%ifarch %arm
EXCLUDE="$EXCLUDE -x test_ctypes"
%ifarch ppc ppc64 ppc64le
# exclue test_faulthandler due to bnc#831629
EXCLUDE="$EXCLUDE -x test_io -x test_faulthandler"
# some tests break in QEMU
%if 0%{?qemu_user_space_build} > 0
EXCLUDE="$EXCLUDE -x test_multiprocessing test_threading test_threadedtempfile test_io test_posix test_ioctl test_mmap test_openpty test_pty test_monotonic_settime test_clock_settime test_time test_subprocess test_asyncore test_send_at_certain_offset test_send_whole_file test_os test_faulthandler"

# on x86_64, SLE_11_SP2 only, extreme gamma function values (close to negative 
# integers) fail. Is probably a bug/imperfection in -lm
# disabling this for all SLE, unless someone knows how to test for SP level?
%ifarch x86_64
%if 0%{?sles_version} == 11
EXCLUDE="$EXCLUDE -x test_math"

# This test (part of test_uuid) requires real network interfaces
# so that ifconfig output has "HWaddr <something>".  Some kvm instances
# done have any such interface breaking teh uuid module.
EXCLUDE="$EXCLUDE -x test_uuid"

# Limit virtual memory to avoid spurious failures
if test $(ulimit -v) = unlimited || test $(ulimit -v) -gt 10000000; then
  ulimit -v 10000000 || :
make test TESTOPTS="-u -network,-gui $EXCLUDE"
# use network, be verbose:
#make test TESTOPTS="-l -u network -v"

make \
    OPT="%{optflags} -fPIC" \

# remove .a
find ${RPM_BUILD_ROOT} -name "*.a" -exec rm {} ";"

# install "site-packages" and __pycache__ for third parties
install -d -m 755 ${RPM_BUILD_ROOT}%{sitedir}/site-packages
install -d -m 755 ${RPM_BUILD_ROOT}%{sitedir}/site-packages/__pycache__
# and their 32bit counterparts explicitly
mkdir -p ${RPM_BUILD_ROOT}/usr/lib/python%{python_version}/site-packages/__pycache__

# cleanup parts that don't belong
for dir in curses dbm sqlite3 tkinter xml xmlrpc; do
    find $RPM_BUILD_ROOT%{sitedir}/$dir/* -maxdepth 0 -name "test" -o -exec rm -rf {} ";"
rm $RPM_BUILD_ROOT%{dynlib pyexpat}

# overwrite the copied binary with a link
ln -sf python%{python_version} ${RPM_BUILD_ROOT}%{_bindir}/python3

# replace duplicate .pyo/.pyc with hardlinks
%fdupes $RPM_BUILD_ROOT/%{sitedir}

# documentation
export PDOCS=${RPM_BUILD_ROOT}%{_docdir}/%{name}
install -d -m 755 $PDOCS
install -c -m 644 %{S:2}                            $PDOCS/
install -c -m 644 LICENSE                           $PDOCS/
install -c -m 644 README                            $PDOCS/

# tools
for x in `find Tools/ \( -not -name Makefile \) -print | sort` ; do
  test -d $x && ( install -c -m 755 -d $PDOCS/$x ) \
             || ( install -c -m 644 $x $PDOCS/$x )
# clean up the bat files
find $PDOCS -name "*.bat" -exec rm {} ";"

# install devel files to /config
#cp Makefile Makefile.pre $RPM_BUILD_ROOT%{sitedir}/config-%{python_abi}/

# move idle config into /etc
install -d -m 755 ${RPM_BUILD_ROOT}/etc/idle3
    cd ${RPM_BUILD_ROOT}/%{sitedir}/idlelib/
    for file in *.def ; do
        mv $file ${RPM_BUILD_ROOT}/etc/idle3/
        ln -sf /etc/idle3/$file  ${RPM_BUILD_ROOT}/%{sitedir}/idlelib/

# startup scripts
mkdir -p $RPM_BUILD_ROOT/etc/profile.d
install -m 644 %{S:3} $RPM_BUILD_ROOT/etc
install -m 644 %{S:4} %{S:5} $RPM_BUILD_ROOT/etc/profile.d

# RPM macros
mkdir -p $RPM_BUILD_ROOT/etc/rpm
LD_LIBRARY_PATH=. ./python %{S:7} > $RPM_BUILD_ROOT/etc/rpm/macros.python3

# import_failed hooks
mkdir $FAILDIR
install -m 644 %{S:8} %{S:9} $FAILDIR
LD_LIBRARY_PATH=. ./python -c "from py_compile import compile; compile('$FAILDIR/', dfile='%{sitedir}/_import_failed/')"
LD_LIBRARY_PATH=. ./python -O -c "from py_compile import compile; compile('$FAILDIR/', dfile='%{sitedir}/_import_failed/')"
    cd $FAILDIR
    while read package modules; do
        for module in $modules; do
            ln $
            pushd __pycache__
            for i in import_failed*; do
                ln $i $module${i#import_failed}
    done < %{S:9}
echo %{sitedir}/_import_failed > $RPM_BUILD_ROOT/%{sitedir}/site-packages/zzzz-import-failed-hooks.pth

# fix shebangs
for dir in %{sitedir} %{_docdir}/%{name}; do
    find $RPM_BUILD_ROOT/$dir -name '*.py' -type f -print0 \
        | xargs -0 sed -r -i -e '1s@^#![[:space:]]*(/usr/(local/)?bin/(env +)?)?python([0-9]+(\.[0-9]+)?)?@#!/usr/bin/python3@'


%post -n libpython%{so_version} -p /sbin/ldconfig

%postun -n libpython%{so_version} -p /sbin/ldconfig

%files -n libpython%{so_version}
%defattr(644, root,root)

%files -n python3-tools
%defattr(644, root, root, 755)
%doc %{_docdir}/%{name}/Tools

%files -n python3-idle
%defattr(644, root, root, 755)
%dir /etc/idle3
%config /etc/idle3/*
%doc Lib/idlelib/NEWS.txt
%doc Lib/idlelib/README.txt
%doc Lib/idlelib/TODO.txt
%doc Lib/idlelib/extend.txt
%doc Lib/idlelib/ChangeLog
%attr(755, root, root) %{_bindir}/idle%{python_version}

%files -n python3-devel
%defattr(644, root, root, 755)
%exclude %{_prefix}/include/python%{python_abi}/pyconfig.h
%defattr(755, root, root)

%files -n python3-testsuite
%defattr(644, root, root, 755)
%{dynlib _ctypes_test}
%{dynlib _testcapi}
%{dynlib xxlimited}
# workaround for missing packages
%dir %{sitedir}/sqlite3
%dir %{sitedir}/tkinter

%defattr(644, root, root, 755)
# profile files
%config /etc/python3start
%config /etc/profile.d/python3.*
# docs
%dir %{_docdir}/%{name}
%doc %{_docdir}/%{name}/README
%doc %{_docdir}/%{name}/LICENSE
%doc %{_docdir}/%{name}/README.SUSE
%doc %{_mandir}/man1/python3.1*
%doc %{_mandir}/man1/python%{python_version}.1*
# license text, not a doc because the code can use it at run-time
# makefile etc
# binary parts
%dir %{sitedir}/lib-dynload
%{dynlib array}
%{dynlib atexit}
%{dynlib audioop}
%{dynlib binascii}
%{dynlib _bisect}
%{dynlib _bz2}
%{dynlib cmath}
%{dynlib _codecs_cn}
%{dynlib _codecs_hk}
%{dynlib _codecs_iso2022}
%{dynlib _codecs_jp}
%{dynlib _codecs_kr}
%{dynlib _codecs_tw}
%{dynlib _crypt}
%{dynlib _csv}
%{dynlib _ctypes}
%{dynlib _datetime}
%{dynlib _decimal}
%{dynlib _elementtree}
%{dynlib fcntl}
%{dynlib grp}
%{dynlib _heapq}
%{dynlib _json}
%{dynlib _lsprof}
%{dynlib _lzma}
%{dynlib math}
%{dynlib mmap}
%{dynlib _multibytecodec}
%{dynlib _multiprocessing}
%{dynlib nis}
%{dynlib ossaudiodev}
%{dynlib parser}
%{dynlib _pickle}
%{dynlib _posixsubprocess}
%{dynlib _random}
%{dynlib resource}
%{dynlib select}
%{dynlib _socket}
%{dynlib spwd}
%{dynlib _struct}
%{dynlib syslog}
%{dynlib termios}
%{dynlib time}
%{dynlib _testbuffer}
%{dynlib unicodedata}
%{dynlib zlib}
# hashlib fallback modules
%{dynlib _md5}
%{dynlib _sha1}
%{dynlib _sha256}
%{dynlib _sha512}
# python parts
%dir /usr/lib/python%{python_version}
%dir /usr/lib/python%{python_version}/site-packages
%dir /usr/lib/python%{python_version}/site-packages/__pycache__
%dir %{sitedir}
%dir %{sitedir}/site-packages
%dir %{sitedir}/site-packages/__pycache__
%exclude %{sitedir}/*/test
# import-failed hooks
# symlinks
# executables
%attr(755, root, root) %{_bindir}/pydoc%{python_version}
%attr(755, root, root) %{_bindir}/python%{python_abi}
%attr(755, root, root) %{_bindir}/python%{python_version}
%attr(755, root, root) %{_bindir}/pyvenv-%{python_version}