hello, On 29.12.2017 02:57, Luciano Santos wrote:
In my case the overall additions looked like this:
%install ... %python_expand mkdir -p %{buildroot}%{_docdir}/$python-gobject %python_expand cp -R examples/* %{buildroot}%{_docdir}/$python-gobject %python_expand find %{buildroot}%{_docdir}/$python-gobject -type f -exec\
If you care about Leap 42.3 and older, the name should be "%{$python_flavor}-gobject". That means that you get "python-gobject" on 42.3 and "python2-gobject" on newer. If you _don't_ care about 42.3, what you did is perfectly fine. Also, %python_expand can do multiline blocks and this is appropriate here. --8<-- %{python_expand # a comment here to prevent RPM barf mkdir -p ... cp -R ... find -exec sed .... } -->8--
%files %ifpython2 %{_docdir}/python2-gobject %endif %ifpython3 %{_docdir}/python3-gobject %endif
Two things. One, %python2_only and %python3_only are your friends. What you wrote is equivalent to: --8<-- %files %python2_only %{_docdir}/python2-gobject %python3_only %{_docdir}/python3-gobject -->8-- Two, even this shorter version is not great. You're listing every flavor by hand. Singlespec is all about not doing that ;) This also fails when we add a new flavor, say, pypy3. The right way to do this is actually very simple: --8<-- %files %{_docdir}/%{python_flavor}-gobject -->8-- also you probably want to mark it as doc: %doc %{_docdir}/... Speaking of which, I haven't tried, but something like this might work: --8<-- %install (...) %{python_expand # convert examples mkdir doc-%{$python_flavor} find examples -type f -exec | while read pathname; do sed 's/.../.../' $pathname > doc-%{$python_flavor}/$pathname done } %files %doc doc-%{python_flavor}/examples -->8-- This relies on the %doc macro to do the installation in the properly named directory. You would prepare a doc-$flavor directory for each flavor. Then using the %doc with a relative path, RPM will take the argument and install it into %{_docdir}/$packagename, without the need to figure out the $packagename. regards m.
Sounds like a lot of trouble only to give the path to the right python binary, but it worked, again, for my 'theoretical' problem as those scripts were only examples. And, of course, there is at least another alternative that was pointed to me which relies on using `sed 's|#!/usr/bin/env python|#!/usr/bin/python|'` and letting the user choose whichever python he wants to with `update-alternatives`.
My solution maybe can be polished a bit, I don't know. But it can be useful in some specific cases I believe. Any further insights on this matter is welcomed!