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


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

2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])

Started byAndreas Tille <andreas@an3as.eu>
First post2019-09-10 08:00 +0200
Last post2019-09-12 11:10 +0200
Articles 5 — 4 participants

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


Contents

  2to3 adds '.' in front dir of "from dir import ..." statements (Was:  [MoM] lefse migration to python 3]) Andreas Tille <andreas@an3as.eu> - 2019-09-10 08:00 +0200
    Re: 2to3 adds '.' in front dir of "from dir import ..." statements  (Was: [MoM] lefse migration to python 3]) Ghislain Vaillant <ghisvail@gmail.com> - 2019-09-10 08:30 +0200
    Re: 2to3 adds '.' in front dir of "from dir import ..." statements  (Was: [MoM] lefse migration to python 3]) Michael Kesper <mkesper@schokokeks.org> - 2019-09-12 09:30 +0200
      Re: 2to3 adds '.' in front dir of "from dir import ..." statements  (Was: [MoM] lefse migration to python 3]) Andreas Tille <andreas@an3as.eu> - 2019-09-12 09:50 +0200
    Re: 2to3 adds '.' in front dir of "from dir import ..." statements  (Was: [MoM] lefse migration to python 3]) Andrey Rahmatullin <wrar@debian.org> - 2019-09-12 11:10 +0200

#11779 — 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])

FromAndreas Tille <andreas@an3as.eu>
Date2019-09-10 08:00 +0200
Subject2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])
Message-ID<yEHm1-4FK-1@gated-at.bofh.it>
Hi,

in the process of the Python3 migration the package lefse was converted
using 2to3.  The changes can be found in git[1].  I'm wondering about
the following diff created by 2to3:

  - from lefse import *
  + from .lefse import *

When calling a random binary of the resulting binary package lefse I
experienced:

$ plot_features 
Traceback (most recent call last):
  File "/usr/bin/plot_features", line 6, in <module>
    from .lefse import *
ModuleNotFoundError: No module named '__main__.lefse'; '__main__' is not a package


I think the line

   from lefse import *

should remain to keep that script functional.  I now checked another
package (cain - nothing pushed yet) and here also 2to3 is changing

   from something import *

to

   from .something import *

Could somebody please enlighten me about this added '.' which does not
seem to work?

Kind regards

      Andreas.

[1] https://salsa.debian.org/med-team/lefse

-- 
http://fam-tille.de

[toc] | [next] | [standalone]


#11780 — Re: 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])

FromGhislain Vaillant <ghisvail@gmail.com>
Date2019-09-10 08:30 +0200
SubjectRe: 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])
Message-ID<yEHP3-56m-3@gated-at.bofh.it>
In reply to#11779

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

It results from the ambiguity between absolute and relative imports in
Python 2.

Here 2to3 considers your imports being relative, hence the added dot. I
believe no dots would be added should a `from __future__ import
absolute_import` be found in the preamble of the module.

Hope this helps.

Ghis

Le mar. 10 sept. 2019 à 07:51, Andreas Tille <andreas@an3as.eu> a écrit :

> Hi,
>
> in the process of the Python3 migration the package lefse was converted
> using 2to3.  The changes can be found in git[1].  I'm wondering about
> the following diff created by 2to3:
>
>   - from lefse import *
>   + from .lefse import *
>
> When calling a random binary of the resulting binary package lefse I
> experienced:
>
> $ plot_features
> Traceback (most recent call last):
>   File "/usr/bin/plot_features", line 6, in <module>
>     from .lefse import *
> ModuleNotFoundError: No module named '__main__.lefse'; '__main__' is not a
> package
>
>
> I think the line
>
>    from lefse import *
>
> should remain to keep that script functional.  I now checked another
> package (cain - nothing pushed yet) and here also 2to3 is changing
>
>    from something import *
>
> to
>
>    from .something import *
>
> Could somebody please enlighten me about this added '.' which does not
> seem to work?
>
> Kind regards
>
>       Andreas.
>
> [1] https://salsa.debian.org/med-team/lefse
>
> --
> http://fam-tille.de
>
>

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


#11788 — Re: 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])

FromMichael Kesper <mkesper@schokokeks.org>
Date2019-09-12 09:30 +0200
SubjectRe: 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])
Message-ID<yFrIe-2FV-3@gated-at.bofh.it>
In reply to#11779

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

Hi all,

On 12.09.19 08:30, Thomas Goirand wrote:
> I wont comment on the relative import ambiguity problem, as Ghislain
> replied correctly. However, I do want to comment on 2to3.
> 
> I generally recommend against using it, in the favor of other tools. 
...
> 
> The advantage is that you'll get a source code that will work on both
> Python 2 and 3. It's generally a way more easy to submit upstream, which
> may not want to loose Python 2 compatibility.

We should stop caring about that.
Python2 will be EOL'ed at January 1, 2020 [0].
Python2 will vanish from next Debian release.
Please convert into idiomatic Python3 code, that's the sane way going forward.

Best regards
Michael

[0] https://github.com/python/devguide/pull/344
    https://pythonclock.org/

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


#11790 — Re: 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])

FromAndreas Tille <andreas@an3as.eu>
Date2019-09-12 09:50 +0200
SubjectRe: 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])
Message-ID<yFs1A-2N4-7@gated-at.bofh.it>
In reply to#11788
Hi Michael,

On Thu, Sep 12, 2019 at 09:22:06AM +0200, Michael Kesper wrote:
> On 12.09.19 08:30, Thomas Goirand wrote:
> > I wont comment on the relative import ambiguity problem, as Ghislain
> > replied correctly. However, I do want to comment on 2to3.
> > 
> > I generally recommend against using it, in the favor of other tools. 
> ...
> > 
> > The advantage is that you'll get a source code that will work on both
> > Python 2 and 3. It's generally a way more easy to submit upstream, which
> > may not want to loose Python 2 compatibility.
> 
> We should stop caring about that.
> Python2 will be EOL'ed at January 1, 2020 [0].
> Python2 will vanish from next Debian release.
> Please convert into idiomatic Python3 code, that's the sane way going forward.

I agree here.  @Thomas:  We talked about sixer at DebConf (thanks for
the hint in any case).  But I consider the additional dependency it
introduces something I'd like to avoid if possible.  So I first try my
luck with 2to3 (and I admit I observed some surprises which did not made
me that lucky at all) before I'd use sixer as fallback.

Kind regards

       Andreas.

-- 
http://fam-tille.de

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


#11792 — Re: 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])

FromAndrey Rahmatullin <wrar@debian.org>
Date2019-09-12 11:10 +0200
SubjectRe: 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3])
Message-ID<yFth0-3TF-17@gated-at.bofh.it>
In reply to#11779

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

On Thu, Sep 12, 2019 at 08:30:20AM +0200, Thomas Goirand wrote:
> I wont comment on the relative import ambiguity problem, as Ghislain
> replied correctly. However, I do want to comment on 2to3.
> 
> I generally recommend against using it, in the favor of other tools. For
> example, you can use sixer, which I maintain in Debian, and often used
> (and abused) to do Python 3 conversions. There's also 2to6, which I
> don't know much about, but I've read it works about the same way as
> sixer (which was specifically written for OpenStack).
> 
> The advantage is that you'll get a source code that will work on both
> Python 2 and 3. It's generally a way more easy to submit upstream, which
> may not want to loose Python 2 compatibility.
I can add to this that it's non-trivial to convert from six to normal Py3
code, unless there are some tools that I didn't find. And it's really time
to do that, not to convert TO six.

-- 
WBR, wRAR

[toc] | [prev] | [standalone]


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


csiph-web