Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.maint.python > #12212 > unrolled thread

Re: dh_python3 sets shebang to Python 2 -- is this a bug?

Started byAndreas Henriksson <andreas@fatal.se>
First post2020-01-20 17:50 +0100
Last post2020-01-23 14:20 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.debian.maint.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: dh_python3 sets shebang to Python 2 -- is this a bug? Andreas Henriksson <andreas@fatal.se> - 2020-01-20 17:50 +0100
    Re: dh_python3 sets shebang to Python 2 -- is this a bug? Nicholas D Steeves <nsteeves@gmail.com> - 2020-01-22 02:20 +0100
      Re: dh_python3 sets shebang to Python 2 -- is this a bug? Matthias Klose <doko@debian.org> - 2020-01-23 14:20 +0100

#12212 — Re: dh_python3 sets shebang to Python 2 -- is this a bug?

FromAndreas Henriksson <andreas@fatal.se>
Date2020-01-20 17:50 +0100
SubjectRe: dh_python3 sets shebang to Python 2 -- is this a bug?
Message-ID<zqIps-4sJ-13@gated-at.bofh.it>
Hello Christian,

On Mon, Jan 20, 2020 at 08:51:56AM +0100, Christian Kastner wrote:
> I have an issue with a package build, and I'm not sure whether this is a
> bug in dh-python, or whether I'm just misunderstanding something.
> 
> 
> A package that had recently been converted from Python 2 to Python3 was
> still generating dependencies for Python 2, see #936924.
> 
> Frederic-Emmanuel Picca correctly pointed me to the source of this
> issue, it was an unversioned shebang in some scripts installed into
> /usr/bin.
> 
> Here's the thing that puzzles me: dh_python3 identifies the unversioned
> shebang,
> 
>   | I: dh_python3 tools:114: replacing shebang in debian/libsvm-tools/usr/bin/svm-grid
>   | I: dh_python3 tools:114: replacing shebang in debian/libsvm-tools/usr/bin/svm-subset
>   | I: dh_python3 tools:114: replacing shebang in debian/libsvm-tools/usr/bin/svm-checkdata
>   | I: dh_python3 tools:114: replacing shebang in debian/libsvm-tools/usr/bin/svm-easy
> 
> but it replaces the shebang with the Python *2* versioned one.

I think you're hitting the following code paths:
https://sources.debian.org/src/dh-python/4.20191017/dhpython/tools.py/#L94
https://sources.debian.org/src/dh-python/4.20191017/dhpython/tools.py/#L100
https://sources.debian.org/src/dh-python/4.20191017/dhpython/interpreter.py/#L212
https://sources.debian.org/src/dh-python/4.20191017/dhpython/interpreter.py/#L196
https://sources.debian.org/src/dh-python/4.20191017/dhpython/tools.py/#L106
https://sources.debian.org/src/dh-python/4.20191017/dhpython/tools.py/#L114

I've personally seen some upstream use 'python' in shebang with the
intention of meaning 'works with either python2 or python3', but in
debian it seems people have always assumed unversioned
(/usr/bin/)python always means python *2*.
I guess the tools are written in the latter sense here, rewriting the
shebang from python -> python2 explicitly unless you override it....

You should note that if you know the code is actually python-version
agnostic you should be able to fix this by setting the shebang
explicitly by using:
https://sources.debian.org/src/dh-python/4.20191017/dh_python3/#L122

eg. in debian/rules use: export DH_OPTIONS=--shebang=/usr/bin/python3 

> 
> A Python 3 helper setting /usr/bin/python2 looks odd to me, but I have
> no in-depth knowledge of dh-python's design, or the corner cases it
> might need to address.
> 
> Is there a use case where dh_python3 (not dh_python2) doing this can
> make sense? Or can this be considered a bug?

I'm not really qualified to answer your questions here but my guess is
that in the past this made sense, but nowadays probably not so much...

> 
> Furthermore, the package does not list any Python 2 build dependencies,
> and all binary package dependencies are generated by the
> ${python3:Depends} substvar. Could this perhaps be worth an "if the
> package does not have Python 2 dependencies, a Python 2 shebang is a
> bug" lintian check?

Having some safety-net in place here would likely be a good idea because
I understand how this could easily be missed otherwise.

Regards,
Andreas Henriksson

[toc] | [next] | [standalone]


#12214

FromNicholas D Steeves <nsteeves@gmail.com>
Date2020-01-22 02:20 +0100
Message-ID<zrcQx-5X5-3@gated-at.bofh.it>
In reply to#12212

[Multipart message — attachments visible in raw view] — view raw

Hi,

Andreas Henriksson <andreas@fatal.se> writes:

> I've personally seen some upstream use 'python' in shebang with the
> intention of meaning 'works with either python2 or python3',

Yes, this has worked thus far, and it will definitely work in cases where
`which python` is a symlink to python3 within a virtual environment.

>  but in debian it seems people have always assumed unversioned
> (/usr/bin/)python always means python *2*.

I don't think this is an assumption.  Debian adheres to PEP 394, which
until recently said that /usr/bin/python is supposed to be Python 2, for
backwards compatibility.  When I discovered this I felt increased trust
in Debian and its developers for doing the sensible and standardised
thing, rather than what some other distributions have done.  To everyone
involved, thank you!  This also made me proud to be part of such a
community :-)

  https://www.python.org/dev/peps/pep-0394/

I believe that it was on 26-Jun-2019 of this year that PEP 394 was
modified to allow /usr/bin/python to be py3, because py2 EOL frees
up this path.  IMHO that change was premature and should have been
deferred until the actual EOL.

> I guess the tools are written in the latter sense here, rewriting the
> shebang from python -> python2 explicitly unless you override it....
>

Yeah, this is a tricky point.  Per PEP 394 (until py2 EOL), this is the
correct approach, but now it may make more sense to change this to
"python -> python3", because if this breaks a package, tough luck, we're
in a python3-only world.  eg: packages in the archive should already
have the shebang override, and NEW py2 packages will be rejected by
ftpmasters.

Cheers,
Nicholas

[toc] | [prev] | [next] | [standalone]


#12221

FromMatthias Klose <doko@debian.org>
Date2020-01-23 14:20 +0100
Message-ID<zrKyS-Zl-7@gated-at.bofh.it>
In reply to#12214
On 22.01.20 02:18, Nicholas D Steeves wrote:
> I don't think this is an assumption.  Debian adheres to PEP 394, which
> until recently said that /usr/bin/python is supposed to be Python 2, for
> backwards compatibility.  When I discovered this I felt increased trust
> in Debian and its developers for doing the sensible and standardised
> thing, rather than what some other distributions have done.  To everyone
> involved, thank you!  This also made me proud to be part of such a
> community :-)

well, looking a few years forward, Debian will be the only system not providing
a python command, incompatible with everybody else.  New users will not
understand that Debian doesn't have a python command when there's no Python2
anymore.

What we will do is to get rid off the unversioned python for all the packaging
in the archive, so that users can do what they want.

Matthias

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.maint.python


csiph-web