%bcond_with bootstrap
%bcond_without python2
%bcond_without python3
%bcond_with signatures
%bcond_without tool
%bcond_with test

%global pypi_name wheel

Name:           python-%{pypi_name}
Version:        0.35.0
Release:        1%{?_dist_release}
Summary:        A built-package format for Python
Group:          programming
Vendor:         Project Vine
Distribution:   Vine Linux

License:        MIT
URL:            https://bitbucket.org/pypa/wheel
Source0:        https://files.pythonhosted.org/packages/source/%(n=%{pypi_name}; echo ${n:0:1})/%{pypi_name}/%{pypi_name}-%{version}.tar.gz
BuildArch:      noarch

BuildRequires:  python-rpm-macros

%if %{with python2}
BuildRequires:  python-devel
BuildRequires:  python2-setuptools
%if ! %{with bootstrap}
%if %{with test}
BuildRequires:  python3-pytest
BuildRequires:  python-jsonschema
%endif
%if %{with signatures}
BuildRequires:  pyxdg
BuildRequires:  python-keyring
%endif
%endif
%{?python_provide:%python_provide python2-%{pypi_name}}
%endif

%if %{with python3}
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools
BuildRequires:  python3-rpm-macros
%if ! %{with bootstrap}
%if %{with test}
BuildRequires:  python3-pytest
BuildRequires:  python3-jsonschema
%endif
%if %{with signatures}
BuildRequires:  python3-pyxdg
BuildRequires:  python3-keyring
%endif
%endif
%endif

%global _description \
A built-package format for Python.\
\
A wheel is a ZIP-format archive with a specially formatted filename and the\
.whl extension. It is designed to contain all the files for a PEP 376\
compatible install in a way that is very close to the on-disk format.

%description %{_description}

Python 2 version.


%if %{with python3}
%package -n     python3-%{pypi_name}
Summary:        %{summary}
Group:          programming
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools
%if ! %{with bootstrap}
%if %{with test}
BuildRequires:  python3-pytest
BuildRequires:  python3-jsonschema
%endif
%if %{with signatures}
BuildRequires:  python3-pyxdg
BuildRequires:  python3-keyring
%endif
%endif
%{?python_provide:%python_provide python3-%{pypi_name}}

%description -n python3-%{pypi_name} %{_description}

Python 3 version.
%endif


%prep
%setup -q -n %{pypi_name}-%{version}


%build
%if %{with python2}
%py_build
%endif
%if %{with python3}
%py3_build
%endif


%install
rm -rf %{buildroot}

%if %{with python2}
%py_install
%if %{with tool}
mv %{buildroot}%{_bindir}/%{pypi_name}{,-%{python_version}}
ln -s %{pypi_name}-%{python_version} %{buildroot}%{_bindir}/%{pypi_name}-2
%endif
%endif

%if %{with python3}
%py3_install
%if %{with tool}
mv %{buildroot}%{_bindir}/%{pypi_name}{,-%{python3_version}}
ln -s %{pypi_name}-%{python3_version} %{buildroot}%{_bindir}/%{pypi_name}-3
%endif
%endif


%if %{with test}
%check
rm -f setup.cfg
%if %{with python2}
PYTHONPATH=%{buildroot}%{python_sitelib} py.test-2 -v --ignore build
%endif
%if %{with python3}
PYTHONPATH=%{buildroot}%{python3_sitelib} py.test-3 -v --ignore build
%endif
%endif


%if %{with python2}
%pre
if [ ! -L %{_bindir}/%{pypi_name} ]; then
  rm -f %{_bindir}/%{pypi_name}
fi

%post
/sbin/update-alternatives \
  --install %{_bindir}/%{pypi_name} %{pypi_name} \
  %{_bindir}/%{pypi_name}-%{python_version} %{python_version_nodots}

%preun
if [ "$1" = 0 ]; then
  /sbin/update-alternatives \
    --remove %{pypi_name} %{_bindir}/%{pypi_name}-%{python_version}
fi
%endif

%if %{with python3}
%pre -n python3-%{pypi_name}
if [ ! -L %{_bindir}/%{pypi_name} ]; then
  rm -f %{_bindir}/%{pypi_name}
fi

%post -n python3-%{pypi_name}
/sbin/update-alternatives \
  --install %{_bindir}/%{pypi_name} %{pypi_name} \
  %{_bindir}/%{pypi_name}-%{python3_version} %{python3_version_nodots}

%preun -n python3-%{pypi_name}
if [ "$1" = 0 ]; then
  /sbin/update-alternatives \
    --remove %{pypi_name} %{_bindir}/%{pypi_name}-%{python3_version}
fi
%endif


%if %{with python2}
%files
%license LICENSE.txt
%doc CHANGES.txt README.txt
%if %{with tool}
%{_bindir}/%{pypi_name}-2
%{_bindir}/%{pypi_name}-%{python_version}
%endif
%{python_sitelib}/%{pypi_name}*
%exclude %{python_sitelib}/%{pypi_name}/test
%endif

%if %{with python3}
%files -n python3-%{pypi_name}
%license LICENSE.txt
%doc CHANGES.txt README.txt
%if %{with tool}
%{_bindir}/%{pypi_name}-3
%{_bindir}/%{pypi_name}-%{python3_version}
%endif
%{python3_sitelib}/%{pypi_name}*
%exclude %{python3_sitelib}/%{pypi_name}/test
%endif


%changelog
* Sat Aug 15 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 0.35.0-1
- new upstream release.

* Mon Dec 18 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 0.30.0a0-8
- initial build for Vine Linux.

* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.30.0a0-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.30.0a0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Tue Jan 03 2017 Charalampos Stratakis <cstratak@redhat.com> - 0.30.0a0-5
- Enable tests

* Fri Dec 09 2016 Charalampos Stratakis <cstratak@redhat.com> - 0.30.0a0-4
- Rebuild for Python 3.6 without tests

* Tue Dec 06 2016 Igor Gnatenko <i.gnatenko.brain@gmail.com> - 0.30.0a0-3
- Add bootstrap method

* Mon Sep 19 2016 Charalampos Stratakis <cstratak@redhat.com> - 0.30.0a0-2
- Use the python_provide macro

* Mon Sep 19 2016 Charalampos Stratakis <cstratak@redhat.com> - 0.30.0a0-1
- Update to 0.30.0a0
- Added patch to remove keyrings.alt dependency

* Wed Aug 10 2016 Igor Gnatenko <ignatenko@redhat.com> - 0.29.0-1
- Update to 0.29.0
- Cleanups and fixes

* Tue Jul 19 2016 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.26.0-3
- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages

* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 0.26.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Tue Oct 13 2015 Robert Kuska <rkuska@redhat.com> - 0.26.0-1
- Update to 0.26.0
- Rebuilt for Python3.5 rebuild

* Thu Jun 18 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.24.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* Tue Jan 13 2015 Slavek Kabrda <bkabrda@redhat.com> - 0.24.0-3
- Make spec buildable in EPEL 6, too.
- Remove additional sources added to upstream tarball.

* Sat Jan 03 2015 Matej Cepl <mcepl@redhat.com> - 0.24.0-2
- Make python3 conditional (switched off for RHEL-7; fixes #1131111).

* Mon Nov 10 2014 Slavek Kabrda <bkabrda@redhat.com> - 0.24.0-1
- Update to 0.24.0
- Remove patches merged upstream

* Sun Jun 08 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.22.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* Fri Apr 25 2014 Matej Stuchlik <mstuchli@redhat.com> - 0.22.0-3
- Another rebuild with python 3.4

* Fri Apr 18 2014 Matej Stuchlik <mstuchli@redhat.com> - 0.22.0-2
- Rebuild with python 3.4

* Thu Nov 28 2013 Bohuslav Kabrda <bkabrda@redhat.com> - 0.22.0-1
- Initial package.
