Path: csiph.com!aioe.org!bofh.it!news.nic.it!robomod From: Ghislain Vaillant Newsgroups: linux.debian.maint.python Subject: Re: 2to3 adds '.' in front dir of "from dir import ..." statements (Was: [MoM] lefse migration to python 3]) Date: Tue, 10 Sep 2019 08:30:01 +0200 Message-ID: References: X-Mailbox-Line: From debian-python-request@lists.debian.org Tue Sep 10 06:24:54 2019 Old-Return-Path: X-Amavis-Spam-Status: No, score=-3.199 tagged_above=-10000 required=5.3 tests=[BAYES_00=-2, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=2, LDO_WHITELIST=-5, MEDS2=2, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=no autolearn_force=no X-Policyd-Weight: using cached result; rate: -5.5 Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EpCxcdXN5QpcCDQxhBS0kP9XqXPyLMfEqaC/SbwDK2o=; b=kB8QDtqUxm82KegStP6hVfYZ2gHv9smClCFT1jzn9LuZorklWnMA5Wjwa5LiPdlYnX w9Ht8EmK0svTtmKR1hne1ZVyl8d5FmWf4ylZqsnOb4HK3ouRhwBXKXXpvKphuo//Z+vT V19hUbW1Gn7YJWkGh6oA2kZNhcwPve+dz/261nrqo0RianZTUzjnibnERaeq+EHt60t5 /CJRthdlEE8zpDbDpfPGbhqF/P605ikGYkJZsKyyht15PiZAZIpavMo+Q8995FmNeE3C cPSb3O6yT3pg7Ifw+fLa26CfyiQi80hcRGo9XWrYq9uU3aNskrrFZTLSeiaSOcFB2hZf Ju6Q== X-Google-Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EpCxcdXN5QpcCDQxhBS0kP9XqXPyLMfEqaC/SbwDK2o=; b=UFz/Nso49UHhl7U5WcyBGJRV4ZU/Xu7hExKOwc7tcQ4IDE2Qzwbb2Q1XxGxmzEKpni n+fHpGaalDe7vWPnKPAe3b3QQGF+avojWQ0Iz2RZRuWwvp1wkGhGUn0GZ8CcYJhCDdXp y3o7i4DMF6QW/u51xVtJAdy3thQ2OvvZSxq23zY+F3jc9+/qm2xWJi9ovEnHzPIIuwyk IfN7kDoVvSDgSs0ABfL0/p0XTbwC4ZPO36BdgqFzffLTCqc2J5dMcbF8oSYWsWlbN+GY +M7DZOx1dIrlIhvykJNH+6dwo7dm07iQsvAhLCAttKNgoCEp9rJI6GoQj1CW1a8KGNYp QLrA== X-Gm-Message-State: APjAAAV9bfGk/rJVbapNy3oYdKTxR8IuBR8MwtFPaOfA8gf0E1Ag0TXV a4ToVEIj1LKpWAu9lahmKOyt9tC0Gc/WkXAemF+lhQ== X-Google-SMTP-Source: APXvYqyK4PiNqNiNUDatrIoq3u0LOkZSpxO1RHP4QPEcfjgj0GklX8qR3cLQwWYxTVCQwuq+7CMOSRzB4Mz2BZD8mzk= X-Received: by 2002:ac5:c5ba:: with SMTP id f26mr12792170vkl.32.1568096678123; Mon, 09 Sep 2019 23:24:38 -0700 (PDT) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000791afe05922cf58d" X-Mailing-List: archive/latest/17301 List-ID: List-URL: List-Archive: https://lists.debian.org/msgid-search/CAFzxpWqaY-4WcGevFd6Mi1wSdJfXe1eSDQAp689Bh-9C6u789w@mail.gmail.com Approved: robomod@news.nic.it Lines: 136 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Cc: debian-python , Shayan Doust X-Original-Date: Tue, 10 Sep 2019 08:24:26 +0200 X-Original-Message-ID: X-Original-References: <20190910055047.otdspqnnnpkd55hp@an3as.eu> Xref: csiph.com linux.debian.maint.python:11780 --000000000000791afe05922cf58d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 =C3=A0 07:51, Andreas Tille a =C3= =A9crit : > 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 > 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 > > --000000000000791afe05922cf58d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
It results from the ambiguity between absolute and r= elative 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.

<= div dir=3D"auto">Ghis

Le mar. 10 sept. 2019 = =C3=A0 07:51, Andreas Tille <andreas= @an3as.eu> a =C3=A9crit=C2=A0:
Hi,

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

=C2=A0 - from lefse import *
=C2=A0 + from .lefse import *

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

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


I think the line

=C2=A0 =C2=A0from lefse import *

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

=C2=A0 =C2=A0from something import *

to

=C2=A0 =C2=A0from .something import *

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

Kind regards

=C2=A0 =C2=A0 =C2=A0 Andreas.

[1] https://salsa.debian.org/med-team/lefse
--
http://fam-tille.de

--000000000000791afe05922cf58d--