All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	qemu-block@nongnu.org, qemu-trivial@nongnu.org,
	"Cleber Rosa" <crosa@redhat.com>,
	kvm@vger.kernel.org, "Eduardo Habkost" <ehabkost@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Fam Zheng" <fam@euphon.net>
Subject: Re: [PATCH v4 5/6] scripts/modules/module_block: Use Python 3 interpreter & add pseudo-main
Date: Wed, 13 May 2020 17:04:59 -0400	[thread overview]
Message-ID: <fdae1c32-5f22-543d-6bef-412cde4d0b8a@redhat.com> (raw)
In-Reply-To: <20200512103238.7078-6-philmd@redhat.com>



On 5/12/20 6:32 AM, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  scripts/modules/module_block.py | 31 ++++++++++++++++---------------
>  1 file changed, 16 insertions(+), 15 deletions(-)
> 
> diff --git a/scripts/modules/module_block.py b/scripts/modules/module_block.py
> index f23191fac1..2e7021b952 100644
> --- a/scripts/modules/module_block.py
> +++ b/scripts/modules/module_block.py
> @@ -1,4 +1,4 @@
> -#!/usr/bin/python
> +#!/usr/bin/env python3
>  #
>  # Module information generator
>  #
> @@ -10,7 +10,6 @@
>  # This work is licensed under the terms of the GNU GPL, version 2.
>  # See the COPYING file in the top-level directory.
>  
> -import sys
>  import os
>  
>  def get_string_struct(line):
> @@ -80,19 +79,21 @@ def print_bottom(fheader):
>  #endif
>  ''')
>  
> -# First argument: output file
> -# All other arguments: modules source files (.c)
> -output_file = sys.argv[1]
> -with open(output_file, 'w') as fheader:
> -    print_top(fheader)
> +if __name__ == '__main__':
> +    import sys

You can keep the imports at the top of the file.

If you want to split apart the code such that the core import doesn't
import it, you can create a "core module" containing the classes and
routines, and a separate script entrypoint, which imports arg parsers,
sys.argv, etc.

For this, for now, it's okay to just leave it at the top of the file.

> +    # First argument: output file
> +    # All other arguments: modules source files (.c)
> +    output_file = sys.argv[1]
> +    with open(output_file, 'w') as fheader:
> +        print_top(fheader)
>  
> -    for filename in sys.argv[2:]:
> -        if os.path.isfile(filename):
> -            process_file(fheader, filename)
> -        else:
> -            print("File " + filename + " does not exist.", file=sys.stderr)
> -            sys.exit(1)
> +        for filename in sys.argv[2:]:
> +            if os.path.isfile(filename):
> +                process_file(fheader, filename)
> +            else:
> +                print("File " + filename + " does not exist.", file=sys.stderr)
> +                sys.exit(1)
>  
> -    print_bottom(fheader)
> +        print_bottom(fheader)
>  
> -sys.exit(0)
> +    sys.exit(0)
> 

But, well. It's nitpicky and I'm not sure it matters just yet. It might,
as we start to expand pylint to more places, but we're not being
rigorous about that just yet. So either way, I know this works:

Reviewed-by: John Snow <jsnow@redhat.com>


WARNING: multiple messages have this Message-ID (diff)
From: John Snow <jsnow@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>,
	qemu-block@nongnu.org, kvm@vger.kernel.org,
	qemu-trivial@nongnu.org, "Marcelo Tosatti" <mtosatti@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Eduardo Habkost" <ehabkost@redhat.com>
Subject: Re: [PATCH v4 5/6] scripts/modules/module_block: Use Python 3 interpreter & add pseudo-main
Date: Wed, 13 May 2020 17:04:59 -0400	[thread overview]
Message-ID: <fdae1c32-5f22-543d-6bef-412cde4d0b8a@redhat.com> (raw)
In-Reply-To: <20200512103238.7078-6-philmd@redhat.com>



On 5/12/20 6:32 AM, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  scripts/modules/module_block.py | 31 ++++++++++++++++---------------
>  1 file changed, 16 insertions(+), 15 deletions(-)
> 
> diff --git a/scripts/modules/module_block.py b/scripts/modules/module_block.py
> index f23191fac1..2e7021b952 100644
> --- a/scripts/modules/module_block.py
> +++ b/scripts/modules/module_block.py
> @@ -1,4 +1,4 @@
> -#!/usr/bin/python
> +#!/usr/bin/env python3
>  #
>  # Module information generator
>  #
> @@ -10,7 +10,6 @@
>  # This work is licensed under the terms of the GNU GPL, version 2.
>  # See the COPYING file in the top-level directory.
>  
> -import sys
>  import os
>  
>  def get_string_struct(line):
> @@ -80,19 +79,21 @@ def print_bottom(fheader):
>  #endif
>  ''')
>  
> -# First argument: output file
> -# All other arguments: modules source files (.c)
> -output_file = sys.argv[1]
> -with open(output_file, 'w') as fheader:
> -    print_top(fheader)
> +if __name__ == '__main__':
> +    import sys

You can keep the imports at the top of the file.

If you want to split apart the code such that the core import doesn't
import it, you can create a "core module" containing the classes and
routines, and a separate script entrypoint, which imports arg parsers,
sys.argv, etc.

For this, for now, it's okay to just leave it at the top of the file.

> +    # First argument: output file
> +    # All other arguments: modules source files (.c)
> +    output_file = sys.argv[1]
> +    with open(output_file, 'w') as fheader:
> +        print_top(fheader)
>  
> -    for filename in sys.argv[2:]:
> -        if os.path.isfile(filename):
> -            process_file(fheader, filename)
> -        else:
> -            print("File " + filename + " does not exist.", file=sys.stderr)
> -            sys.exit(1)
> +        for filename in sys.argv[2:]:
> +            if os.path.isfile(filename):
> +                process_file(fheader, filename)
> +            else:
> +                print("File " + filename + " does not exist.", file=sys.stderr)
> +                sys.exit(1)
>  
> -    print_bottom(fheader)
> +        print_bottom(fheader)
>  
> -sys.exit(0)
> +    sys.exit(0)
> 

But, well. It's nitpicky and I'm not sure it matters just yet. It might,
as we start to expand pylint to more places, but we're not being
rigorous about that just yet. So either way, I know this works:

Reviewed-by: John Snow <jsnow@redhat.com>



  reply	other threads:[~2020-05-13 21:05 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 10:32 [PATCH v4 0/6] scripts: More Python fixes Philippe Mathieu-Daudé
2020-05-12 10:32 ` Philippe Mathieu-Daudé
2020-05-12 10:32 ` [PATCH v4 1/6] scripts/qemugdb: Remove shebang header Philippe Mathieu-Daudé
2020-05-12 10:32   ` Philippe Mathieu-Daudé
2020-05-13 20:58   ` John Snow
2020-05-13 20:58     ` John Snow
2020-05-12 10:32 ` [PATCH v4 2/6] scripts/qemu-gdb: Use Python 3 interpreter Philippe Mathieu-Daudé
2020-05-12 10:32   ` Philippe Mathieu-Daudé
2020-05-13 20:58   ` John Snow
2020-05-13 20:58     ` John Snow
2020-05-12 10:32 ` [PATCH v4 3/6] scripts/qmp: " Philippe Mathieu-Daudé
2020-05-12 10:32   ` Philippe Mathieu-Daudé
2020-05-13 20:59   ` John Snow
2020-05-13 20:59     ` John Snow
2020-05-12 10:32 ` [PATCH v4 4/6] scripts/kvm/vmxcap: Use Python 3 interpreter and add pseudo-main() Philippe Mathieu-Daudé
2020-05-12 10:32   ` Philippe Mathieu-Daudé
2020-05-12 11:35   ` Paolo Bonzini
2020-05-12 11:35     ` Paolo Bonzini
2020-05-13 21:00   ` John Snow
2020-05-13 21:00     ` John Snow
2020-05-12 10:32 ` [PATCH v4 5/6] scripts/modules/module_block: Use Python 3 interpreter & add pseudo-main Philippe Mathieu-Daudé
2020-05-12 10:32   ` Philippe Mathieu-Daudé
2020-05-13 21:04   ` John Snow [this message]
2020-05-13 21:04     ` John Snow
2020-05-12 10:32 ` [PATCH v4 6/6] tests/migration/guestperf: Use Python 3 interpreter Philippe Mathieu-Daudé
2020-05-12 10:32   ` Philippe Mathieu-Daudé
2020-05-13 21:08   ` John Snow
2020-05-13 21:08     ` John Snow
2020-05-12 11:16 ` [PATCH v4 0/6] scripts: More Python fixes Kevin Wolf
2020-05-12 11:16   ` Kevin Wolf
2020-05-29  9:40 ` Philippe Mathieu-Daudé
2020-05-29  9:40   ` Philippe Mathieu-Daudé

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=fdae1c32-5f22-543d-6bef-412cde4d0b8a@redhat.com \
    --to=jsnow@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=fam@euphon.net \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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 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.