Conditionalize the Python 2/Python 3 parts using bcond

This commit is contained in:
Petr Viktorin 2019-07-24 15:35:44 +02:00
parent a25c536b5e
commit c7fdae32e2

View File

@ -1,13 +1,20 @@
%global with_python2 1
%if 0%{?rhel} && 0%{?rhel} >= 8 %if 0%{?rhel} && 0%{?rhel} >= 8
%global with_python2 0 # disable python2 by default
%bcond_with python2
%else
# enable python2 by default
%bcond_without python2
%endif %endif
%if 0%{?fedora} || 0%{?rhel} >= 8 %if 0%{?fedora} || 0%{?rhel} >= 8
%global with_python3 1 # enable python3 by default
%bcond_without python3
%else
# disable python3 by default
%bcond_with python3
%endif %endif
%if ( 0%{?fedora} >= 31 ) || ( 0%{?with_python2} == 0 ) %if %{with python3} && ( 0%{?fedora} >= 31 || %{without python2} )
# link /usr/bin/alembic to /usr/bin/alembic-3 # link /usr/bin/alembic to /usr/bin/alembic-3
# (https://fedoraproject.org/wiki/Changes/Python_means_Python3) # (https://fedoraproject.org/wiki/Changes/Python_means_Python3)
%global python_version 3 %global python_version 3
@ -32,7 +39,7 @@ BuildArch: noarch
BuildRequires: help2man BuildRequires: help2man
%if 0%{?with_python2} %if %{with python2}
BuildRequires: python2-devel BuildRequires: python2-devel
BuildRequires: python2-mako BuildRequires: python2-mako
BuildRequires: python2-setuptools BuildRequires: python2-setuptools
@ -56,7 +63,7 @@ BuildRequires: python2-psycopg2
BuildRequires: python2-mysql BuildRequires: python2-mysql
%endif %endif
%if 0%{?with_python3} %if %{with python3}
BuildRequires: python3-devel BuildRequires: python3-devel
BuildRequires: python2-tools BuildRequires: python2-tools
BuildRequires: python3-sqlalchemy >= 0.7.4 BuildRequires: python3-sqlalchemy >= 0.7.4
@ -86,7 +93,7 @@ Documentation and status of Alembic is at http://readthedocs.org/docs/alembic/
%description %_description %description %_description
%if 0%{?with_python2} %if %{with python2}
%package -n python2-alembic %package -n python2-alembic
Summary: %summary Summary: %summary
@ -107,7 +114,7 @@ Requires: python2-mako
%description -n python2-alembic %_description %description -n python2-alembic %_description
%endif %endif
%if 0%{?with_python3} %if %{with python3}
%package -n python3-alembic %package -n python3-alembic
Summary: %summary Summary: %summary
@ -129,7 +136,7 @@ Conflicts: python2-alembic < 1.0.11-2
%prep %prep
%autosetup -p1 -n %{modname}-%{version} %autosetup -p1 -n %{modname}-%{version}
%if 0%{?with_python3} %if %{with python3}
rm -rf %{py3dir} rm -rf %{py3dir}
cp -a . %{py3dir} cp -a . %{py3dir}
%endif %endif
@ -141,17 +148,17 @@ mv setup.py.tmp setup.py
%endif %endif
%build %build
%if 0%{?with_python2} %if %{with python2}
%{__python2} setup.py build %{__python2} setup.py build
%endif %endif
%if 0%{?with_python3} %if %{with python3}
pushd %{py3dir} pushd %{py3dir}
%{__python3} setup.py build %{__python3} setup.py build
popd popd
%endif %endif
%if 0%{?with_python2} %if %{with python2}
# Hack around setuptools so we can get access to help strings for help2man # Hack around setuptools so we can get access to help strings for help2man
# Credit for this goes to Toshio Kuratomi # Credit for this goes to Toshio Kuratomi
%if 0%{?rhel} && 0%{?rhel} <= 6 %if 0%{?rhel} && 0%{?rhel} <= 6
@ -164,7 +171,7 @@ mv bin/alembic bin/python2-alembic
%endif %endif
%endif %endif
%if 0%{?with_python3} %if %{with python3}
pushd %{py3dir} pushd %{py3dir}
%{__mkdir_p} bin %{__mkdir_p} bin
echo 'python3 -c "import alembic.config; alembic.config.main()" $*' > bin/alembic echo 'python3 -c "import alembic.config; alembic.config.main()" $*' > bin/alembic
@ -178,7 +185,7 @@ popd
install -d -m 0755 %{buildroot}%{_mandir}/man1 install -d -m 0755 %{buildroot}%{_mandir}/man1
%if 0%{?with_python3} %if %{with python3}
pushd %{py3dir} pushd %{py3dir}
%{__python3} setup.py install --skip-build --root=%{buildroot} %{__python3} setup.py install --skip-build --root=%{buildroot}
mv %{buildroot}/%{_bindir}/%{modname} %{buildroot}/%{_bindir}/%{modname}-3 mv %{buildroot}/%{_bindir}/%{modname} %{buildroot}/%{_bindir}/%{modname}-3
@ -188,7 +195,7 @@ ln -s alembic-3.1 %{buildroot}%{_mandir}/man1/alembic-%{python3_version}.1
popd popd
%endif %endif
%if 0%{?with_python2} %if %{with python2}
%{__python2} setup.py install -O1 --skip-build --root=%{buildroot} %{__python2} setup.py install -O1 --skip-build --root=%{buildroot}
mv %{buildroot}/%{_bindir}/%{modname} %{buildroot}/%{_bindir}/%{modname}-2 mv %{buildroot}/%{_bindir}/%{modname} %{buildroot}/%{_bindir}/%{modname}-2
ln -s %{modname}-2 %{buildroot}/%{_bindir}/%{modname}-%{python2_version} ln -s %{modname}-2 %{buildroot}/%{_bindir}/%{modname}-%{python2_version}
@ -210,18 +217,18 @@ sed -i -e "s|__requires__ = 'alembic==0.4.2'|__requires__ = ['alembic==0.4.2', '
%endif %endif
%check %check
%if 0%{?with_python2} %if %{with python2}
%{__python2} setup.py test %{__python2} setup.py test
%endif %endif
%if 0%{?with_python3} %if %{with python3}
pushd %{py3dir} pushd %{py3dir}
%{__python3} setup.py test %{__python3} setup.py test
popd popd
%endif %endif
%if 0%{?with_python2} %if %{with python2}
%files -n python2-alembic %files -n python2-alembic
%doc README.rst LICENSE CHANGES docs %doc README.rst LICENSE CHANGES docs
%{python2_sitelib}/%{modname}/ %{python2_sitelib}/%{modname}/
@ -242,7 +249,7 @@ popd
%endif %endif
%endif %endif
%if 0%{?with_python3} %if %{with python3}
%files -n python3-%{modname} %files -n python3-%{modname}
%doc LICENSE README.rst CHANGES docs %doc LICENSE README.rst CHANGES docs
%{python3_sitelib}/%{modname}/ %{python3_sitelib}/%{modname}/
@ -263,6 +270,7 @@ popd
- Make /usr/bin/alembic point to alembic-3 on Fedora 31+ - Make /usr/bin/alembic point to alembic-3 on Fedora 31+
See https://fedoraproject.org/wiki/Changes/Python_means_Python3 See https://fedoraproject.org/wiki/Changes/Python_means_Python3
- Avoid absolute symlinks - Avoid absolute symlinks
- Conditionalize the Python 2/Python 3 parts with bcond
* Sun Jun 30 2019 Kevin Fenzi <kevin@scrye.com> - 1.0.11-1 * Sun Jun 30 2019 Kevin Fenzi <kevin@scrye.com> - 1.0.11-1
- Update to 1.0.11. Fixes bug #1723981 - Update to 1.0.11. Fixes bug #1723981