All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Hanna Reitz <hreitz@redhat.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	qemu-block@nongnu.org, qemu-devel <qemu-devel@nongnu.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [PATCH v3 07/16] iotests/297: Don't rely on distro-specific linter binaries
Date: Mon, 4 Oct 2021 14:59:24 -0400	[thread overview]
Message-ID: <CAFn=p-bgfkYYpnP6q5E2mxsCsK3tJS6sQFzSXfWFerk9qf1hRQ@mail.gmail.com> (raw)
In-Reply-To: <58254219-d4a5-c4c2-20ab-21e33e034ce5@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 5467 bytes --]

On Mon, Oct 4, 2021 at 4:17 AM Hanna Reitz <hreitz@redhat.com> wrote:

> On 22.09.21 21:53, John Snow wrote:
> > (This email just explains python packaging stuff. No action items in
> > here. Skim away.)
> >
> > On Fri, Sep 17, 2021 at 5:43 AM Hanna Reitz <hreitz@redhat.com
> > <mailto:hreitz@redhat.com>> wrote:
> >
> >     On 16.09.21 06:09, John Snow wrote:
> >     > 'pylint-3' is another Fedora-ism. Use "python3 -m pylint" or
> >     "python3 -m
> >     > mypy" to access these scripts instead. This style of invocation
> will
> >     > prefer the "correct" tool when run in a virtual environment.
> >     >
> >     > Note that we still check for "pylint-3" before the test begins
> >     -- this
> >     > check is now "overly strict", but shouldn't cause anything that was
> >     > already running correctly to start failing.
> >     >
> >     > Signed-off-by: John Snow <jsnow@redhat.com
> >     <mailto:jsnow@redhat.com>>
> >     > Reviewed-by: Vladimir Sementsov-Ogievskiy
> >     <vsementsov@virtuozzo.com <mailto:vsementsov@virtuozzo.com>>
> >     > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com
> >     <mailto:philmd@redhat.com>>
> >     > ---
> >     >   tests/qemu-iotests/297 | 45
> >     ++++++++++++++++++++++++------------------
> >     >   1 file changed, 26 insertions(+), 19 deletions(-)
> >
> >     I know it sounds silly, but to be honest I have no idea if replacing
> >     `mypy` by `python3 -m mypy` is correct, because no mypy documentation
> >     seems to suggest it.
> >
> >
> > Right, I don't think it's necessarily documented that you can do this.
> > It just happens to be a very convenient way to invoke the same script
> > without needing to know *where* mypy is. You let python figure out
> > where it's going to import mypy from, and it handles the rest.
> >
> > (This also makes it easier to use things like mypy, pylint etc with an
> > explicitly specified PYTHON interpreter. I don't happen to do that in
> > this patch, but ... we could.)
> >
> >      From what I understand, that’s generally how Python “binaries” work,
> >     though (i.e., installed as a module invokable with `python -m`,
> >     and then
> >     providing some stub binary that, well, effectively does this, but
> >     kind
> >     of in a weird way, I just don’t understand it), and none of the
> >     parameters seem to be hurt in this conversion, so:
> >
> >
> > Right. Technically, any python package can ask for any number of
> > executables to be installed, but the setuptools packaging ecosystem
> > provides a way to "generate" these based on package configuration. I
> > use a few in our own Python packages. If you look in python/setup.cfg,
> > you'll see stuff like this:
> >
> > [options.entry_points]
> > console_scripts =
> >     qom = qemu.qmp.qom:main
> >     qom-set = qemu.qmp.qom:QOMSet.entry_point
> >     qom-get = qemu.qmp.qom:QOMGet.entry_point
> >     qom-list = qemu.qmp.qom:QOMList.entry_point
> >     qom-tree = qemu.qmp.qom:QOMTree.entry_point
> >     qom-fuse = qemu.qmp.qom_fuse:QOMFuse.entry_point [fuse]
> >     qemu-ga-client = qemu.qmp.qemu_ga_client:main
> >     qmp-shell = qemu.qmp.qmp_shell:main
> >
> > These entries cause those weird little binary wrapper scripts to be
> > generated for you when the package is *installed*. So our packages
> > will put 'qmp-shell' and 'qom-tree' into your $PATH*.The stuff to the
> > right of the equals sign is just a pointer to a function that can be
> > executed that implements the CLI command. qemu.qmp.qmp_shell points to
> > the module to import, and ':main' points to the function to run.
> >
> > The last bit of this is that many, though not all (and there's zero
> > requirement this has to be true), python packages that implement CLI
> > commands will often have a stanza in their __init__.py module that
> > says something like this:
> >
> > if __name__ == '__main__':
> >     do_the_command_line_stuff()
> >
> > Alternatively, a package can include a literal __main__.py file that
> > python knows to check for, and this module is the one that gets
> > executed for `python3 -m mypackage` invocations. This is what mypy does.
> >
> > Those are the magical blurbs that allow you to execute a module as if
> > it were a script by running "python3 -m mymodule" -- that hooks
> > directly into that little execution stanza. For python code
> > distributed as packages, that's the real reason to have that little
> > magic stanza -- it provides a convenient way to run stuff without
> > needing to write the incredibly more tedious:
> >
> > python3 -c "from mypy.__main__ import console_entry; console_entry();"
> >
> > ... which is quite a bit more porcelain too, depending on how they
> > re/factor the code inside of the package.
> >
> > Seeing as how mypy explicitly includes a __main__.py file:
> > https://github.com/python/mypy/blob/master/mypy/__main__.py
> > <https://github.com/python/mypy/blob/master/mypy/__main__.py>, I am
> > taking it as a given that they are fully aware of invoking mypy in
> > this fashion, and believe it safe to rely on.
>
> Wow, thanks a lot for this detailed explanation!
> > There will be a quiz later.
> > (There will not be a quiz.)
>
> I’m ready to fail any test on Python so one day I can get a “Officially
> knows nothing about Python” badge.
>
>
I can respect that ;)

--js

[-- Attachment #2: Type: text/html, Size: 7421 bytes --]

  reply	other threads:[~2021-10-04 19:02 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-16  4:09 [PATCH v3 00/16] python/iotests: Run iotest linters during Python CI John Snow
2021-09-16  4:09 ` [PATCH v3 01/16] python: Update for pylint 2.10 John Snow
2021-09-16 13:28   ` Alex Bennée
2021-09-16 14:34     ` John Snow
2021-09-16  4:09 ` [PATCH v3 02/16] iotests/mirror-top-perms: Adjust imports John Snow
2021-09-16  4:27   ` Philippe Mathieu-Daudé
2021-09-16 14:27     ` John Snow
2021-09-16 15:05       ` Philippe Mathieu-Daudé
2021-09-17  8:35   ` Hanna Reitz
2021-09-16  4:09 ` [PATCH v3 03/16] iotests/migrate-bitmaps-postcopy-test: declare instance variables John Snow
2021-09-17  8:37   ` Hanna Reitz
2021-09-22 19:15     ` John Snow
2021-09-16  4:09 ` [PATCH v3 04/16] iotests/migrate-bitmaps-test: delint John Snow
2021-09-16  4:28   ` Philippe Mathieu-Daudé
2021-09-17  8:59   ` Hanna Reitz
2021-09-16  4:09 ` [PATCH v3 05/16] iotests/297: modify is_python_file to work from any CWD John Snow
2021-09-17  9:08   ` Hanna Reitz
2021-09-16  4:09 ` [PATCH v3 06/16] iotests/297: Add get_files() function John Snow
2021-09-17  9:24   ` Hanna Reitz
2021-09-22 19:25     ` John Snow
2021-09-16  4:09 ` [PATCH v3 07/16] iotests/297: Don't rely on distro-specific linter binaries John Snow
2021-09-17  9:43   ` Hanna Reitz
2021-09-22 19:53     ` John Snow
2021-10-04  8:16       ` Hanna Reitz
2021-10-04 18:59         ` John Snow [this message]
2021-09-16  4:09 ` [PATCH v3 08/16] iotests/297: Create main() function John Snow
2021-09-16  4:31   ` Philippe Mathieu-Daudé
2021-09-17  9:58   ` Hanna Reitz
2021-09-16  4:09 ` [PATCH v3 09/16] iotests/297: Separate environment setup from test execution John Snow
2021-09-17 10:05   ` Hanna Reitz
2021-09-16  4:09 ` [PATCH v3 10/16] iotests/297: Add 'directory' argument to run_linters John Snow
2021-09-17 10:10   ` Hanna Reitz
2021-09-16  4:09 ` [PATCH v3 11/16] iotests/297: return error code from run_linters() John Snow
2021-09-17 11:00   ` Hanna Reitz
2021-09-22 20:18     ` John Snow
2021-10-04  7:45       ` Hanna Reitz
2021-10-04 19:26         ` John Snow
2021-09-16  4:09 ` [PATCH v3 12/16] iotests/297: split linters.py off from 297 John Snow
2021-09-16  4:09 ` [PATCH v3 13/16] iotests/linters: Add entry point for Python CI linters John Snow
2021-09-16  4:52   ` Philippe Mathieu-Daudé
2021-09-16  4:09 ` [PATCH v3 14/16] iotests/linters: Add workaround for mypy bug #9852 John Snow
2021-09-17 11:16   ` Hanna Reitz
2021-09-22 20:37     ` John Snow
2021-09-22 20:38       ` John Snow
2021-10-04  8:35         ` Hanna Reitz
2021-10-04  8:31       ` Hanna Reitz
2021-09-16  4:09 ` [PATCH v3 15/16] python: Add iotest linters to test suite John Snow
2021-09-16  4:09 ` [PATCH v3 16/16] iotests/linters: check mypy files all at once John Snow
2021-09-17 11:23   ` Hanna Reitz
2021-09-22 20:41     ` John Snow
2021-09-17  5:46 ` [PATCH v3 00/16] python/iotests: Run iotest linters during Python CI John Snow

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='CAFn=p-bgfkYYpnP6q5E2mxsCsK3tJS6sQFzSXfWFerk9qf1hRQ@mail.gmail.com' \
    --to=jsnow@redhat.com \
    --cc=armbru@redhat.com \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.