I hit this while writing an ebuild that installs a file with a python3 sheband. Said file also works perfectly fine with python2. Calling python_fix_shebang fails though when PYTHON_SINGLE_TARGET is set to 2.x. This can currently only be worked around by: a) setting PYTHON_COMPAT to python3_* only, forcing the user to change PYTHON_SINGLE_TARGET b) sedding the python3 shebang to "python", so python_fix_shebang can properly replace it with the user-chosen implementation Ideally, python_fix_shebang should work without the sed. I also cannot think of any case where the fatal die would be useful. Except to stop people from pushing something they didn't test on all PYTHON_COMPAT versions.
Why would upstream use 'python3' shebang on script that works in Python 2? The check is there to avoid mistakes.
No idea, I'd guess because they prefer python3 or come from a platform where there's only python2 and python3, not python. At least that's the case for pastebinit-1.4.1 where I had to use the sed workaround. Like I said, avoiding mistakes is the only reason I found, but I don't think letting a script die is a good way to hint at possible mistakes when there's perfectly valid scenarios.
Another possible solution to this would be a --force parameter or something like that. That would make the developer writing the ebuild think twice about what he's doing and still give him the chance to use python_fix_shebang.
+ 19 Jun 2014; Michał Górny <mgorny@gentoo.org> python-r1.eclass, + python-utils-r1.eclass, tests/python-utils-r1.sh: + Improve handling of corner cases in python_fix_shebang. Support --force and + --quiet options, bug #505354. Add tests.