[projects/template-specs] Python 3 support cleaned up

jajcus jajcus at pld-linux.org
Tue Oct 29 12:43:53 CET 2013


commit 0dd464e707a92d05e99bc4ce18845dd25eaf8f5a
Author: Jacek Konieczny <j.konieczny at eggsoft.pl>
Date:   Tue Oct 29 12:39:10 2013 +0100

    Python 3 support cleaned up
    
    – pre-populating of the 'build-3' directory dropped. Such magic to
      fix python3 path is hardly ever needed and I doubt this code snipped
      would ever work properly
    – python2 support optional too
    – %package for the python3 version
    – redundant code removed
    – 'build --build-base install --skip-build' to use code previously built
      to a custom build base
    – 'tests' target adedd to the 'build' invocation, so the code built in
      our custom build base is tested
    – py_comp/py_ocomp commented-out – it is usually not needed

 python.spec | 89 ++++++++++++++++++++++++-------------------------------------
 1 file changed, 35 insertions(+), 54 deletions(-)
---
diff --git a/python.spec b/python.spec
index ba54006..3aeb9bf 100644
--- a/python.spec
+++ b/python.spec
@@ -1,6 +1,7 @@
 #
 # Conditional build:
 %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
@@ -37,6 +38,15 @@ BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
 %description -l pl.UTF-8
 
+%package -n python3-%{module}
+Summary:	-
+Summary(pl.UTF-8):	-
+Group:		Libraries/Python
+
+%description -n python3-%{module}
+
+%description -n python3-%{module} -l pl.UTF-8
+
 %package apidoc
 Summary:	%{module} API documentation
 Summary(pl.UTF-8):	Dokumentacja API %{module}
@@ -54,38 +64,19 @@ Dokumentacja API %{module}.
 # fix #!/usr/bin/env python -> #!/usr/bin/python:
 #%{__sed} -i -e '1s,^#!.*python,#!%{__python},' %{name}.py
 
-%if %{with python3}
-rm -rf build-3
-set -- *
-install -d build-3
-cp -a "$@" build-3
-find build-3 -name '*.py' | xargs sed -i '1s|^#!python|#!%{__python3}|'
-%endif
-
 %build
 %if %{with python2}
-%{__python} setup.py build --build-base build-2
-%endif
-%if %{with python3}
-%{__python3} setup.py build --build-base build-3
-%endif
-
 # CC/CFLAGS is only for arch packages - remove on noarch packages
 CC="%{__cc}" \
 CFLAGS="%{rpmcflags}" \
-%{__python} setup.py build
-%{__python} setup.py \
-	build -b build-2
-
-%{?with_tests:%{__python} setup.py test}
+%{__python} setup.py build --build-base build-2 %{?with_tests:test}
+%endif
 
 %if %{with python3}
-%{__python3} setup.py \
-	build -b build-3
-
-%if %{with tests}
-%{__python3} setup.py test
-%endif
+# CC/CFLAGS is only for arch packages - remove on noarch packages
+CC="%{__cc}" \
+CFLAGS="%{rpmcflags}" \
+%{__python3} setup.py build --build-base build-3 %{?with_tests:test}
 %endif
 
 %if %{with doc}
@@ -96,52 +87,48 @@ rm -rf _build/html/_sources
 
 %install
 rm -rf $RPM_BUILD_ROOT
-%{__python} setup.py install \
-	--skip-build \
-	--optimize=2 \
-	--root=$RPM_BUILD_ROOT
-
-%{__python} -- setup.py \
-	build -b build-2 \
-	install \
-	--root=$RPM_BUILD_ROOT \
-	--optimize=2
 
 %if %{with python2}
 %{__python} setup.py \
 	build --build-base build-2 \
-	install \
+	install --skip-build \
 	--root=$RPM_BUILD_ROOT \
 	--optimize=2
 
 %py_postclean
 %endif
 
-%{__python3} -- setup.py \
-	build -b build-3 \
-	install \
-	--root=$RPM_BUILD_ROOT \
-	--optimize=2
-
 %if %{with python3}
 %{__python3} setup.py \
 	build --build-base build-3 \
-	install \
+	install --skip-build \
 	--root=$RPM_BUILD_ROOT \
 	--optimize=2
 %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}/%{name}-%{version}
 cp -a examples/* $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version}
+find $RPM_BUILD_ROOT%{_examplesdir}/%{name}-%{version} -name '*.py' \
+	| xargs sed -i '1s|^#!.*python|#!%{__python3}|'
+%endif
 
-# change %{py_sitedir} to %{py_sitescriptdir} for 'noarch' packages!
-%py_ocomp $RPM_BUILD_ROOT%{py_sitedir}
-%py_comp $RPM_BUILD_ROOT%{py_sitedir}
-%py_postclean
+# when files are installed in other way that standard 'setup.py
+# they need to be (re-)compiled
+## change %{py_sitedir} to %{py_sitescriptdir} for 'noarch' packages!
+#%%py_ocomp $RPM_BUILD_ROOT%{py_sitedir}
+#%%py_comp $RPM_BUILD_ROOT%{py_sitedir}
+#%%py_postclean
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 
+%if %{with python2}
 %files
 %defattr(644,root,root,755)
 %doc AUTHORS CREDITS ChangeLog NEWS README THANKS TODO
@@ -152,13 +139,6 @@ rm -rf $RPM_BUILD_ROOT
 %{py_sitedir}/TEMPLATE-*.egg-info
 %endif
 %{_examplesdir}/%{name}-%{version}
-
-%if %{with python2}
-%files
-%defattr(644,root,root,755)
-%doc AUTHORS CHANGES LICENSE
-%{py_sitescriptdir}/%{module}
-%{py_sitescriptdir}/%{module}-%{version}-py*.egg-info
 %endif
 
 %if %{with python3}
@@ -167,6 +147,7 @@ rm -rf $RPM_BUILD_ROOT
 %doc AUTHORS CHANGES LICENSE
 %{py3_sitescriptdir}/%{module}
 %{py3_sitescriptdir}/%{module}-%{version}-py*.egg-info
+%{_examplesdir}/%{python3}-%{module}-%{version}
 %endif
 
 %if %{with doc}
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/template-specs.git/commitdiff/0dd464e707a92d05e99bc4ce18845dd25eaf8f5a



More information about the pld-cvs-commit mailing list