Make Python 2 optional

To facilitate building the Python 2 and Python 3 modules.
This commit is contained in:
Tomas Orsava 2017-08-29 14:38:10 +02:00
parent a096270f29
commit 222c069cc5

View File

@ -1,13 +1,17 @@
%bcond_with bootstrap
%bcond_with tests
%bcond_without python2
%bcond_without python3
%global srcname pip
%global python_wheelname %{srcname}-%{version}-py2.py3-none-any.whl
%if %{without bootstrap}
%global python2_wheelname %{srcname}-%{version}-py2.py3-none-any.whl
%if %{with python2}
%global python2_wheelname %python_wheelname
%endif
%if %{with python3}
%global python3_wheelname %python2_wheelname
%global python3_wheelname %python_wheelname
%endif
%endif
@ -18,7 +22,7 @@
Name: python-%{srcname}
Version: 9.0.1
Release: 11%{?dist}
Release: 12%{?dist}
Summary: A tool for installing and managing Python packages
Group: Development/Libraries
@ -28,6 +32,9 @@ Source0: https://files.pythonhosted.org/packages/source/p/%{srcname}/%{sr
BuildArch: noarch
BuildRequires: git
BuildRequires: bzr
# to get tests:
# git clone https://github.com/pypa/pip && cd pip
# git checkout 9.0.1 && tar -czvf ../pip-9.0.1-tests.tar.gz tests/
@ -51,14 +58,13 @@ written in Python. Many packages can be found in the Python Package Index
Packages" or "Pip Installs Python".
%if %{with python2}
%package -n python2-%{srcname}
Summary: A tool for installing and managing Python 2 packages
Group: Development/Libraries
BuildRequires: python2-devel
BuildRequires: python-setuptools
%if %{with tests}
BuildRequires: git
BuildRequires: bzr
BuildRequires: python-mock
BuildRequires: pytest
BuildRequires: python-pretend
@ -80,6 +86,8 @@ written in Python. Many packages can be found in the Python Package Index
(PyPI). pip is a recursive acronym that can stand for either "Pip Installs
Packages" or "Pip Installs Python".
%endif # with python2
%if %{with python3}
%package -n python%{python3_pkgversion}-%{srcname}
@ -127,11 +135,13 @@ sed -i '1d' pip/__init__.py
%build
%if %{with python2}
%if %{without bootstrap}
%py2_build_wheel
%else
%py2_build
%endif
%endif # with python2
%if %{with python3}
%if %{without bootstrap}
@ -155,16 +165,20 @@ sed -i '1d' pip/__init__.py
rm %{buildroot}%{_bindir}/pip
%endif # with python3
%if %{with python2}
%if %{without bootstrap}
%py2_install_wheel %{python2_wheelname}
%else
%py2_install
%endif
%endif # with python2
mkdir -p %{buildroot}%{bashcompdir}
PYTHONPATH=%{buildroot}%{python_sitelib} \
%if %{with python2}
PYTHONPATH=%{buildroot}%{python2_sitelib} \
%{buildroot}%{_bindir}/pip completion --bash \
> %{buildroot}%{bashcompdir}/pip
%endif
%if %{with python3}
PYTHONPATH=%{buildroot}%{python3_sitelib} \
%{buildroot}%{_bindir}/pip3 completion --bash \
@ -175,12 +189,14 @@ pips3=pip3
for pip in %{buildroot}%{_bindir}/pip*; do
pip=$(basename $pip)
case $pip in
%if %{with python2}
pip2*)
pips2="$pips2 $pip"
%if 0%{?bashcomp2}
ln -s pip %{buildroot}%{bashcompdir}/$pip
%endif
;;
%endif
%if %{with python3}
pip3?*)
pips3="$pips3 $pip"
@ -196,23 +212,34 @@ sed -i -e "s/^\\(complete.*\\) pip\$/\\1 $pips3/" \
-e s/_pip_completion/_pip3_completion/ \
%{buildroot}%{bashcompdir}/pip3
%endif
%if %{with python2}
sed -i -e "s/^\\(complete.*\\) pip\$/\\1 $pips2/" \
%{buildroot}%{bashcompdir}/pip
%endif
# Provide symlinks to executables to comply with Fedora guidelines for Python
%if %{with python2}
ln -s ./pip%{python2_version} %{buildroot}%{_bindir}/pip-%{python2_version}
ln -s ./pip%{python3_version} %{buildroot}%{_bindir}/pip-%{python3_version}
ln -s ./pip-%{python2_version} %{buildroot}%{_bindir}/pip-2
%endif
%if %{with python3}
ln -s ./pip%{python3_version} %{buildroot}%{_bindir}/pip-%{python3_version}
ln -s ./pip-%{python3_version} %{buildroot}%{_bindir}/pip-3
%endif
%if %{with tests}
%check
py.test -m 'not network'
%if %{with python2}
py.test-%{python2_version} -m 'not network'
%endif
%if %{with python3}
py.test-%{python3_version} -m 'not network'
%endif
%endif
%if %{with python2}
%files -n python2-%{srcname}
%license LICENSE.txt
%doc README.rst docs
@ -221,14 +248,14 @@ py.test-%{python3_version} -m 'not network'
%{_bindir}/pip-2
%{_bindir}/pip%{python2_version}
%{_bindir}/pip-%{python2_version}
%{python_sitelib}/pip*
%{bashcompdir}
%if %{with python3}
%exclude %{bashcompdir}/pip3*
%endif
%{python2_sitelib}/pip*
%dir %{bashcompdir}
%{bashcompdir}/pip
%{bashcompdir}/pip2*
%if 0%{?bashcomp2}
%dir %(dirname %{bashcompdir})
%endif
%endif # with python2
%if %{with python3}
%files -n python%{python3_pkgversion}-%{srcname}
@ -247,6 +274,10 @@ py.test-%{python3_version} -m 'not network'
%endif # with python3
%changelog
* Tue Aug 29 2017 Tomas Orsava <torsava@redhat.com> - 9.0.1-12
- Switch macros to bcond's and make Python 2 optional to facilitate building
the Python 2 and Python 3 modules
* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 9.0.1-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild