File python-Cython.spec of Package python-Cython
%define realname cython
%define srcext tar.bz2
%if ! 0%{?py_ver:1}
%define py_ver %(python2 -c "import sys; v=sys.version_info[:2]; print '%%d.%%d'%%v" 2>/dev/null || echo PYTHON-NOT-FOUND)
%endif
%define py_gen %(python2 -c "import sys; v=sys.version_info[:2]; print('%%d%%d'%%v)" 2>/dev/null || echo PYTHON-NOT-FOUND)
# Python 3.x
%if 0%{?suse_version} || 0%{?rhel} == 7
%define python3_pkg python3
%define python3 %{_bindir}/python3
%endif
# EPEL
%if 0%{?rhel} == 6
%define python3_pkg python34
%define python3 %{_bindir}/python3.4
%endif
%if 0%{?rhel} == 8
%define python3_pkg python3
%define python3 %{_libexecdir}/platform-python
%define __python %{_bindir}/python2
%endif
%if ! 0%{?py3_ver:1}
%define py3_ver %(%python3 -c "import sys; v=sys.version_info[:2]; print ('%%d.%%d'%%v)" 2>/dev/null || echo PYTHON3-NOT-FOUND)
%endif
%define py3_gen %(%python3 -c "import sys; v=sys.version_info[:2]; print ('%%d%%d'%%v)" 2>/dev/null || echo PYTHON3-NOT-FOUND)
%if ! 0%{?python3_sitearch:1}
%define python3_sitearch %(%python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib(True))')
%endif
# Common info
Name: %{?suse_version:python-}Cython
Version: 0.25.2
Release: wiz%{?extraver:0.}1%{?dist}
License: Apache-2.0
Group: Development/Languages/Python
URL: http://cython.org/
Summary: The Cython compiler for writing C extensions for the Python language
# Install-time parameters
Requires: python(abi) = %{py_ver}
Requires: python-setuptools
%if 0%{?suse_version}
Requires: python-xml
Provides: Cython = %{version}-%{release}
Provides: Cython2 = %{version}-%{release}
%else
Provides: python-Cython = %{version}-%{release}
Provides: python2-Cython = %{version}-%{release}
%endif
# Build-time parameters
BuildRequires: python-devel
BuildRequires: python-setuptools
%if 0%{?suse_version}
BuildRequires: python-xml
%endif
BuildRoot: %{_tmppath}/%{name}-root
Source: %{realname}-%{version}%{?extraver}.%{srcext}
%description
The Cython language makes writing C extensions for the Python language as
easy as Python itself. Cython is a source code translator based on Pyrex_,
but supports more cutting edge functionality and optimizations.
The Cython language is a superset of the Python language (almost all Python
code is also valid Cython code), but Cython additionally supports optional
static typing to natively call C functions, operate with C++ classes and
declare fast C types on variables and class attributes. This allows the
compiler to generate very efficient C code from Cython code.
This makes Cython the ideal language for writing glue code for external
C/C++ libraries, and for fast C modules that speed up the execution of
Python code.
%package -n %{?suse_version:%{python3_pkg}-}Cython%{!?suse_version:3}
Group: Development/Languages/Python
Summary: The Cython compiler for writing C extensions for the Python language
Requires: python(abi) = %{py3_ver}
Requires: %{python3_pkg}-setuptools
%if 0%{?suse_version}
Provides: Cython3 = %{version}-%{release}
%else
Provides: %{python3_pkg}-Cython = %{version}-%{release}
%endif
BuildRequires: %{python3_pkg}-devel
BuildRequires: %{python3_pkg}-setuptools
%description -n %{?suse_version:%{python3_pkg}-}Cython%{!?suse_version:3}
The Cython language makes writing C extensions for the Python language as
easy as Python itself. Cython is a source code translator based on Pyrex_,
but supports more cutting edge functionality and optimizations.
The Cython language is a superset of the Python language (almost all Python
code is also valid Cython code), but Cython additionally supports optional
static typing to natively call C functions, operate with C++ classes and
declare fast C types on variables and class attributes. This allows the
compiler to generate very efficient C code from Cython code.
This makes Cython the ideal language for writing glue code for external
C/C++ libraries, and for fast C modules that speed up the execution of
Python code.
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -c -n %{realname}-%{version}%{?extraver} -T -a0
mv %{realname}-%{version}%{?extraver} python2
cp -r python2 python3
%build
CFLAGS="%{optflags} %{?gcc_lto} -g0"
LDFLAGS="-Wl,--as-needed -Wl,--strip-all %{?gcc_lto}"
if [ $(rpm --eval %rhel) -eq 8 ]; then
CFLAGS+=" -iplugindir=/usr/lib/gcc/x86_64-redhat-linux/8/plugin -fplugin=annobin -fplugin-arg-annobin-disable"
fi
export CFLAGS LDFLAGS
cd python2
#python2 setup.py build
python2 setup.py build_ext --inplace
cd ../python3
%{python3} setup.py build_ext --inplace
%install
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
cd python2
python2 setup.py install --prefix=%{_prefix} --root=%{buildroot} -O2
for bin in cygdb cython cythonize; do
%{__mv} "%{buildroot}%{_bindir}/${bin}" "%{buildroot}%{_bindir}/${bin}%{py_ver}"
done
cd ../python3
%{python3} setup.py install --prefix=%{_prefix} --root=%{buildroot} -O2
for bin in cygdb cython cythonize; do
%{__mv} "%{buildroot}%{_bindir}/${bin}" "%{buildroot}%{_bindir}/${bin}%{py3_ver}"
done
# Alternatives
%{__install} -d -m755 %{buildroot}%{_sysconfdir}/alternatives/
for bin in cygdb cython cythonize; do
touch "%{buildroot}%{_sysconfdir}/alternatives/${bin}"
%{__ln_s} "%{_sysconfdir}/alternatives/${bin}" "%{buildroot}%{_bindir}/${bin}"
done
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%files
%defattr(-,root,root)
%doc python2/CHANGES.rst python2/COPYING.txt python2/LICENSE.txt python2/README.rst python2/USAGE.txt
%{_bindir}/cygdb
%{_bindir}/cython
%{_bindir}/cythonize
%{_bindir}/*%{py_ver}
%{python_sitearch}/Cython/
%{python_sitearch}/Cython-%{version}-py%{py_ver}.egg-info/
%{python_sitearch}/pyximport/
%{python_sitearch}/cython.py*
%ghost %{_sysconfdir}/alternatives/*
%files -n %{?suse_version:%{python3_pkg}-}Cython%{!?suse_version:3}
%defattr(-,root,root)
%doc python3/CHANGES.rst python3/COPYING.txt python3/LICENSE.txt python3/README.rst python3/USAGE.txt
%{_bindir}/cygdb
%{_bindir}/cython
%{_bindir}/cythonize
%{_bindir}/*%{py3_ver}
%{python3_sitearch}/Cython/
%{python3_sitearch}/Cython-%{version}-py%{py3_ver}.egg-info/
%{python3_sitearch}/__pycache__/*
%{python3_sitearch}/pyximport/
%{python3_sitearch}/cython.py
%ghost %{_sysconfdir}/alternatives/*
%post
/usr/sbin/update-alternatives \
--install %{_bindir}/cython cython %{_bindir}/cython%{py_ver} %{py_gen} \
--slave %{_bindir}/cygdb cygdb %{_bindir}/cygdb%{py_ver} \
--slave %{_bindir}/cythonize cythonize %{_bindir}/cythonize%{py_ver}
%postun
if [ $1 -eq 0 ]; then
/usr/sbin/update-alternatives --remove cython %{_bindir}/cython%{py_ver}
fi
%post -n %{?suse_version:%{python3_pkg}-}Cython%{!?suse_version:3}
/usr/sbin/update-alternatives \
--install %{_bindir}/cython cython %{_bindir}/cython%{py3_ver} %{py3_gen} \
--slave %{_bindir}/cygdb cygdb %{_bindir}/cygdb%{py3_ver} \
--slave %{_bindir}/cythonize cythonize %{_bindir}/cythonize%{py3_ver}
%postun -n %{?suse_version:%{python3_pkg}-}Cython%{!?suse_version:3}
if [ $1 -eq 0 ]; then
/usr/sbin/update-alternatives --remove cython %{_bindir}/cython%{py3_ver}
fi
%changelog