-%define module pyicu
-Summary: PyICU is a python extension wrapping IBM's ICU C++ API
-Name: python-%{module}
-Version: 0.8.1
-Release: 1
-License: GPL
-Group: Base
-URL: http://pyicu.osafoundation.org/
-Source0: http://pypi.python.org/packages/source/P/PyICU/PyICU-%{version}.tar.gz
-# Source0-md5: 789092993f84ccd6ba21d7346d6e093d
-BuildRequires: libicu-devel >= 3.6
-BuildRequires: libstdc++-devel
+#
+# Conditional build:
+%bcond_without python2 # CPython 2.x module
+%bcond_without python3 # CPython 3.x module
+%bcond_without tests # unit tests
+#
+Summary: PyICU - Python 2 extension wrapping IBM's ICU C++ API
+Summary(pl.UTF-8): PyICU - rozszerzenie Pythona 2 obudowujące API C++ biblioteki ICU firmy IBM
+Name: python-pyicu
+Version: 2.3
+Release: 3
+License: MIT-like
+Group: Development/Languages/Python
+Source0: https://files.pythonhosted.org/packages/87/10/fdf5842f42834f6e3141668b607c07bc3c94de39acf582c3d4015e7a7fc5/PyICU-2.3.tar.gz
+# Source0-md5: 622d9bc07bca7d5be4b5cc061f4770c4
+Patch0: 0001-disable-failing-test.patch
+URL: https://pypi.python.org/pypi/PyICU
+BuildRequires: libicu-devel >= 59
+BuildRequires: libstdc++-devel >= 6:4.7
+%if %{with python2}
BuildRequires: python-devel >= 1:2.3
-BuildRequires: rpmbuild(macros) >= 1.219
-Requires: libicu >= 3.6
-Requires: libstdc++
+BuildRequires: python-modules >= 1:2.3
+%endif
+%if %{with python3}
+BuildRequires: python3-2to3 >= 1:3.2
+BuildRequires: python3-devel >= 1:3.2
+BuildRequires: python3-modules >= 1:3.2
+%endif
+BuildRequires: rpm-pythonprov
+BuildRequires: rpmbuild(macros) >= 1.714
BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
%description
-PyICU is a python extension wrapping IBM's ICU C++ API.
+PyICU is a Python extension wrapping IBM's ICU C++ API.
+
+This package contains Python 2 module.
+
+%description -l pl.UTF-8
+PyICU to rozszerzenie Pythona obudowujące API C++ biblioteki ICU firmy
+IBM.
+
+Ten pakiet zawiera moduł Pythona 2.
+
+%package -n python3-pyicu
+Summary: PyICU - Python 3 extension wrapping IBM's ICU C++ API
+Summary(pl.UTF-8): PyICU - rozszerzenie Pythona 3 obudowujące API C++ biblioteki ICU firmy IBM
+Group: Development/Languages/Python
+
+%description -n python3-pyicu
+PyICU is a Python extension wrapping IBM's ICU C++ API.
+
+This package contains Python 3 module.
+
+%description -n python3-pyicu -l pl.UTF-8
+PyICU to rozszerzenie Pythona obudowujące API C++ biblioteki ICU firmy
+IBM.
+
+Ten pakiet zawiera moduł Pythona 3.
%prep
%setup -q -n PyICU-%{version}
+%patch0 -p1
%build
-CC="%{__cc}" \
-CFLAGS="%{rpmcflags}" \
-%{__python} setup.py build
+# uses ICU C++ API, which (in case if icu 59+) needs char16_t as distinct type, i.e. C++ 11
+CFLAGS="%{rpmcxxflags} %{rpmcppflags} -std=c++11"
+
+%if %{with python2}
+%py_build
+
+# tests need module already built
+%{?with_tests:PYTHONPATH=$(pwd)/$(echo build-2/lib.*) %{__python} -m unittest discover -s test}
+%endif
+
+%if %{with python3}
+%py3_build
+
+# tests to be 2to3'ed (by setup) and module already built
+%{?with_tests:PYTHONPATH=$(pwd)/$(echo build-3/lib.*) %{__python3} -m unittest discover -s test}
+%endif
%install
rm -rf $RPM_BUILD_ROOT
-%{__python} setup.py install \
- --skip-build \
- --optimize=2 \
- --root=$RPM_BUILD_ROOT
+%if %{with python2}
+%py_install
%py_postclean
+%endif
+
+%if %{with python3}
+%py3_install
+%endif
%clean
rm -rf $RPM_BUILD_ROOT
+%if %{with python2}
%files
%defattr(644,root,root,755)
-%doc CHANGES CREDITS LICENSE README
-%{py_sitedir}/PyICU.py
+%doc CHANGES CREDITS LICENSE README.md
%{py_sitedir}/PyICU.py[co]
-%{py_sitedir}/_PyICU.so
+%dir %{py_sitedir}/icu
+%{py_sitedir}/icu/__init__.py[co]
+%attr(755,root,root) %{py_sitedir}/_icu.so
%if "%{py_ver}" > "2.4"
-%{py_sitedir}/PyICU-%{version}*.egg-info
+%{py_sitedir}/PyICU-%{version}-py*.egg-info
+%endif
+%endif
+
+%if %{with python3}
+%files -n python3-pyicu
+%defattr(644,root,root,755)
+%doc CHANGES CREDITS LICENSE README.md
+%{py3_sitedir}/PyICU.py
+%dir %{py3_sitedir}/icu
+%{py3_sitedir}/__pycache__/PyICU.*.py[co]
+%{py3_sitedir}/icu/__init__.py
+%dir %{py3_sitedir}/icu/__pycache__
+%{py3_sitedir}/icu/__pycache__/__init__.*.py[co]
+%attr(755,root,root) %{py3_sitedir}/_icu.cpython-*.so
+%{py3_sitedir}/PyICU-%{version}-py*.egg-info
%endif