churchyard / rpms / python3

Forked from rpms/python3 6 years ago
Blob Blame History Raw
# ==================
# Top-level metadata
# ==================

%global pybasever 3.7

# pybasever without the dot:
%global pyshortver 37

Name: python%{pyshortver}
Summary:  Version %{pybasever} of the Python interpreter

# Third beta
%global prerel rc1

#  WARNING  When rebasing to a new Python version,
#           remember to update the python3-docs package as well
Version: %{pybasever}.0
Release: 0.20.%{?prerel}%{?dist}
License: Python

# ==================================
# Conditionals controlling the build
# ==================================

# Note that the bcond macros are named for the CLI option they create.
# "%%bcond_without" means "ENABLE by default and create a --without option"

# Flat package, i.e. python36, python37, python38 for tox etc.
# warning: changes some other defaults
# in Fedora, never turn this on for the python3 package
# and always keep it on for python37 etc.
# WARNING: This does not change the package name and summary above
%bcond_without flatpackage

# Expensive optimizations (mainly, profile-guided optimizations)
%ifarch %{ix86} x86_64
%bcond_without optimizations
# On some architectures, the optimized build takes tens of hours, possibly
# longer than Koji's 24-hour timeout. Disable optimizations here.
%bcond_with optimizations

# Run the test suite in %%check
%bcond_without tests

# Ability to reuse RPM-installed pip using rewheel
%if %{with flatpackage}
%bcond_with rewheel
%bcond_without rewheel

# Extra build for debugging the interpreter or C-API extensions
# (the -debug subpackages)
%if %{with flatpackage}
%bcond_with debug_build
%bcond_without debug_build

# Support for the GDB debugger
%bcond_without gdb_hooks

# The dbm.gnu module (key-value database)
%bcond_without gdbm

# Main interpreter loop optimization
%bcond_without computed_gotos

# Support for the Valgrind debugger/profiler
%ifnarch s390 %{mips} riscv64
%bcond_without valgrind
# Some arches don't have valgrind, disable support for it there.
%bcond_with valgrind

# ==================================
# Notes from bootstraping Python 3.6
# ==================================
# New Python major version (3.X) break ABI and bytecode compatibility,
# so all packages depending on it need to be rebuilt.
# Due to a dependency cycle between Python, gdb, rpm, pip, setuptools, wheel,
# and other packages, this isn't straightforward.
# Build in the following order:
# 1. At the same time:
#     - gdb without python support (add %%global _without_python 1 on top of
#       gdb's SPEC file)
#     - python-rpm-generators
#       (this can be done also during step 2., but should be done before 3.)
# 2. python3 without rewheel (use %%bcond_with rewheel instead of
#     %%bcond_without)
# 3. gdb with python support (remove %%global _without_python 1 on top of
#    gdb's SPEC file)
# 4. rpm
# 5. python-setuptools with bootstrap set to 1
# 6. python-pip with build_wheel set to 0
# 7. python-wheel with %%bcond_without bootstrap
# 8. python-setuptools with bootstrap set to 0 and also with_check set to 0
# 9. python-pip with build_wheel set to 1
# 10. pyparsing
# 11. python3 with rewheel
# Then the most important packages have to be built, in dependency order.
# These were:
#   python-sphinx, pytest, python-requests, cloud-init, dnf, anaconda, abrt
# After these have been built, a targeted rebuild should be done for the rest.

# =====================
# General global macros
# =====================

%global pylibdir %{_libdir}/python%{pybasever}
%global dynload_dir %{pylibdir}/lib-dynload

# ABIFLAGS, LDVERSION and SOABI are in the upstream
# See PEP 3149 for some background:
%global ABIFLAGS_optimized m
%global ABIFLAGS_debug     dm

%global LDVERSION_optimized %{pybasever}%{ABIFLAGS_optimized}
%global LDVERSION_debug     %{pybasever}%{ABIFLAGS_debug}

%global SOABI_optimized cpython-%{pyshortver}%{ABIFLAGS_optimized}-%{_arch}-linux%{_gnu}
%global SOABI_debug     cpython-%{pyshortver}%{ABIFLAGS_debug}-%{_arch}-linux%{_gnu}

# All bytecode files are in a __pycache__ subdirectory, with a name
# reflecting the version of the bytecode.
# See PEP 3147:
# For example,
#   foo/
# has bytecode at:
#   foo/__pycache__/bar.cpython-%%{pyshortver}.pyc
#   foo/__pycache__/bar.cpython-%%{pyshortver}.opt-1.pyc
#   foo/__pycache__/bar.cpython-%%{pyshortver}.opt-2.pyc
%global bytecode_suffixes .cpython-%{pyshortver}*.pyc

# Python's configure script defines SOVERSION, and this is used in the Makefile
# to determine INSTSONAME, the name of the libpython DSO:
#   LDLIBRARY='libpython$(VERSION).so'
# We mirror this here in order to make it easier to add the hooks.
# (if these get out of sync, the payload of the libs subpackage will fail
# and halt the build)
%global py_SOVERSION 1.0
%global py_INSTSONAME_optimized libpython%{LDVERSION_optimized}.so.%{py_SOVERSION}
%global py_INSTSONAME_debug     libpython%{LDVERSION_debug}.so.%{py_SOVERSION}

# Disable automatic bytecompilation. The python3 binary is not yet be
# available in /usr/bin when Python is built. Also, the bytecompilation fails
# on files that test invalid syntax.
%undefine py_auto_byte_compile

# For multilib support, files that are different between 32- and 64-bit arches
# need different filenames. Use "64" or "32" according to the word size.
# Currently, the best way to determine an architecture's word size happens to
# be checking %%{_lib}.
%if "%{_lib}" == "lib64"
%global wordsize 64
%global wordsize 32

# =======================
# Build-time requirements
# =======================

# (keep this list alphabetized)

BuildRequires: autoconf
BuildRequires: bluez-libs-devel
BuildRequires: bzip2
BuildRequires: bzip2-devel
BuildRequires: desktop-file-utils
BuildRequires: expat-devel

BuildRequires: findutils
BuildRequires: gcc-c++
%if %{with gdbm}
BuildRequires: gdbm-devel >= 1:1.13
BuildRequires: glibc-devel
BuildRequires: gmp-devel
BuildRequires: libappstream-glib
BuildRequires: libffi-devel
BuildRequires: libnsl2-devel
BuildRequires: libtirpc-devel
BuildRequires: libGL-devel
BuildRequires: libuuid-devel
BuildRequires: libX11-devel
BuildRequires: ncurses-devel

BuildRequires: openssl-devel
BuildRequires: pkgconfig
BuildRequires: readline-devel
BuildRequires: sqlite-devel
BuildRequires: gdb

BuildRequires: tar
BuildRequires: tcl-devel
BuildRequires: tix-devel
BuildRequires: tk-devel

%if %{with valgrind}
BuildRequires: valgrind-devel

BuildRequires: xz-devel
BuildRequires: zlib-devel

BuildRequires: /usr/bin/dtrace

# workaround (test_uuid requires ifconfig)
BuildRequires: /usr/sbin/ifconfig

%if %{with rewheel}
BuildRequires: python3-setuptools
BuildRequires: python3-pip

# =======================
# Source code and patches
# =======================


# A simple script to check timestamps of bytecode files
# Run in check section with Python that is currently being built
# Written by bkabrda

# Desktop menu entry for idle3
Source10: idle3.desktop

# AppData file for idle3
Source11: idle3.appdata.xml

# 00001 #
# Fixup distutils/ to remove standard library path from rpath:
# Was Patch0 in ivazquez' python3000 specfile:
Patch1:         00001-rpath.patch

# 00102 #
# Change the various install paths to use /usr/lib64/ instead or /usr/lib
# Only used when "%%{_lib}" == "lib64"
# Not yet sent upstream.
Patch102: 00102-lib64.patch

# 00111 #
# Patch the so that the generated Makefile doesn't try to build
# a libpythonMAJOR.MINOR.a
# See
# Downstream only: not appropriate for upstream
Patch111: 00111-no-static-lib.patch

# 00132 #
# Add non-standard hooks to unittest for use in the "check" phase below, when
# running selftests within the build:
#   @unittest._skipInRpmBuild(reason)
# for tests that hang or fail intermittently within the build environment, and:
#   @unittest._expectedFailureInRpmBuild
# for tests that always fail within the build environment
# The hooks only take effect if WITHIN_PYTHON_RPM_BUILD is set in the
# environment, which we set manually in the appropriate portion of the "check"
# phase below (and which potentially other python-* rpms could set, to reuse
# these unittest hooks in their own "check" phases)
Patch132: 00132-add-rpmbuild-hooks-to-unittest.patch

# 00155 #
# Avoid allocating thunks in ctypes unless absolutely necessary, to avoid
# generating SELinux denials on "import ctypes" and "import uuid" when
# embedding Python within httpd
# See
Patch155: 00155-avoid-ctypes-thunks.patch

# 00160 #
# Python 3.3 added os.SEEK_DATA and os.SEEK_HOLE, which may be present in the
# header files in the build chroot, but may not be supported in the running
# kernel, hence we disable this test in an rpm build.
# Adding these was upstream issue
# Not yet sent upstream
Patch160: 00160-disable-test_fs_holes-in-rpm-build.patch

# 00163 #
# Some tests within test_socket fail intermittently when run inside Koji;
# disable them using unittest._skipInRpmBuild
# Not yet sent upstream
Patch163: 00163-disable-parts-of-test_socket-in-rpm-build.patch

# 00170 #
# In debug builds, try to print repr() when a C-level assert fails in the
# garbage collector (typically indicating a reference-counting error
# somewhere else e.g in an extension module)
# The new macros/functions within gcmodule.c are hidden to avoid exposing
# them within the extension API.
# Sent upstream:
# See
Patch170: 00170-gc-assertions.patch

# 00178 #
# Don't duplicate various FLAGS in sysconfig values
# Does not affect python2 AFAICS (different sysconfig values initialization)
Patch178: 00178-dont-duplicate-flags-in-sysconfig.patch

# 00189 #
# Add the rewheel module, allowing to recreate wheels from already installed
# ones
Patch189: 00189-add-rewheel-module.patch

# 00205 #
# LIBPL variable in makefile takes LIBPL from
# but the LIBPL variable defined there doesn't respect libdir macro
Patch205: 00205-make-libpl-respect-lib64.patch

# 00251
# Set values of prefix and exec_prefix in distutils install command
# to /usr/local if executable is /usr/bin/python* and RPM build
# is not detected to make pip and distutils install into separate location
# Fedora Change:
Patch251: 00251-change-user-install-location.patch

# 00274 #
# Upstream uses Debian-style architecture naming. Change to match Fedora.
Patch274: 00274-fix-arch-names.patch

# 00291 #
# Build fails with undefined references to dlopen / dlsym otherwise.
# See:
# and:
Patch291: 00291-setup-Link-ctypes-against-dl-explicitly.patch

# (New patches go here ^^^)
# When adding new patches to "python" and "python3" in Fedora, EL, etc.,
# please try to keep the patch numbers in-sync between all specfiles.
# More information, and a patch number catalog, is at:

# ==========================================
# Descriptions, and metadata for subpackages
# ==========================================

%if %{without flatpackage}

# Packages with Python modules in standard locations automatically
# depend on python(abi). Provide that here.
Provides: python(abi) = %{pybasever}

# For backward compatibility only, remove in F29:
Provides: system-python(abi) = %{pybasever}
Provides: system-python = %{version}-%{release}
Provides: system-python%{?_isa} = %{version}-%{release}
Obsoletes: system-python < %{version}-%{release}

Requires: %{name}-libs%{?_isa} = %{version}-%{release}

# In order to support multiple Python interpreters for development purposes,
# packages with the naming scheme flatpackage (e.g. python35) exist for
# non-default versions of Python 3.
# For consistency, and to keep the upgrade path clean, we Provide/Obsolete
# these names here.
Provides: python%{pyshortver} = %{version}-%{release}
# Note that using Obsoletes without package version is not standard practice.
# Here we assert that *any* version of the system's default interpreter is
# preferable to an "extra" interpreter. For example, python3-3.6.1 will
# replace python36-3.6.2.
Obsoletes: python%{pyshortver}

# Shall be removed in Fedora 31
# The release is bumped to 20, so we can do f27 platform-python updates
# If the release in f27 ever goes >= 20, raise it here
# If platform-python is ever reintroduced, make it higher version than this:
%global platpyver 3.6.2-20
Obsoletes: platform-python < %{platpyver}

%if %{with rewheel}
Requires: python3-setuptools
Requires: python3-pip

# This prevents ALL subpackages built from this spec to require
# /usr/bin/python3*. Granularity per subpackage is impossible.
# It's intended for the libs package not to drag in the interpreter, see
# All others require %%{name} anyway.
%global __requires_exclude ^/usr/bin/python3

# The description used both for the SRPM and the main `python3` subpackage:
Python is an accessible, high-level, dynamically typed, interpreted programming
language, designed with an emphasis on code readability.
It includes an extensive standard library, and has a vast ecosystem of
third-party libraries.

The %{name} package provides the "python3" executable: the reference
interpreter for the Python language, version 3.
The majority of its standard library is provided in the %{name}-libs package,
which should be installed automatically along with %{name}.
The remaining parts of the Python standard library are broken out into the
%{name}-tkinter and %{name}-test packages, which may need to be installed

Documentation for Python is provided in the %{name}-docs package.

Packages containing additional libraries for Python are generally named with
the "%{name}-" prefix.

%package libs
Summary:        Python runtime libraries

# The "enum" module is included in the standard library.
# Provide an upgrade path from the external library.
Provides: python3-enum34 = 1.0.4-5%{?dist}
Obsoletes: python3-enum34 < 1.0.4-5%{?dist}

# Python 3 built with glibc >= 2.24.90-26 needs to require it
# See
Requires: glibc%{?_isa} >= 2.24.90-26

%if %{with gdbm}
# When built with this (as guarded by the BuildRequires above), require it
Requires: gdbm%{?_isa} >= 1:1.13

# There are files in the standard library that have python shebang.
# We've filtered the automatic requirement out so libs are installable without
# the main package. This however makes it pulled in by default.
# See
Recommends: %{name}%{?_isa} = %{version}-%{release}

# For backward compatibility only, remove in F29:
Provides: system-python-libs = %{version}-%{release}
Provides: system-python-libs%{?_isa} = %{version}-%{release}
Obsoletes: system-python-libs < %{version}-%{release}

# Shall be removed in Fedora 31
Obsoletes: platform-python-libs < %{platpyver}
Obsoletes: platform-python-libs-devel < %{platpyver}

%description libs
This package contains runtime libraries for use by Python:
- the majority of the Python standard library
- a dynamically linked library for use by applications that embed Python as
  a scripting language, and by the main "python3" executable

%package devel
Summary: Libraries and header files needed for Python development
Requires: %{name} = %{version}-%{release}
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
BuildRequires: python-rpm-macros
Requires: python-rpm-macros
Requires: python3-rpm-macros

%if %{with rewheel}
# without rewheel is used to bootstrap setuptools+pip
# python3-rpm-generators needs python3-setuptools, so we cannot have it yet
Requires: python3-rpm-generators

# TODO change to a specific subpackage once available (#1218294)
Requires: redhat-rpm-config

Provides: %{name}-2to3 = %{version}-%{release}
Provides: 2to3 = %{version}-%{release}

Conflicts: %{name} < %{version}-%{release}

# /usr/bin/2to3 was moved from python2-tools to python3-tools
# TODO Remove in Fedora 29
Conflicts: python2-tools < 2.7.13-17
Conflicts: python-tools < 2.7.13-17
# /usr/bin/2to3 was moved from python3-tools to python3-devel
# TODO Remove in Fedora 30
Conflicts: python3-tools < 3.7

# Shall be removed in Fedora 31
Obsoletes: platform-python-devel < %{platpyver}

%description devel
This package contains the header files and configuration needed to compile
Python extension modules (typically written in C or C++), to embed Python
into other programs, and to make binary distributions for Python libraries.

It also contains the necessary macros to build RPM packages with Python modules
and 2to3 tool, an automatic source converter from Python 2.X.

%package idle
Summary: A basic graphical development environment for Python
Requires: %{name} = %{version}-%{release}
Requires: %{name}-tkinter = %{version}-%{release}

Provides: idle3 = %{version}-%{release}

Provides: %{name}-tools = %{version}-%{release}
Provides: %{name}-tools%{?_isa} = %{version}-%{release}
Obsoletes: %{name}-tools < %{version}-%{release}

# Shall be removed in Fedora 31
Obsoletes: platform-python-tools < %{platpyver}

%description idle
IDLE is Python’s Integrated Development and Learning Environment.

IDLE has the following features: Python shell window (interactive
interpreter) with colorizing of code input, output, and error messages;
multi-window text editor with multiple undo, Python colorizing,
smart indent, call tips, auto completion, and other features;
search within any window, replace within editor windows, and
search through multiple files (grep); debugger with persistent
breakpoints, stepping, and viewing of global and local namespaces;
configuration, browsers, and other dialogs.

%package tkinter
Summary: A GUI toolkit for Python
Requires: %{name} = %{version}-%{release}

# Shall be removed in Fedora 31
Obsoletes: platform-python-tkinter < %{platpyver}

%description tkinter
The Tkinter (Tk interface) library is a graphical user interface toolkit for
the Python programming language.

%package test
Summary: The self-test suite for the main python3 package
Requires: %{name} = %{version}-%{release}

# Shall be removed in Fedora 31
Obsoletes: platform-python-test < %{platpyver}

%description test
The self-test suite for the Python interpreter.

This is only useful to test Python itself. For testing general Python code,
you should use the unittest module from %{name}-libs, or a library such as
%{name}-pytest or %{name}-nose.

%if %{with debug_build}
%package debug
Summary: Debug version of the Python runtime

# The debug build is an all-in-one package version of the regular build, and
# shares the same .py/.pyc files and directories as the regular build. Hence
# we depend on all of the subpackages of the regular build:
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
Requires: %{name}-devel%{?_isa} = %{version}-%{release}
Requires: %{name}-test%{?_isa} = %{version}-%{release}
Requires: %{name}-tkinter%{?_isa} = %{version}-%{release}
Requires: %{name}-idle%{?_isa} = %{version}-%{release}

%description debug
python3-debug provides a version of the Python runtime with numerous debugging
features enabled, aimed at advanced Python users such as developers of Python
extension modules.

This version uses more memory and will be slower than the regular Python build,
but is useful for tracking down reference-counting issues and other bugs.

The bytecode format is unchanged, so that .pyc files are compatible between
this and the standard version of Python, but the debugging features mean that
C/C++ extension modules are ABI-incompatible and must be built for each version

The debug build shares installation directories with the standard Python
runtime, so that .py and .pyc files can be shared.
Compiled extension modules use a special ABI flag ("d") in the filename,
so extensions for both versions can co-exist in the same directory.
%endif # with debug_build

%else  # with flatpackage

Requires: redhat-rpm-config

# We'll not provide this, on purpose
# No package in Fedora shall ever depend on flatpackage via this
%global __requires_exclude ^python\\(abi\\) = 3\\..$
%global __provides_exclude ^python\\(abi\\) = 3\\..$

# We keep those inside on purpose
Provides: bundled(python3-pip) = 10.0.1
Provides: bundled(python3-setuptools) = 39.0.1

# The description for the flat package
Python %{pybasever} package for developers.

This package exists to allow developers to test their code against a newer
version of Python. This is not a full Python stack and if you wish to run
your applications with Python %{pybasever}, update your Fedora to a newer
version once Python %{pybasever} is stable.

%endif # with flatpackage

# ======================================================
# The prep phase of the build:
# ======================================================

%setup -q -n Python-%{version}%{?prerel}

# Remove bundled libraries to ensure that we're using the system copy.
rm -r Modules/expat

%if %{with rewheel}
%global pip_version 9.0.1
sed -r -i s/'_PIP_VERSION = "[0-9.]+"'/'_PIP_VERSION = "%{pip_version}"'/ Lib/ensurepip/

# Apply patches:
%patch1 -p1

%if "%{_lib}" == "lib64"
%patch102 -p1
%patch111 -p1
%patch132 -p1
%patch155 -p1
%patch160 -p1
%patch163 -p1
%patch170 -p1
%patch178 -p1

%if %{with rewheel}
%patch189 -p1

%patch205 -p1
%patch251 -p1
%patch274 -p1
%patch291 -p1

# Remove files that should be generated by the build
# (This is after patching, so that we can use patches directly from upstream)
rm configure

# ======================================================
# Configuring and building the code:
# ======================================================


# Regenerate the configure script and

# Remember the current directory (which has sources and the configure script),
# so we can refer to it after we "cd" elsewhere.

# Get proper option names from bconds
%if %{with computed_gotos}
%global computed_gotos_flag yes
%global computed_gotos_flag no

%if %{with optimizations}
%global optimizations_flag "--enable-optimizations"
%global optimizations_flag "--disable-optimizations"

# Set common compiler/linker flags
export CPPFLAGS="$(pkg-config --cflags-only-I libffi)"
export OPT="$RPM_OPT_FLAGS -D_GNU_SOURCE -fPIC -fwrapv"
export LINKCC="gcc"
export CFLAGS="$CFLAGS $(pkg-config --cflags openssl)"
export LDFLAGS="$RPM_LD_FLAGS -g $(pkg-config --libs-only-L openssl)"

# We can build several different configurations of Python: regular and debug.
# Define a common function that does one build:
BuildPython() {

  # Each build is done in its own directory
  mkdir -p $ConfDir
  pushd $ConfDir

  # Normally, %%configure looks for the "configure" script in the current
  # directory.
  # Since we changed directories, we need to tell %%configure where to look.
  %global _configure $topdir/configure

%configure \
  --enable-ipv6 \
  --enable-shared \
  --with-computed-gotos=%{computed_gotos_flag} \
  --with-dbmliborder=gdbm:ndbm:bdb \
  --with-system-expat \
  --with-system-ffi \
  --enable-loadable-sqlite-extensions \
  --with-dtrace \
  --with-lto \
  --with-ssl-default-suites=openssl \
%if %{with valgrind}
  --with-valgrind \
  $ExtraConfigArgs \

  # Invoke the build
  make EXTRA_CFLAGS="$CFLAGS $MoreCFlags" %{?_smp_mflags}


# Call the above to build each configuration.

%if %{with debug_build}
BuildPython debug \
  "--without-ensurepip --with-pydebug" \
%endif # with debug_build

BuildPython optimized \
  "--without-ensurepip %{optimizations_flag}" \

# ======================================================
# Installing the built code:
# ======================================================


# As in %%build, remember the current directory

# We install a collection of hooks for gdb that make it easier to debug
# executables linked against libpython3* (such as /usr/bin/python3 itself)
# These hooks are implemented in Python itself (though they are for the version
# of python that gdb is linked with)
# gdb-archer looks for them in the same path as the ELF file or its .debug
# file, with a suffix.
# We put them next to the debug file, because ldconfig would complain if
# it found non-library files directly in /usr/lib/
# (see
# We'll put these files in the debuginfo package by installing them to e.g.:
#  /usr/lib/debug/usr/lib/
# (note that the debug path is /usr/lib/debug for both 32/64 bit)
# See for more
# information

%if %{with gdb_hooks}
mkdir -p %{buildroot}$DirHoldingGdbPy
%endif # with gdb_hooks

# Multilib support for pyconfig.h
# 32- and 64-bit versions of pyconfig.h are different. For multilib support
# (making it possible to install 32- and 64-bit versions simultaneously),
# we need to install them under different filenames, and to make the common
# "pyconfig.h" include the right file based on architecture.
# See
# Filanames are defined here:
%global _pyconfig32_h pyconfig-32.h
%global _pyconfig64_h pyconfig-64.h
%global _pyconfig_h pyconfig-%{wordsize}.h

# Use a common function to do an install for all our configurations:
InstallPython() {


  # Switch to the directory with this configuration's built files
  mkdir -p $ConfDir
  pushd $ConfDir

  make \
    DESTDIR=%{buildroot} \
    INSTALL="install -p" \
    EXTRA_CFLAGS="$MoreCFlags" \


%if %{with gdb_hooks}
  # See comment on $DirHoldingGdbPy above
  cp Tools/gdb/ %{buildroot}$PathOfGdbPy
%endif # with gdb_hooks

  # Rename the -devel script that differs on different arches to arch specific name
  mv %{buildroot}%{_bindir}/python${LDVersion}-{,`uname -m`-}config
  echo -e '#!/bin/sh\nexec `dirname $0`/python'${LDVersion}'-`uname -m`-config "$@"' > \
  echo '[ $? -eq 127 ] && echo "Could not find python'${LDVersion}'-`uname -m`-config. Look around to see available arches." >&2' >> \
    chmod +x %{buildroot}%{_bindir}/python${LDVersion}-config

  # Make python3-devel multilib-ready
  mv %{buildroot}%{_includedir}/python${LDVersion}/pyconfig.h \
  cat > %{buildroot}%{_includedir}/python${LDVersion}/pyconfig.h << EOF
#include <bits/wordsize.h>

#if __WORDSIZE == 32
#include "%{_pyconfig32_h}"
#elif __WORDSIZE == 64
#include "%{_pyconfig64_h}"
#error "Unknown word size"


# Install the "debug" build first; any common files will be overridden with
# later builds
%if %{with debug_build}
InstallPython debug \
  %{py_INSTSONAME_debug} \
  -O0 \
%endif # with debug_build

# Now the optimized build:
InstallPython optimized \
  %{py_INSTSONAME_optimized} \
  "" \

# Install directories for additional packages
install -d -m 0755 %{buildroot}%{pylibdir}/site-packages/__pycache__
%if "%{_lib}" == "lib64"
# The 64-bit version needs to create "site-packages" in /usr/lib/ (for
# pure-Python modules) as well as in /usr/lib64/ (for packages with extension
# modules).
# Note that rpmlint will complain about hardcoded library path;
# this is intentional.
install -d -m 0755 %{buildroot}%{_prefix}/lib/python%{pybasever}/site-packages/__pycache__

%if %{without flatpackage}
# add idle3 to menu
install -D -m 0644 Lib/idlelib/Icons/idle_16.png %{buildroot}%{_datadir}/icons/hicolor/16x16/apps/idle3.png
install -D -m 0644 Lib/idlelib/Icons/idle_32.png %{buildroot}%{_datadir}/icons/hicolor/32x32/apps/idle3.png
install -D -m 0644 Lib/idlelib/Icons/idle_48.png %{buildroot}%{_datadir}/icons/hicolor/48x48/apps/idle3.png
desktop-file-install --dir=%{buildroot}%{_datadir}/applications %{SOURCE10}

# Install and validate appdata file
mkdir -p %{buildroot}%{_datadir}/appdata
cp -a %{SOURCE11} %{buildroot}%{_datadir}/appdata
appstream-util validate-relax --nonet %{buildroot}%{_datadir}/appdata/idle3.appdata.xml

# Make sure distutils looks at the right pyconfig.h file
# See
# Similar for sysconfig: sysconfig.get_config_h_filename tries to locate
# pyconfig.h so it can be parsed, and needs to do this at runtime in
# when python starts up (see
# Split this out so it goes directly to the pyconfig-32.h/pyconfig-64.h
# variants:
sed -i -e "s/'pyconfig.h'/'%{_pyconfig_h}'/" \
  %{buildroot}%{pylibdir}/distutils/ \

# Install to bindir
# See
cp -p Tools/scripts/ %{buildroot}%{_bindir}/

# Switch all shebangs to refer to the specific Python version.
# This currently only covers files matching ^[a-zA-Z0-9_]+\.py$,
# so handle files named using other naming scheme separately.
LD_LIBRARY_PATH=./build/optimized ./build/optimized/python \
  Tools/scripts/ \
  -i "%{_bindir}/python%{pybasever}" -pn \
  %{buildroot} \

# Remove tests for python3-tools which was removed in
rm -rf %{buildroot}%{pylibdir}/test/test_tools

# Remove shebang lines from .py files that aren't executable, and
# remove executability from .py files that don't have a shebang line:
find %{buildroot} -name \*.py \
  \( \( \! -perm /u+x,g+x,o+x -exec sed -e '/^#!/Q 0' -e 'Q 1' {} \; \
  -print -exec sed -i '1d' {} \; \) -o \( \
  -perm /u+x,g+x,o+x ! -exec grep -m 1 -q '^#!' {} \; \
  -exec chmod a-x {} \; \) \)

# Get rid of DOS batch files:
find %{buildroot} -name \*.bat -exec rm {} \;

# Get rid of backup files:
find %{buildroot}/ -name "*~" -exec rm -f {} \;
find . -name "*~" -exec rm -f {} \;

# Get rid of a stray copy of the license:
rm %{buildroot}%{pylibdir}/LICENSE.txt

# Do bytecompilation with the newly installed interpreter.
# This is similar to the script in macros.pybytecompile
# compile *.pyc
find %{buildroot} -type f -a -name "*.py" -print0 | \
    LD_LIBRARY_PATH="%{buildroot}%{dynload_dir}/:%{buildroot}%{_libdir}" \
    PYTHONPATH="%{buildroot}%{_libdir}/python%{pybasever} %{buildroot}%{_libdir}/python%{pybasever}/site-packages" \
    xargs -0 %{buildroot}%{_bindir}/python%{pybasever} -O -c 'import py_compile, sys; [py_compile.compile(f, dfile=f.partition("%{buildroot}")[2], optimize=opt) for opt in range(3) for f in sys.argv[1:]]' || :

# Since we have in bindir, this is created, but we don't want it
rm -rf %{buildroot}%{_bindir}/__pycache__

# Fixup permissions for shared libraries from non-standard 555 to standard 755:
find %{buildroot} -perm 555 -exec chmod 755 {} \;

# Create "/usr/bin/python3-debug", a symlink to the python3 debug binary, to
# avoid the user having to know the precise version and ABI flags.
# See e.g.
%if %{with debug_build} && %{without flatpackage}
ln -s \
  %{_bindir}/python%{LDVERSION_debug} \

# System Python: Link the executable to libexec
# This is for backwards compatibility only and should be removed in Fedora 29
%if %{without flatpackage}
mkdir -p %{buildroot}%{_libexecdir}
ln -s %{_bindir}/python%{pybasever} %{buildroot}%{_libexecdir}/system-python

# There's 2to3-X.X executable and 2to3 soft link to it.
# No reason to have both, so keep only 2to3 as an executable.
# See
mv %{buildroot}%{_bindir}/2to3-%{pybasever} %{buildroot}%{_bindir}/2to3

%if %{with flatpackage}
# Remove stuff that would conflict with python3 package
rm %{buildroot}%{_bindir}/python3
rm %{buildroot}%{_bindir}/pydoc3
rm %{buildroot}%{_bindir}/
rm %{buildroot}%{_bindir}/idle3
rm %{buildroot}%{_bindir}/python3-*
rm %{buildroot}%{_bindir}/pyvenv
rm %{buildroot}%{_bindir}/2to3
rm %{buildroot}%{_libdir}/
rm %{buildroot}%{_mandir}/man1/python3.1*
rm %{buildroot}%{_libdir}/pkgconfig/python3.pc

# ======================================================
# Checks for packaging issues
# ======================================================


# first of all, check timestamps of bytecode files
find %{buildroot} -type f -a -name "*.py" -print0 | \
    LD_LIBRARY_PATH="%{buildroot}%{dynload_dir}/:%{buildroot}%{_libdir}" \
    PYTHONPATH="%{buildroot}%{_libdir}/python%{pybasever} %{buildroot}%{_libdir}/python%{pybasever}/site-packages" \
    xargs -0 %{buildroot}%{_bindir}/python%{pybasever} %{SOURCE8}

# Ensure that the curses module was linked against, rather than
# See
ldd %{buildroot}/%{dynload_dir}/_curses*.so \
    | grep curses \
    | grep && (echo " linked against" ; exit 1)

# Ensure that the debug modules are linked against the debug libpython, and
# likewise for the optimized modules and libpython:
for Module in %{buildroot}/%{dynload_dir}/*.so ; do
    case $Module in
        ldd $Module | grep %{py_INSTSONAME_optimized} &&
            (echo Debug module $Module linked against optimized %{py_INSTSONAME_optimized} ; exit 1)

        ldd $Module | grep %{py_INSTSONAME_debug} &&
            (echo Optimized module $Module linked against debug %{py_INSTSONAME_debug} ; exit 1)

# ======================================================
# Running the upstream test suite
# ======================================================

CheckPython() {


  # Note that we're running the tests using the version of the code in the
  # builddir, not in the buildroot.

  # Run the upstream test suite, setting "WITHIN_PYTHON_RPM_BUILD" so that the
  # our non-standard decorators take effect on the relevant tests:
  #   @unittest._skipInRpmBuild(reason)
  #   @unittest._expectedFailureInRpmBuild
  LD_LIBRARY_PATH=$ConfDir $ConfDir/python -m test.regrtest \
    -wW --slowest --findleaks \
    -x test_distutils \
    -x test_bdist_rpm \
    %ifarch %{mips64}
    -x test_ctypes \
    %ifarch %{power64} s390 s390x armv7hl %{mips}
    -x test_gdb \
    %ifarch ppc64le
    -x test_buffer \



%if %{with tests}

# Check each of the configurations:
%if %{with debug_build}
CheckPython debug
%endif # with debug_build
CheckPython optimized

%endif # with tests

%defattr(-, root, root)
%license LICENSE
%doc README.rst

%if %{without flatpackage}
# Remove in Fedora 29:


%if %{without flatpackage}
%files libs
%license LICENSE
%doc README.rst

%dir %{pylibdir}
%dir %{dynload_dir}

%if %{without flatpackage}
%exclude %{pylibdir}/lib2to3/tests

%dir %{pylibdir}/unittest/
%dir %{pylibdir}/unittest/__pycache__/

%dir %{pylibdir}/asyncio/
%dir %{pylibdir}/asyncio/__pycache__/

%dir %{pylibdir}/venv/
%dir %{pylibdir}/venv/__pycache__/


%dir %{pylibdir}/ensurepip/
%dir %{pylibdir}/ensurepip/__pycache__/

%if %{without flatpackage}
%exclude %{pylibdir}/ensurepip/_bundled
%dir %{pylibdir}/ensurepip/_bundled

%if %{with rewheel}
%dir %{pylibdir}/ensurepip/rewheel/
%dir %{pylibdir}/ensurepip/rewheel/__pycache__/

%dir %{pylibdir}/test/
%dir %{pylibdir}/test/__pycache__/
%dir %{pylibdir}/test/support/
%dir %{pylibdir}/test/support/__pycache__/

%dir %{pylibdir}/concurrent/
%dir %{pylibdir}/concurrent/__pycache__/

%dir %{pylibdir}/concurrent/futures/
%dir %{pylibdir}/concurrent/futures/__pycache__/



%if %{with gdbm}

%dir %{pylibdir}/site-packages/
%dir %{pylibdir}/site-packages/__pycache__/
%dir %{pylibdir}/__pycache__/

%dir %{pylibdir}/collections/
%dir %{pylibdir}/collections/__pycache__/

%dir %{pylibdir}/ctypes/
%dir %{pylibdir}/ctypes/__pycache__/


%dir %{pylibdir}/dbm/
%dir %{pylibdir}/dbm/__pycache__/

%dir %{pylibdir}/distutils/
%dir %{pylibdir}/distutils/__pycache__/
%exclude %{pylibdir}/distutils/command/wininst-*.exe

%dir %{pylibdir}/email/
%dir %{pylibdir}/email/__pycache__/
%doc %{pylibdir}/email/architecture.rst



%dir %{pylibdir}/importlib/
%dir %{pylibdir}/importlib/__pycache__/

%dir %{pylibdir}/json/
%dir %{pylibdir}/json/__pycache__/


%dir %{pylibdir}/sqlite3/
%dir %{pylibdir}/sqlite3/__pycache__/

%if %{without flatpackage}
%exclude %{pylibdir}/
%exclude %{pylibdir}/__pycache__/turtle*%{bytecode_suffixes}


%if "%{_lib}" == "lib64"
%attr(0755,root,root) %dir %{_prefix}/lib/python%{pybasever}
%attr(0755,root,root) %dir %{_prefix}/lib/python%{pybasever}/site-packages
%attr(0755,root,root) %dir %{_prefix}/lib/python%{pybasever}/site-packages/__pycache__/

# "Makefile" and the config-32/64.h file are needed by
# distutils/, so we include them in the core
# package, along with their parent directories (bug 531901):
%dir %{pylibdir}/config-%{LDVERSION_optimized}-%{_arch}-linux%{_gnu}/
%dir %{_includedir}/python%{LDVERSION_optimized}/

%if %{without flatpackage}

%if %{without flatpackage}
%files devel

%if %{without flatpackage}
%exclude %{pylibdir}/config-%{LDVERSION_optimized}-%{_arch}-linux%{_gnu}/Makefile
%exclude %{_includedir}/python%{LDVERSION_optimized}/%{_pyconfig_h}
%doc Misc/README.valgrind Misc/valgrind-python.supp Misc/gdbinit

%if %{without flatpackage}


%if %{without flatpackage}
%files idle



%if %{without flatpackage}

%if %{without flatpackage}
%files tkinter

%if %{without flatpackage}
%exclude %{pylibdir}/tkinter/test
%dir %{pylibdir}/turtledemo
%dir %{pylibdir}/turtledemo/__pycache__/

%if %{without flatpackage}
%files test
%defattr(-, root, root)


# We don't bother splitting the debug build out into further subpackages:
# if you need it, you're probably a developer.

# Hence the manifest is the combination of analogous files in the manifests of
# all of the other subpackages

%if %{with debug_build}
%if %{without flatpackage}
%files debug

# Analog of the core subpackage's files:

# Analog of the -libs subpackage's files:
# ...with debug builds of the built-in "extension" modules:


%if %{with gdbm}

# No need to split things out the "Makefile" and the config-32/64.h file as we
# do for the regular build above (bug 531901), since they're all in one package
# now; they're listed below, under "-devel":


# Analog of the -devel subpackage's files:

# Analog of the -tools subpackage's files:
#  None for now; we could build precanned versions that have the appropriate
# shebang if needed

# Analog  of the tkinter subpackage's files:

# Analog  of the -test subpackage's files:

%endif # with debug_build

# We put the file inside /usr/lib/debug to avoid noise from ldconfig
# See
# The /usr/lib/rpm/redhat/macros defines %%__debug_package to use
# debugfiles.list, and it appears that everything below /usr/lib/debug and
# (/usr/src/debug) gets added to this file (via LISTFILES) in
# /usr/lib/rpm/
# Hence by installing it below /usr/lib/debug we ensure it is added to the
# -debuginfo subpackage
# (if it doesn't, then the rpmbuild ought to fail since the
# payload file would be unpackaged)

# Workaround for
%undefine _debuginfo_subpackages

# ======================================================
# Finally, the changelog:
# ======================================================

* Tue Jun 12 2018 Miro Hrončok <> - 3.7.0-0.20.rc1
- Update to 3.7.0rc1

* Thu May 31 2018 Miro Hrončok <> - 3.7.0-0.19.b5
- Update to 3.7.0b5

* Sat May 12 2018 Miro Hrončok <> - 3.7.0-0.18.b4
- Bump the bundled pip version to 10.0.1

* Thu May 10 2018 Miro Hrončok <> - 3.7.0-0.17.b4
- Update to 3.7.0b4

* Mon Apr 23 2018 Miro Hrončok <> - 3.7.0-0.16.b3
- Fix multiprocessing regression on newer glibcs
- Enable test_multiprocessing_fork(server) and _spawn again
Resolves: rhbz#1569933

* Thu Apr 19 2018 Miro Hrončok <> - 3.7.0-0.15.b3
- Skip test_multiprocessing_fork(server) and _spawn for now

* Thu Mar 29 2018 Miro Hrončok <> - 3.7.0-0.14.b3
- Update to 3.7.0b3

* Sat Mar 24 2018 Miro Hrončok <> - 3.7.0-0.13.b2
- Fix broken macro invocation and broken building of C Python extensions
Resolves: rhbz#1560103

* Wed Feb 28 2018 Miro Hrončok <> - 3.7.0-0.12.b2
- Update to 3.7.0b2

* Wed Feb 21 2018 Miro Hrončok <> - 3.7.0-0.11.b1
- Fix the py_byte_compile macro to work on Python 2
- Remove the pybytecompile macro file from the flat package
Resolves: rhbz#1484993

* Wed Feb 21 2018 Miro Hrončok <> - 3.7.0-0.10.b1
- Filter out automatic /usr/bin/python3.X requirement,
  recommend the main package from libs instead
Resolves: rhbz#1547131

* Thu Feb 15 2018 Michal Cyprian <> - 3.7.0-0.9.b1
- Remove sys.executable check from change-user-install-location patch
Resolves: rhbz#1532287

* Wed Feb 14 2018 Miro Hrončok <> - 3.7.0-0.8.b1
- Readd ldconfig scriplets via macro (later removed on F28+ only)

* Mon Feb 12 2018 Iryna Shcherbina <> - 3.7.0-0.7.b1
- Update to 3.7.0b1
- Define TLS cipher suite on build time

* Fri Feb 09 2018 Fedora Release Engineering <> - 3.7.0-0.6.a4
- Rebuilt for

* Fri Jan 26 2018 Iryna Shcherbina <> - 3.7.0-0.5.a4
- Remove the python3-tools package (#rhbz 1312030)
- Move /usr/bin/2to3 to python3-devel
- Move /usr/bin/idle and idlelib to python3-idle
- Provide python3-tools from python3-idle

* Sat Jan 20 2018 Björn Esser <> - 3.7.0-0.4.a4
- Rebuilt for switch to libxcrypt

* Thu Jan 18 2018 Miro Hrončok <> - 3.7.0-0.3.a4
- Remove /usr/bin/python37 (#1526129)
- Move install stuff from %%check to %%install, where it belongs (oops)

* Tue Jan 09 2018 Miro Hrončok <> - 3.7.0-0.2.a4
- Update to 3.7.0 alpha 4
- Fix the compilation of the nis module

* Tue Nov 28 2017 Miro Hrončok <> - 3.7.0-0.1.a2
- Update to 3.7.0 alpha 2
- Removed merged patches 262, 277, 279