Re: [opensuse-packaging] Proper way to set shebangs in singlespecs
hello, On 23.12.2017 00:45, Luciano Santos wrote:
I read the python singlespec on the wiki but some parts felt kind of obscure to me. If it had either all the macros for singlespec purposes, or at least all the most useful ones with their use cases description I could've made the pain go away with my own meds.
there's a full list on the github page, which is linked from the wiki: https://github.com/openSUSE/python-rpm-macros i'll make the link more prominent as soon as the wiki unlocks
The problem is that there isn't actually a macro for "true if package is built for python2/3". This needs to be fixed. Now you can use "%if 0%{?have_python2}". It's not exactly the right thing but it works.
%python_expand sed -i '$python for you' %{buildroot}%{_datadir}/doc/packages/$python-gobject .....
Now, that's such an interesting piece of information. The have_python macro and this use of %python_expand with some other information on the wiki were the missing puzzle pieces that I needed. Thank you Jan and Sebastian for your time.
Hello, Am Donnerstag, 28. Dezember 2017, 17:28:51 CET schrieb jan matejek:
i'll make the link more prominent as soon as the wiki unlocks
Oops ;-) Fixed since two hours, after Andreas told me about the issue on IRC. For your entertainment: I blocked a spammer earlier today, and didn't uncheck the "block the IP" checkbox. It turned out that I still had the Provo proxy IPs whitelisted in the wiki config instead of the Nuremberg login proxy. Therefore blocking the "spammer's IP" blocked the login proxy, which made the english wiki read-only for everybody. So nothing really surprising, the only surprising thing is that this went unnoticed for so long. Needless to say that I updated the IP whitelist in the config file ;-) Regards, Christian Boltz -- One piece of advice: if you maintain a C&C server (which is both a really bad idea and a criminal act and as such, strongly discouraged), always use a strong password. It's very unprofessional if your server is cracked this easily. [http://www.sophos.com/en-us/medialibrary/PDFs/technical%20papers/ SophosInsideABlackHole.pdf] -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org
Sent: Thursday, December 28, 2017 at 2:28 PM From: "jan matejek" <jmatejek@suse.cz
there's a full list on the github page, which is linked from the wiki: https://github.com/openSUSE/python-rpm-macros i'll make the link more prominent as soon as the wiki unlocks
Holy shell! I missed that one. I did some fragmented readings and on the last one GitHub's reference went totally unnoticed. But the python-rpm-macros surely gave me some insights. I will add in my to-do's list helping to improve the python singlespec when I feel comfortable enough to. If someone is interested, I solved my 'theoretical' problem of giving the right python version in the after-shebang header with the following measures: * First of all I installed manually the scripts which I wanted to edit the python binary path; * Then, under %install section I used `find` to look for the *.py scripts which would be edited by `sed`; * And, finally, under %files section I used %ifpythonX to package the scripts. 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\ sed -i 's|%{_bindir}/env python|%{_bindir}/$python|' {} ";" %files %ifpython2 %{_docdir}/python2-gobject %endif %ifpython3 %{_docdir}/python3-gobject %endif 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! Wishing the best for everyone in this ending year, Luciano. -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org
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!
Sent: Tuesday, January 02, 2018 at 2:44 PM From: "jan matejek" <jmatejek@suse.com>
%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}/...
The cake's cherry. I knew I was missing something, the way I went didn't seem the right one.
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.
I'm actually very satisfied right now with all this feedback and even without this last experimental chunk, but it worth a try for future references. Thank you Jan Matejek. Wishing a good year for everybody, Luciano. -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org
participants (4)
-
Christian Boltz
-
jan matejek
-
jan matejek
-
Luciano Santos