File opt-python27.spec of Package opt-python27

%define pyversion        2.7.18
%define pipversion       19.2.3
%define stversion        41.2.0
%define vmajor           %(echo %{pyversion} | head -c 1)
%define vminor           %(echo %{pyversion} | head -c 3 | tail -c 1)
%define vmicro           %(echo %{pyversion} | head -c 6 | tail -c 2)
%define pyver            %{vmajor}.%{vminor}
%define nver             %{vmajor}%{vminor}
%define _prefix          /opt/python
%define _libdir          %{_prefix}/lib
%define python_sitelib   %{_libdir}/python%{pyver}/site-packages

%global with_pip         1
%global with_setuptools  1

Name:           opt-python%{nver}
Version:        %{pyversion}
Release:        1
Summary:        Python Interpreter
License:        Python-2.0
Group:          Development/Languages/Python
Url:            https://www.python.org/
Source0:        https://www.python.org/ftp/python/%{pyversion}/Python-%{pyversion}.tar.xz
# Deliberately abstain from applying any patches.  These are test
# versions.  Do not need production quality.  Opt for simplicity
# rather then for fine tuning.
BuildRequires:  db-devel
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  gdbm-devel
BuildRequires:  gmp-devel
BuildRequires:  libbz2-devel
BuildRequires:  libopenssl-devel
BuildRequires:  ncurses-devel
BuildRequires:  readline-devel
BuildRequires:  sqlite-devel
BuildRequires:  tk-devel
BuildRequires:  xorg-x11-devel
BuildRequires:  xz
Provides:       %{name} = %{pyver}
Provides:       opt-python%{nver}-argparse = 1.1
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

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

This package is installed in /opt/python in such a way that multiple
Python version may live there next to each other.

%if %{with_pip}
%package pip
Version:        %{pipversion}
Summary:        The PyPA recommended tool for installing Python packages
License:        MIT
Url:            https://pip.pypa.io/
Requires:       %{name} = %{pyver}
BuildArch:      noarch

%description pip
The PyPA recommended tool for installing Python packages.
%endif

%if %{with_setuptools}
%package setuptools
Version:        %{stversion}
Summary:        Easily download, build, install, upgrade, and uninstall Python packages
License:        Python-2.0 or ZPL-2.0
Url:            https://bitbucket.org/pypa/setuptools
Requires:       %{name} = %{pyver}
BuildArch:      noarch

%description setuptools
setuptools is a collection of enhancements to the Python distutils
that allow you to more easily build and distribute Python packages,
especially ones that have dependencies on other packages.
%endif


%prep
%setup -q -n Python-%{pyversion}


%build

# Tell the linker to set the rpath in the python executable.
export LD_RUN_PATH=%{_libdir}

./configure \
    --prefix=%{_prefix} \
    --libdir=%{_libdir} \
    --enable-ipv6 \
    --with-fpectl \
    --enable-shared \
    --enable-unicode=ucs4 \
    --with-ensurepip
make

# replace rest of /usr/local/bin/python or /usr/bin/env python* with
# /opt/python/bin/python%{pyver}.
find . -path "./Parser" -prune -o -path "./Python/makeopcodetargets.py" -prune -o -name '*.py' -type f -print0 | xargs -0 grep -lE '^#! *(/usr/.*bin/(env +)?)?python' | xargs sed -r -i -e '1s@^#![[:space:]]*(/usr/(local/)?bin/(env +)?)?python([0-9]+(\.[0-9]+)?)?@#! %{_prefix}/bin/python%{pyver}@'


%install

# Tell the linker to set the rpath in the python executable.
export LD_RUN_PATH=%{_libdir}

make altinstall DESTDIR=%{buildroot}

# Some old Python version do not get make altinstall rigtht, fix this.
rm -f %{buildroot}%{_prefix}/bin/smtpd.py
test -f %{buildroot}%{_prefix}/bin/2to3 \
    && mv -f %{buildroot}%{_prefix}/bin/2to3 \
             %{buildroot}%{_prefix}/bin/2to3-%{pyver}
test -f %{buildroot}%{_prefix}/bin/idle \
    && mv -f %{buildroot}%{_prefix}/bin/idle \
             %{buildroot}%{_prefix}/bin/idle%{pyver}
test -f %{buildroot}%{_prefix}/bin/idle%{vmajor} \
    && mv -f %{buildroot}%{_prefix}/bin/idle%{vmajor} \
             %{buildroot}%{_prefix}/bin/idle%{pyver}
test -f %{buildroot}%{_prefix}/bin/pydoc \
    && mv -f %{buildroot}%{_prefix}/bin/pydoc \
             %{buildroot}%{_prefix}/bin/pydoc%{pyver}
test -f %{buildroot}%{_prefix}/bin/pydoc%{vmajor} \
    && mv -f %{buildroot}%{_prefix}/bin/pydoc%{vmajor} \
             %{buildroot}%{_prefix}/bin/pydoc%{pyver}

%fdupes %{buildroot}%{_libdir}/python%{pyver}


# Deliberately do not include %post scripts to add /opt/python/lib to
# the ld.so.conf and run ldconfig in order to avoid interfering with
# the system Python installation.  Set the rpath in the binaries
# instead, see setting of LD_RUN_PATH above.


%files
%defattr(-, root, root)
%{_prefix}
%exclude %{_bindir}/easy_install-%{pyver}
%exclude %{_bindir}/pip%{pyver}
%exclude %{_libdir}/python%{pyver}/test
%exclude %{python_sitelib}/easy_install.*
%exclude %{python_sitelib}/pip*
%exclude %{python_sitelib}/pkg_resources
%exclude %{python_sitelib}/setuptools*

%if %{with_pip}
%files pip
%defattr(-, root, root)
%{_bindir}/pip%{pyver}
%{python_sitelib}/pip*
%endif

%if %{with_setuptools}
%files setuptools
%defattr(-, root, root)
%{_bindir}/easy_install-%{pyver}
%{python_sitelib}/easy_install.*
%{python_sitelib}/pkg_resources
%{python_sitelib}/setuptools*
%endif

%changelog
openSUSE Build Service is sponsored by