From: John Snow <jsnow@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: "Fam Zheng" <fam@euphon.net>,
"Eduardo Habkost" <ehabkost@redhat.com>,
qemu-block@nongnu.org,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-devel@nongnu.org, "Stefan Hajnoczi" <stefanha@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH 4/4] scripts/qmp: Fix QEMU Python scripts path
Date: Wed, 13 May 2020 17:10:46 -0400 [thread overview]
Message-ID: <367fef97-af0e-5569-0123-6b199c48c3ca@redhat.com> (raw)
In-Reply-To: <878sidimxu.fsf@dusky.pond.sub.org>
On 4/30/20 1:04 AM, Markus Armbruster wrote:
> John Snow <jsnow@redhat.com> writes:
>
>> On 4/21/20 5:42 AM, Philippe Mathieu-Daudé wrote:
>>> QEMU Python scripts have been moved in commit 8f8fd9edba4 ("Introduce
>>> Python module structure"). Use the same sys.path modification used
>>> in the referenced commit to be able to use these scripts again.
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>>> ---
>>> scripts/qmp/qmp | 4 +++-
>>> scripts/qmp/qom-fuse | 4 +++-
>>> scripts/qmp/qom-get | 4 +++-
>>> scripts/qmp/qom-list | 4 +++-
>>> scripts/qmp/qom-set | 4 +++-
>>> scripts/qmp/qom-tree | 4 +++-
>>> 6 files changed, 18 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/scripts/qmp/qmp b/scripts/qmp/qmp
>>> index 0625fc2aba..8e52e4a54d 100755
>>> --- a/scripts/qmp/qmp
>>> +++ b/scripts/qmp/qmp
>>> @@ -11,7 +11,9 @@
>>> # See the COPYING file in the top-level directory.
>>>
>>> import sys, os
>>> -from qmp import QEMUMonitorProtocol
>>> +
>>> +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
>>> +from qemu.qmp import QEMUMonitorProtocol
>>>
>>
>> Try to avoid using sys.path hacks; they don't work in pylint or mypy and
>> it provides an active barrier to CQA work here.
>> (They also tend to be quite fragile.)
>>
>> We can discuss the right way to do this; one of those ways is to create
>> an installable package that we can install locally in a virtual environment.
>>
>> Another way is perhaps to set PYTHONPATH in the calling environment so
>> that standard "import" directives will work.
>>
>> Both ultimately involve changing the environment of the user to
>> accommodate the script.
>
> For what it's worth, tests/Makefile.involve does the latter for
> tests/qapi-schema/test-qapi.py. Simple enough, but makes manual
> invocation inconvenient.
>
> Not necessary for scripts/qapi-gen.py, because its "import qmp.FOO"
> finds qmp right in scripts/qmp/.
>
Yeah, I should be clear here: this is actually kind of a hard thing to
fix tree-wide right now.
What I didn't realize when I was reviewing this patch is that these
imports are *already broken* and these sys.path hacks actually make it
*work again*.
Under that premise, I rescind my feedback, and offer instead:
Reviewed-by: John Snow <jsnow@redhat.com>
But we should look into how to fix the sys.path problems more long-term;
as part of the packaging work we should investigate this. I believe
similar problems are cropping up in iotests.
Sorry for the noise.
--js
prev parent reply other threads:[~2020-05-13 21:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-21 9:42 [PATCH 0/4] scripts: More Python fixes Philippe Mathieu-Daudé
2020-04-21 9:42 ` [PATCH 1/4] MAINTAINERS: Cover the GDB Python scripts in the gdbstub section Philippe Mathieu-Daudé
2020-04-21 10:43 ` Alex Bennée
2020-04-21 9:42 ` [PATCH 2/4] scripts/qemugdb: Remove shebang header Philippe Mathieu-Daudé
2020-04-21 10:43 ` Alex Bennée
2020-04-21 9:42 ` [PATCH 3/4] scripts/qmp: Use Python 3 interpreter Philippe Mathieu-Daudé
2020-04-29 13:49 ` John Snow
2020-04-21 9:42 ` [PATCH 4/4] scripts/qmp: Fix QEMU Python scripts path Philippe Mathieu-Daudé
2020-04-29 13:54 ` John Snow
2020-04-30 5:04 ` Markus Armbruster
2020-04-30 17:56 ` John Snow
2020-05-02 5:54 ` Markus Armbruster
2020-05-04 18:24 ` John Snow
2020-05-13 21:10 ` John Snow [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=367fef97-af0e-5569-0123-6b199c48c3ca@redhat.com \
--to=jsnow@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=f4bug@amsat.org \
--cc=fam@euphon.net \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).