+#
+# This is template for pure python modules (noarch)
+# use template-specs/python-ext.spec for binary python packages
+#
+#
+# Conditional build:
+%bcond_without doc # don't build doc
+%bcond_without tests # do not perform "make test"
+%bcond_without python2 # CPython 2.x module
+%bcond_without python3 # CPython 3.x module
+
%define module template
Summary: -
Summary(pl.UTF-8): -
+# Name must match the python module/package name (as on pypi or in 'import' statement)
Name: python-%{module}
Version: _
Release: 0.1
License: - (enter GPL/GPL v2/GPL v3/LGPL/BSD/BSD-like/other license name here)
-Group: Development/Languages/Python
-Source0: %{name}-%{version}.tar.gz
+Group: Libraries/Python
+Source0: https://pypi.python.org/packages/source/M/MODULE/%{module}-%{version}.tar.gz
# Source0-md5: -
+#URL: https://pypi.python.org/pypi/MODULE
URL: -
-BuildRequires: python-devel
BuildRequires: rpm-pythonprov
-# if py_postclean is used
-BuildRequires: rpmbuild(macros) >= 1.219
-#Requires: python-libs
-Requires: python-modules
-#BuildArch: noarch
+# for the py_build, py_install macros
+BuildRequires: rpmbuild(macros) >= 1.714
+%if %{with python2}
+BuildRequires: python-modules
+#BuildRequires: python-setuptools
+%endif
+%if %{with python3}
+BuildRequires: python3-modules
+#BuildRequires: python3-setuptools
+%endif
+# when using /usr/bin/env or other in-place substitutions
+#BuildRequires: sed >= 4.0
+# replace with other requires if defined in setup.py
+Requires: python-modules
+BuildArch: noarch
BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
%description
%description -l pl.UTF-8
+%package -n python3-%{module}
+Summary: -
+Summary(pl.UTF-8): -
+Group: Libraries/Python
+Requires: python3-modules
+
+%description -n python3-%{module}
+
+%description -n python3-%{module} -l pl.UTF-8
+
+%package apidocs
+Summary: %{module} API documentation
+Summary(pl.UTF-8): Dokumentacja API %{module}
+Group: Documentation
+
+%description apidocs
+API documentation for %{module}.
+
+%description apidocs -l pl.UTF-8
+Dokumentacja API %{module}.
+
%prep
%setup -q -n %{module}-%{version}
+# fix #!/usr/bin/env python -> #!/usr/bin/python:
+#%{__sed} -i -e '1s,^#!.*python,#!%{__python},' %{name}.py
+
%build
-export CFLAGS="%{rpmcflags}"
-%{__python} setup.py build
+%if %{with python2}
+%py_build %{?with_tests:test}
+%endif
+
+%if %{with python3}
+%py3_build %{?with_tests:test}
+%endif
+
+%if %{with doc}
+cd docs
+%{__make} -j1 html
+rm -rf _build/html/_sources
+%endif
%install
rm -rf $RPM_BUILD_ROOT
-%{__python} setup.py install \
- --optimize=2 \
- --root=$RPM_BUILD_ROOT
-%py_ocomp $RPM_BUILD_ROOT%{py_sitedir}
-%py_comp $RPM_BUILD_ROOT%{py_sitedir}
+%if %{with python2}
+%py_install
+
%py_postclean
+%endif
+
+%if %{with python3}
+%py3_install
+%endif
+
+# in case there are examples provided
+%if %{with python2}
+install -d $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version}
+cp -a examples/* $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version}
+%endif
+%if %{with python3}
+install -d $RPM_BUILD_ROOT%{_examplesdir}/python3-%{module}-%{version}
+cp -a examples/* $RPM_BUILD_ROOT%{_examplesdir}/python3-%{module}-%{version}
+find $RPM_BUILD_ROOT%{_examplesdir}/python3-%{module}-%{version} -name '*.py' \
+ | xargs sed -i '1s|^#!.*python\b|#!%{__python3}|'
+%endif
%clean
rm -rf $RPM_BUILD_ROOT
+%if %{with python2}
%files
%defattr(644,root,root,755)
%doc AUTHORS CREDITS ChangeLog NEWS README THANKS TODO
-%{py_sitedir}/*.py[co]
-%attr(755,root,root) %{py_sitedir}/*.so
-%if "%{pld_release}" != "ac"
-%{py_sitedir}/TEMPLATE-*.egg-info
+%{py_sitescriptdir}/%{module}
+%if "%{py_ver}" > "2.4"
+%{py_sitescriptdir}/%{module}-%{version}-py*.egg-info
+%endif
+%{_examplesdir}/%{name}-%{version}
+%endif
+
+%if %{with python3}
+%files -n python3-%{module}
+%defattr(644,root,root,755)
+%doc AUTHORS CHANGES LICENSE
+%{py3_sitescriptdir}/%{module}
+%{py3_sitescriptdir}/%{module}-%{version}-py*.egg-info
+%{_examplesdir}/python3-%{module}-%{version}
+%endif
+
+%if %{with doc}
+%files apidocs
+%defattr(644,root,root,755)
+%doc docs/_build/html/*
%endif