#720 Easy way of changing/removing shebangs
Closed: duplicate a year ago Opened a year ago by ignatenkobrain.

On some of the previous FPC meetings I remember about asking users for massively changing #!/usr/bin/env python and #!/usr/bin/python to proper python2/python3 interpreters. At that time I was thinking about some macro which would simplify doing this because we don't have standard way of changing shebang (even on PackagingTricks wiki page we have 3 different ways of doing same thing).

I played a bit this morning with RPM and came up with something..

# -l        List the current shebang
# -d        Delete current shebang
# -r<path>  Replace current shebang
%chshebang(ldr:) \
for f in %*; do \
  %{-l:head -n1 "$f" | grep -Po '#!\\K.*'} \
  %{-d:t=$(stat -c %%y "$f"); sed -i -e '1{\\@^#!@d}' "$f"; touch -d "$t" "$f"} \
  %{-r:t=$(stat -c %%y "$f"); sed -i -e '1{s@^#!.*@#!%{-r*}@}' "$f"; touch -d "$t" "$f"} \
done

This worked quite well for me. Probably it should have been written in Lua, but I am very bad in that language.


I like that idea, but have several remarks:

1) Where is this macro going to be placed? Shouldn't it go directly into RPM?
2) I don't like the name. Do we have to save every character? Why it is not "change_shebang"?
3) I would appreciate if the comments were accompanied by some example. It seems that this macro can change shebangs of several files in one run, but it would be probably better to see that from example then from reading the code.
4) Shouldn't there be %{nil} at the end, or semicolon?

1) Where is this macro going to be placed? Shouldn't it go directly into RPM?

For example, redhat-rpm-config.

2) I don't like the name. Do we have to save every character? Why it is not "change_shebang"?

It is very similar for tool called chrpath ;)

3) I would appreciate if the comments were accompanied by some example. It seems that this macro can change shebangs of several files in one run, but it would be probably better to see that from example then from reading the code.

I think that's what wiki is for.

4) Shouldn't there be %{nil} at the end, or semicolon?

nope.

2) I don't like the name. Do we have to save every character? Why it is not "change_shebang"?

It is very similar for tool called chrpath ;)

Yes, and similar to chdir, chown, chmod, chroot, but no matter how many similar examples you'll find, it does not make them good names IMO.

3) I would appreciate if the comments were accompanied by some example. It seems that this macro can change shebangs of several files in one run, but it would be probably better to see that from example then from reading the code.

I think that's what wiki is for.

API documentation should be part of the source code, not somewhere in wiki. You don't even explain what is actually purpose of the method.

May be you can get some inspiration from RPM:

https://github.com/rpm-software-management/rpm/blob/master/macros.in

Metadata Update from @james:
- Issue tagged with: meeting

a year ago

We discussed this at this weeks meeting (https://meetbot-raw.fedoraproject.org/fedora-meeting-1/2017-10-26/fpc.2017-10-26-16.00.txt):

  • x720 Easy way of changing/removing shebangs (geppetto, 16:09:10)
  • Everyone seems happy with the general idea. (geppetto, 16:18:15)
  • ACTION: ignatenkobrain A real draft we can vote on would be cool,
    including an example or two (geppetto, 16:18:40)

I'm not sure I see the need for the -l option.

Btw. in python packaging context in particular, where shebangs matter
are typically the launcher scripts that get auto-generated by setuptools
(or equivalent tooling?) based on configuring console_scripts as
entry_points (or equivalent?), and that's already covered in current
RPM macros with --executable switch, e.g.:

py_build [...] %{__python} %{py_setup} %{?py_setup_args} build --executable="%{__python2} %{py_shbang_opts}"

(though this approach is not necessarily reliable:
https://github.com/pypa/setuptools/issues/188; wontfix-ed in RHEL 7:
https://bugzilla.redhat.com/show_bug.cgi?id=1353934)

What I want to say, language ecosystems might/should have their own
frontline measures for this, making this one just a last resort
of any such enforcement.

Actually in Python, setuptools based projects that can benefit from the above macro are OK. We fight with shebangs of other (non-setuptools) Python projects (that use autotools or cmake or just copy files around with scripts). Relevant issue is here https://github.com/fedora-python/python-rpm-porting/issues/24

@ignatenkobrain Can you please push this forward? I believe it's waiting for " A real draft (FPC) can vote on would be cool, including an example or two". Thank you.

I mean, if this is just adding a macro and there's consensus that the macro works and has reasonable arguments and whatnot, then great; let's just add it to redhat-rpm-config. But my understand was that this had morphed into a brp-* script for auto-removing shebangs from things, and I'm not sure what happened from there. I think a macro has a much lower barrier to entry than a brp script.

Those two things are different. The macro is when you want to change the shabang manually, and this ticket is about that. For the brp script, see https://pagure.io/packaging-committee/issue/738

Note that those 2 are unrelated when it comes to approval (i.e. they can both be accepted).

Igor asked that I just close this proposal in favor of the new one (which is #738).

Personally I don't have any problem with a macro either way, so if we need one we can just add it. That doesn't really need to involve FPC, really; just a PR filed against redhat-rpm-config. Maybe the guidelines could mention such a macro after it actually existed if that were necessary.

Metadata Update from @tibbs:
- Issue close_status updated to: duplicate
- Issue status updated to: Closed (was: Open)

a year ago

Login to comment on this ticket.

Metadata