%global cairo_version 1.10.2

# this is only turned on during transitional periods
%{?python3_next_pkgversion: %global with_python3_next 1}

### Abstract ###

Name: python3-cairo
Version: 1.10.0
Release: 25%{?dist}
License: MPLv1.1 or LGPLv2
Group: Development/Languages
Summary: Python %{python3_version} bindings for the cairo library
URL: http://cairographics.org/pycairo

Source: http://cairographics.org/releases/pycairo-%{version}.tar.bz2
# Since Python 3.4, pythonX.Y-config is shell script, not Python script,
#  so prevent waf from trying to invoke it as a Python script
Patch0: cairo-waf-use-python-config-as-shell-script.patch
Patch1: pycairo-1.10.0-test-python3.patch
# https://bugs.freedesktop.org/show_bug.cgi?id=91561
Patch2: pycairo-1.10.0-pickle-python3.patch

### Build Dependencies ###

BuildRequires: cairo-devel >= %{cairo_version}
BuildRequires: python%{python3_pkgversion}-devel
BuildRequires: python%{python3_pkgversion}-pytest
BuildRequires: lyx-fonts

%description
Python %{python3_version} bindings for the cairo library.

%if "python%{python3_pkgversion}-cairo" != "%{name}"
%package -n python%{python3_pkgversion}-cairo
Summary: Python %{python3_version} bindings for the cairo library
Group: Development/Languages

%description -n python%{python3_pkgversion}-cairo
Python %{python3_version} bindings for the cairo library.
%endif


%package -n python%{python3_pkgversion}-cairo-devel
Summary: Libraries and headers for python%{python3_pkgversion}-cairo
Group: Development/Libraries
Requires: cairo-devel
Requires: python%{python3_pkgversion}-cairo%{?_isa} = %{version}-%{release}
Requires: python%{python3_pkgversion}-devel

%description -n python%{python3_pkgversion}-cairo-devel
This package contains files required to build wrappers for cairo add-on
libraries so that they interoperate with python%{python3_pkgversion}-cairo.


%if 0%{?with_python3_next}
%package -n python%{python3_next_pkgversion}-cairo
Group: Development/Languages
Summary: Python %{python3_next_version} bindings for the cairo library

BuildRequires: python%{python3_next_pkgversion}-devel
BuildRequires: python%{python3_next_pkgversion}-pytest

%description -n python%{python3_next_pkgversion}-cairo
Python %{python3_next_version} bindings for the cairo library.


%package -n python%{python3_next_pkgversion}-cairo-devel
Summary: Libraries and headers for python%{python3_next_pkgversion}-cairo
Group: Development/Libraries
Requires: cairo-devel
Requires: python%{python3_next_pkgversion}-cairo%{?_isa} = %{version}-%{release}
Requires: python%{python3_next_pkgversion}-devel

%description -n python%{python3_next_pkgversion}-cairo-devel
This package contains files required to build wrappers for cairo add-on
libraries so that they interoperate with python%{python3_next_pkgversion}-cairo.
%endif


%prep
%setup -Dcqn pycairo-%{version}

%if 0%{?with_python3_next}
cp -a pycairo-%{version} pycairo%{python3_next_pkgversion}-%{version}
%endif

pushd pycairo-%{version}
# Ensure that ./waf has created the cached unpacked version
# of the wafadmin source tree.
# This will be created to a subdirectory like
#    .waf3-1.5.18-a7b91e2a913ce55fa6ecdf310df95752
%{__python3} ./waf --version

%patch0 -p0
%patch1 -p1
%patch2 -p1
popd

%if 0%{?with_python3_next}
pushd pycairo%{python3_next_pkgversion}-%{version}
# Ensure that ./waf has created the cached unpacked version
# of the wafadmin source tree.
# This will be created to a subdirectory like
#    .waf3-1.5.18-a7b91e2a913ce55fa6ecdf310df95752
%{__python3_next} ./waf --version

%patch0 -p0
%patch1 -p1
%patch2 -p1
popd
%endif


%build
# FIXME: we should be using the system version of waf (e.g. %{_bindir}/waf)
%configure || :
pushd pycairo-%{version}
export PYTHON=%{__python3}
%{__python3} ./waf --prefix=%{_usr} \
                   --libdir=%{_libdir} \
                   configure

# do not fail on utf-8 encoded files
LANG=en_US.utf8 %{__python3} ./waf build -v

# remove executable bits from examples
find ./examples/ -type f -print0 | xargs -0 chmod -x
popd

%if 0%{?with_python3_next}
pushd pycairo%{python3_next_pkgversion}-%{version}
export PYTHON=%{__python3_next}
%{__python3_next} ./waf --prefix=%{_usr} \
                         --libdir=%{_libdir} \
                         configure

# do not fail on utf-8 encoded files
LANG=en_US.utf8 %{__python3_next} ./waf build -v

# remove executable bits from examples
find ./examples/ -type f -print0 | xargs -0 chmod -x
popd
%endif


%install
pushd pycairo-%{version}
DESTDIR=%{buildroot} %{__python3} ./waf install
popd

%if 0%{?with_python3_next}
pushd pycairo%{python3_next_pkgversion}-%{version}
DESTDIR=%{buildroot} %{__python3_next} ./waf install
popd
%endif

# add executable bit to the .so libraries so we strip the debug info
find %{buildroot} -name '*.so' | xargs chmod +x

find %{buildroot} -name '*.la' | xargs rm -f

# Remove stowaway py2 build artifacts
find %{buildroot} -name '*.pyc' | xargs rm -f
find %{buildroot} -name '*.pyo' | xargs rm -f


%check
pushd pycairo-%{version}/test
PYTHONPATH=%{buildroot}%{python3_sitearch} %{_bindir}/py.test-%{python3_version}
popd

%if 0%{?with_python3_next}
pushd pycairo-%{version}/test
PYTHONPATH=%{buildroot}%{python3_next_sitearch} %{_bindir}/py.test-%{python3_next_version}
popd
%endif

%if "python%{python3_pkgversion}-cairo" != "%{name}"
%files -n python%{python3_pkgversion}-cairo
%else
%files
%endif
%license pycairo-%{version}/COPYING*
%doc pycairo-%{version}/AUTHORS
%doc pycairo-%{version}/NEWS
%doc pycairo-%{version}/README
%doc pycairo-%{version}/examples
%doc pycairo-%{version}/doc/faq.rst
%doc pycairo-%{version}/doc/overview.rst
%doc pycairo-%{version}/doc/README
%{python3_sitearch}/cairo/


%files -n python%{python3_pkgversion}-cairo-devel
%dir %{_includedir}/pycairo
%{_includedir}/pycairo/py3cairo.h
%{_libdir}/pkgconfig/py3cairo.pc


%if 0%{?with_python3_next}
%files -n python%{python3_next_pkgversion}-cairo
%license pycairo-%{version}/COPYING*
%doc pycairo-%{version}/AUTHORS
%doc pycairo-%{version}/NEWS
%doc pycairo-%{version}/README
%doc pycairo-%{version}/examples
%doc pycairo-%{version}/doc/faq.rst
%doc pycairo-%{version}/doc/overview.rst
%doc pycairo-%{version}/doc/README
%{python3_next_sitearch}/cairo/

%files -n python%{python3_next_pkgversion}-cairo-devel
%dir %{_includedir}/pycairo
%{_includedir}/pycairo/py3cairo.h
%{_libdir}/pkgconfig/py3cairo.pc
%endif


%changelog
* Thu Mar 07 2019 Troy Dawson <tdawson@redhat.com> - 1.10.0-25
- Rebuilt to change main python from 3.4 to 3.6

* Thu Nov 16 2017 Björn Esser <besser82@fedoraproject.org> - 1.10.0-24
- More changes for EPEL7

* Thu Nov 16 2017 Björn Esser <besser82@fedoraproject.org> - 1.10.0-23
- Changes for EPEL7

* Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.10.0-22
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild

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

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

* Tue Dec 13 2016 Charalampos Stratakis <cstratak@redhat.com> - 1.10.0-19
- Enable tests

* Mon Dec 12 2016 Charalampos Stratakis <cstratak@redhat.com> - 1.10.0-18
- Rebuild for Python 3.6
- Disable tests for now

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

* Mon Apr 04 2016 Ralph Bean <rbean@redhat.com> - 1.10.0-16
- Remove py2 build artifacts that came along for the ride.

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

* Tue Nov 03 2015 Robert Kuska <rkuska@redhat.com> - 1.10.0-14
- Rebuilt for Python3.5 rebuild
- Add patch from Ubuntu to workaround the pickle issue when building

* Sun Aug 23 2015 Kalev Lember <klember@redhat.com> - 1.10.0-13
- Use license macro for license files

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

* Sun Aug 17 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.10.0-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* Mon Jul 14 2014 Jakub Čajka <jcajka@redhat.com> - 1.10.0-10
- Fixed tests on ppc(64(le)) by adding missing fonts

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

* Thu May 29 2014 Peter Robinson <pbrobinson@fedoraproject.org> 1.10.0-8
- Cleanup spec
- Run tests (RHBZ 1045724)

* Mon May 12 2014 Bohuslav Kabrda <bkabrda@redhat.com> - 1.10.0-7
- Rebuilt for https://fedoraproject.org/wiki/Changes/Python_3.4
- Fixed bundled waf to work correctly with python3.4-config

* Sun Aug 04 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.10.0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild

* Thu Feb 14 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.10.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild

* Fri Aug 03 2012 David Malcolm <dmalcolm@redhat.com> - 1.10.0-4
- rebuild for https://fedoraproject.org/wiki/Features/Python_3.3

* Sat Jul 21 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.10.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

* Sat Jan 14 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.10.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild

* Thu Aug 18 2011 John (J5) Palmieri <johnp@redhat.com> - 1.10.0-1
- update to upstream 1.10.0

* Thu Feb 10 2011 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-12
- remove cairo_rectangle_int_t patch as it was rejected upstream and is
  no longer needed

* Thu Feb 10 2011 David Malcolm <dmalcolm@redhat.com> - 1.8.10-11
- fix embedded copy of waf so that the package builds against python
3.2 (PEP-3149)

* Wed Feb 09 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.8.10-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild

* Wed Nov 10 2010 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-9
- add rectangle_int_t wrapper patch which is needed by PyGObject

* Thu Sep 30 2010 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-8
- typo, set CFLAGS to $RPM_OPT_FLAGS not RPM_BUILD_OPTS

* Tue Sep 28 2010 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-7
- add patch to move to using PyCapsule API since PyCObject was removed from 3.2

* Tue Sep 28 2010 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-6
- move defattr above the first file manifest item in the devel sub package

* Mon Sep 27 2010 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-5
- revert back to using the provided waf script until
  https://bugzilla.redhat.com/show_bug.cgi?id=637935
  is fixed

* Mon Sep 27 2010 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-4
- add buildreq for waf

* Wed Sep 22 2010 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-3
- Use system waf instead of bundled version (this does not work
  on F13 since the system waf contains syntax which has changed
  in python3)

* Wed Sep 22 2010 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-2
- Fixed up for package review

* Thu Sep 16 2010 John (J5) Palmieri <johnp@redhat.com> - 1.8.10-1
- Initial build.
