File python.spec of Package python313

%define realname Python
%define realver  3.13.2

# See Lib/ensurepip/_bundled/
%define pip_ver        24.3.1
# See ./Lib/test/wheeldata/
%define setuptools_ver 67.6.1

%define py_ver   %(awk -F. '{printf "%i.%i", $1, $2}' <<< %{realver})
%define py_gen   %(tr -d . <<< %{py_ver})

%define so_ver   1
%define so_lib   %{so_ver}_0
%define lib_ver  %(tr . _ <<< %{py_ver})

%define python_sitelib  %{_prefix}/lib/python%{py_ver}/site-packages
%define python_sitearch %{_libdir}/python%{py_ver}/site-packages

%if 0%{?rhel}
%undefine _annotated_build
# Turn off the brp-python-bytecompile script
%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')
%endif

# Common info
Name:          python%{py_gen}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       Python-2.0
Group:         Development/Languages/Python
URL:           https://www.python.org/
Summary:       A high-level object-oriented programming language

# Install-time parameters
Provides:      python(abi) = %{py_ver}
Provides:      python3 = %{version}-%{release}
%if 0%{?suse_version}
Provides:      python%{py_gen}-base = %{version}-%{release}
Provides:      python3-base = %{version}-%{release}
Requires:      update-alternatives
%else
Provides:      python%{py_gen}-libs = %{version}-%{release}
Provides:      python3-libs = %{version}-%{release}
Requires:      chkconfig
%endif

# Build-time parameters
BuildRequires: xz
BuildRequires: gcc-c++
BuildRequires: pkg-config
BuildRequires: pkgconfig(uuid) >= 2.20
BuildRequires: pkgconfig(libffi)
### BuildRequires: pkgconfig(libmpdec) >= 2.5.0
BuildRequires: pkgconfig(sqlite3) >= 3.15.2
BuildRequires: pkgconfig(zlib) >= 1.2.0
BuildRequires: pkgconfig(bzip2)
BuildRequires: pkgconfig(liblzma)
BuildRequires: pkgconfig(libedit)
BuildRequires: pkgconfig(ncurses)
### BuildRequires: pkgconfig(libb2)
BuildRequires: pkgconfig(openssl)
BuildRequires: gdbm-devel
%if 0%{?suse_version}
BuildRequires: db-devel
### BuildRequires: libexpat-devel
%else
BuildRequires: libdb-devel
### BuildRequires: expat-devel
%endif
%if 0%{?suse_version}
BuildRequires: fdupes
%endif
BuildRoot:     %{_tmppath}/%{name}-root
Source:        https://www.python.org/ftp/python/%{realver}/%{realname}-%{realver}.tar.xz

# PATCH-FEATURE-UPSTREAM F00251-change-user-install-location.patch bsc#[0-9]+ mcepl@suse.com
# Fix installation in /usr/local (boo#1071941), originally from Fedora
# https://src.fedoraproject.org/rpms/python3/blob/master/f/00251-change-user-install-location.patch
# 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
Patch02:        F00251-change-user-install-location.patch

# support finding packages in /usr/local, install to /usr/local by default
Patch07:        python-3.3.0b1-localpath.patch

# POSIX_FADV_WILLNEED throws EINVAL. Use a different constant in test
Patch09:        python-3.3.0b1-test-posix_fadvise.patch

%description
Python is an interpreted, interactive, object-oriented programming
language. It is often compared to Tcl, Perl, Scheme or Java.

Python combines remarkable power with very clear syntax. It has
modules, classes, exceptions, very high level dynamic data types, and
dynamic typing. There are interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac, MFC). New built-in modules are easily written in C or C++. Python
is also usable as an extension language for applications that need a
programmable interface.

The Python implementation is portable: it runs on many brands of UNIX,
on Windows, DOS, Mac, Amiga... If your favorite system isn't
listed here, it may still be supported, if there's a C compiler for
it. Ask around on comp.lang.python -- or just try compiling Python
yourself.

%package devel
Group:         Development/Languages/C and C++
Summary:       Development stuff for %{name}

Requires:      libpython%{lib_ver}-%{so_lib} = %{version}-%{release}
Provides:      libpython%{lib_ver}-%{so_lib}-devel = %{version}-%{release}
Provides:      python3-devel = %{version}-%{release}

%description devel
This package contains headers and libraries required to build software
against %{name}.

%package pip
Version:       %{pip_ver}
Group:         Development/Languages/Python
URL:           https://pip.pypa.io/
Summary:       The PyPA recommended tool for installing Python packages

Requires:      python(abi) = %{py_ver}
Provides:      python3-pip = %{pip_ver}-%{release}
Obsoletes:     python3-pip < %{pip_ver}-%{release}
%if 0%{?suse_version}
Requires:      update-alternatives
%else
Requires:      chkconfig
%endif

BuildArch:     noarch

%description pip
pip supports installing from PyPI, version control, local projects, and
directly from distribution files.

The most common scenario is to install from PyPI using Requirement Specifiers.

%package -n libpython%{lib_ver}-%{so_lib}
Version:       %{realver}
Group:         System/Libraries
Summary:       Python %{py_ver} shared library

%description -n libpython%{lib_ver}-%{so_lib}
This package provides Python %{py_ver} shared library.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{version}%{?extraver}
%patch02 -p1
%patch07 -p1
%patch09 -p1

# Build/compile
%build
_CFLAGS='%{optflags}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro'
%{configure} \
  --enable-shared \
  --enable-optimizations \
  --enable-loadable-sqlite-extensions \
  --disable-test-modules \
  \
  --without-static-libpython \
%if 0%{?gcc_lto:1}
  --with-lto \
%endif
  --without-system-expat \
  --with-dbmliborder=bdb:gdbm \
  --with-platlibdir=%{_lib} \
  --with-readline=editline \
  --with-ssl-default-suites=openssl \
  \
  CXX=%{_bindir}/g++ \
  CFLAGS="$_CFLAGS" \
  CXXFLAGS="$_CFLAGS" \
  LDFLAGS="$_LDFLAGS"
export DISTUTILS_DEBUG=1
%{__make} %{?_smp_mflags}

# Install built software
%install
%{__make} install DESTDIR=%{buildroot}
%if %{__isa_bits} == 64
[ -d %{buildroot}%{_libdir}/python%{py_ver}/site-packages ] || %{__mkdir_p} %{buildroot}%{_libdir}/python%{py_ver}/site-packages
%endif
# Prepare alternatives
[ "%{buildroot}" != "/" ] && %{__rm} -vf %{buildroot}%{_bindir}/{idle,pip,pydoc,python}3 %{buildroot}%{_mandir}/man1/python3.1*
%{__install} -D -m0644 Misc/python.man %{buildroot}%{_mandir}/man1/python%{py_ver}.1
%{__install} -d -m755 %{buildroot}%{_sysconfdir}/alternatives/
# Python binaries
touch %{buildroot}%{_sysconfdir}/alternatives/idle3
touch %{buildroot}%{_sysconfdir}/alternatives/pydoc3
touch %{buildroot}%{_sysconfdir}/alternatives/python3
# pip
touch %{buildroot}%{_sysconfdir}/alternatives/pip3
# Alternatives symlinks
for alt in %{buildroot}%{_sysconfdir}/alternatives/*; do
    bin=${alt##*/}
    %{__ln_s} -f %{_sysconfdir}/alternatives/$bin %{buildroot}%{_bindir}/$bin
done
# Manpage
touch %{buildroot}%{_sysconfdir}/alternatives/python3.1
%{__ln_s} -f %{_sysconfdir}/alternatives/python3.1 %{buildroot}%{_mandir}/man1/python3.1.gz
# Fix shebang line
%{__sed} -i -e '1 s|^#! *%{_bindir}/python$|#!%{_bindir}/python%{py_ver}|' %{buildroot}%{_bindir}/pip%{py_ver}
find %{buildroot}%{_prefix}/lib/python%{py_ver}/ %{buildroot}%{_libdir}/python%{py_ver}/ -name \*.py \
  | xargs -n1 %{__sed} -i \
    -e '1 s|^#! */usr/bin/env .*$|#!%{_bindir}/python%{py_ver}|' \
    -e '1 s|^#! */usr/local/bin/python.*$|#!%{_bindir}/python%{py_ver}|'
# compileall
if [ '%{buildroot}' != '/' ]; then
    LD_LIBRARY_PATH=%{buildroot}%{_libdir} \
    PYTHONHOME=%{buildroot}%{_prefix} \
        %{buildroot}%{_bindir}/python%{py_ver} -m compileall -q %{?_smp_mflags} -o 2 \
            %{buildroot}%{_prefix}/lib/python%{py_ver} \
            %{buildroot}%{_libdir}/python%{py_ver} \
            %{buildroot}%{python_sitelib}
fi
# Remove file duplicates
%if 0%{?suse_version}
%fdupes %{buildroot}%{_prefix}
%endif

# Cleanup
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

# Files list
%files
%defattr(-,root,root)
%license LICENSE
%doc README.rst Misc/NEWS
%{_bindir}/idle3
%{_bindir}/idle%{py_ver}
%{_bindir}/pydoc3
%{_bindir}/pydoc%{py_ver}
%{_bindir}/python3
%{_bindir}/python%{py_ver}
%ghost %{_sysconfdir}/alternatives/idle3
%ghost %{_sysconfdir}/alternatives/pydoc3
%ghost %{_sysconfdir}/alternatives/python3
%ghost %{_sysconfdir}/alternatives/python3.1
%{_prefix}/lib/python%{py_ver}/
%{_libdir}/python%{py_ver}/
%doc %{_mandir}/man1/python%{py_ver}.1*
%doc %{_mandir}/man1/python3.1*
%exclude %{python_sitelib}/*
%exclude %{_libdir}/python%{py_ver}/config-%{py_ver}-%{_arch}-%{_os}%{?_gnu}/

%files devel
%defattr(-,root,root)
%{_bindir}/python3
%{_bindir}/python%{py_ver}-config
%{_includedir}/python%{py_ver}/
%{_libdir}/libpython%{py_ver}.so
%{_libdir}/libpython3.so
%{_libdir}/pkgconfig/*.pc
%{_libdir}/python%{py_ver}/config-%{py_ver}-%{_arch}-%{_os}%{?_gnu}/
%exclude %{_bindir}/python3-config

%files pip
%defattr(-,root,root)
%{_bindir}/pip3
%{_bindir}/pip%{py_ver}
%{python_sitelib}/pip/
%{python_sitelib}/pip-%{pip_ver}.dist-info/
%ghost %{_sysconfdir}/alternatives/pip3

%files -n libpython%{lib_ver}-%{so_lib}
%defattr(-,root,root)
%{_libdir}/libpython%{py_ver}.so.%{so_ver}*

%post
/usr/sbin/update-alternatives \
    --install %{_bindir}/python3 python3 %{_bindir}/python%{py_ver} %{py_gen} \
    --slave   %{_bindir}/idle3   idle3   %{_bindir}/idle%{py_ver} \
    --slave   %{_bindir}/pydoc3  pydoc3  %{_bindir}/pydoc%{py_ver} \
    --slave   %{_mandir}/man1/python3.1.gz python3.1 %{_mandir}/man1/python%{py_ver}.1.gz

%preun
if [ $1 -eq 0 ]; then
    /usr/sbin/update-alternatives --remove python3 %{_bindir}/python%{py_ver}
fi

%postun
/usr/sbin/update-alternatives --auto python3

%post pip
/usr/sbin/update-alternatives \
    --install %{_bindir}/pip3 pip3 %{_bindir}/pip%{py_ver} %{py_gen}

%preun pip
if [ $1 -eq 0 ]; then
    /usr/sbin/update-alternatives --remove pip3 %{_bindir}/pip%{py_ver}
fi

%postun pip
/usr/sbin/update-alternatives --auto pip3

%post   -n libpython%{lib_ver}-%{so_lib} -p /sbin/ldconfig
%postun -n libpython%{lib_ver}-%{so_lib} -p /sbin/ldconfig

%changelog
openSUSE Build Service is sponsored by