scripts: More Python fixes
v4 cover scripts: More Python fixes
Trivial Python3 fixes, again...
Since v3:
- Fixed missing scripts/qemugdb/timers.py (kwolf)
- Cover more scripts
- Check for __main__ in few scripts
Since v2:
- Remove patch updating MAINTAINERS
Since v1:
- Added Alex Bennée A-b tags
- Addressed John Snow review comments
- Use /usr/bin/env
- Do not modify os.path (dropped last patch)
Philippe Mathieu-Daudé (6):
scripts/qemugdb: Remove shebang header scripts/qemu-gdb: Use Python 3 interpreter
scripts/qmp: Use Python 3 interpreter scripts/kvm/vmxcap: Use Python 3 interpreter and add pseudo-main() scripts/modules/module_block: Use Python 3 interpreter & add
pseudo-main
tests/migration/guestperf: Use Python 3 interpreter
scripts/kvm/vmxcap | 7 ++++--- scripts/modules/module_block.py | 31 +++++++++++++++--------------- scripts/qemu-gdb.py | 4 ++-- scripts/qemugdb/__init__.py | 3 +-- scripts/qemugdb/aio.py | 3 +-- scripts/qemugdb/coroutine.py | 3 +-- scripts/qemugdb/mtree.py | 4 +--- scripts/qemugdb/tcg.py | 1 - scripts/qemugdb/timers.py | 1 - scripts/qmp/qom-get | 2 +- scripts/qmp/qom-list | 2 +- scripts/qmp/qom-set | 2 +- scripts/qmp/qom-tree | 2 +- tests/migration/guestperf-batch.py | 2 +- tests/migration/guestperf-plot.py | 2 +- tests/migration/guestperf.py | 2 +- 16 files changed, 33 insertions(+), 38 deletions(-)
Signature · 1 line
2.21.3
PATCH v4 1/6 scripts/qemugdb: Remove shebang header
From: Philippe Mathieu-Daudé <[email protected]>
These scripts are loaded as plugin by GDB (and they don't have any __main__ entry point). Remove the shebang header.
--- scripts/qemugdb/__init__.py | 3 +-- scripts/qemugdb/aio.py | 3 +-- scripts/qemugdb/coroutine.py | 3 +-- scripts/qemugdb/mtree.py | 4 +--- scripts/qemugdb/tcg.py | 1 - scripts/qemugdb/timers.py | 1 - 6 files changed, 4 insertions(+), 11 deletions(-)
scripts/qemugdb/__init__.py +1 -2
@@ -1,5 +1,4 @@ -#!/usr/bin/python - +# # GDB debugging support # # Copyright (c) 2015 Linaro Ltd
scripts/qemugdb/aio.py +1 -2
@@ -1,5 +1,4 @@ -#!/usr/bin/python - +# # GDB debugging support: aio/iohandler debug # # Copyright (c) 2015 Red Hat, Inc.
scripts/qemugdb/coroutine.py +1 -2
@@ -1,5 +1,4 @@ -#!/usr/bin/python - +# # GDB debugging support # # Copyright 2012 Red Hat, Inc. and/or its affiliates
scripts/qemugdb/mtree.py +1 -3
@@ -1,5 +1,4 @@ -#!/usr/bin/python - +# # GDB debugging support # # Copyright 2012 Red Hat, Inc. and/or its affiliates
@@ -84,4 +83,3 @@ def print_item(self, ptr, offset = gdb.Value(0), level = 0): while not isnull(subregion): self.print_item(subregion, addr, level) subregion = subregion['subregions_link']['tqe_next'] -
scripts/qemugdb/tcg.py +0 -1
@@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # # GDB debugging support, TCG status
scripts/qemugdb/timers.py +0 -1
@@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # GDB debugging support #
Signature · 1 line
2.21.3
Re: [PATCH v4 1/6] scripts/qemugdb: Remove shebang header
Quoted 7 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
These scripts are loaded as plugin by GDB (and they don't have any
__main__entry point). Remove the shebang header.Acked-by Alex Bennée <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]
(The A-B should come below the S-O-B unless you do mean to indicate you've since made changes that AB didn't acknowledge, I think.)
PATCH v4 2/6 scripts/qemu-gdb: Use Python 3 interpreter
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- scripts/qemu-gdb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/qemu-gdb.py +2 -2
@@ -1,5 +1,5 @@ -#!/usr/bin/python - +#!/usr/bin/env python3 +# # GDB debugging support # # Copyright 2012 Red Hat, Inc. and/or its affiliates
Signature · 1 line
2.21.3
Re: [PATCH v4 2/6] scripts/qemu-gdb: Use Python 3 interpreter
Quoted 3 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
PATCH v4 3/6 scripts/qmp: Use Python 3 interpreter
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- scripts/qmp/qom-get | 2 +- scripts/qmp/qom-list | 2 +- scripts/qmp/qom-set | 2 +- scripts/qmp/qom-tree | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
scripts/qmp/qom-get +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools #
scripts/qmp/qom-list +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools #
scripts/qmp/qom-set +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools #
scripts/qmp/qom-tree +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools #
Signature · 1 line
2.21.3
Re: [PATCH v4 3/6] scripts/qmp: Use Python 3 interpreter
Quoted 3 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Whoops, I address this in a patch series I'm working on, too. I'll keep my patch in there for now until this one makes it in, or vice-versa.
Quoted 48 lines
--- scripts/qmp/qom-get | 2 +- scripts/qmp/qom-list | 2 +- scripts/qmp/qom-set | 2 +- scripts/qmp/qom-tree | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)scripts/qmp/qom-get +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools #scripts/qmp/qom-list +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools #scripts/qmp/qom-set +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools #scripts/qmp/qom-tree +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools #
Signature · 1 line
—js
PATCH v4 4/6 scripts/kvm/vmxcap: Use Python 3 interpreter and add pseudo-main()
In reply to Philippe Mathieu-Daudé--- scripts/kvm/vmxcap | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
scripts/kvm/vmxcap +4 -3
@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # tool for querying VMX capabilities #
@@ -275,5 +275,6 @@ controls = [ ), ] -for c in controls: - c.show() +if __name__ == '__main__': + for c in controls: + c.show()
Signature · 1 line
2.21.3
Re: [PATCH v4 4/6] scripts/kvm/vmxcap: Use Python 3 interpreter and add pseudo-main()
Quoted 17 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- scripts/kvm/vmxcap | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)scripts/kvm/vmxcap +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # tool for querying VMX capabilities #
scripts/kvm/vmxcap controls = [ · line 280
Quoted 8 lines
scripts/kvm/vmxcap +3
-2@@ -275,5 +275,6 @@ controls = [ ), ] -for c in controls: - c.show() +if __name__ == '__main__': + for c in controls: + c.show()
Re: [PATCH v4 4/6] scripts/kvm/vmxcap: Use Python 3 interpreter and add pseudo-main()
In reply to Philippe Mathieu-DaudéQuoted 17 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- scripts/kvm/vmxcap | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)scripts/kvm/vmxcap +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # tool for querying VMX capabilities #
scripts/kvm/vmxcap controls = [ · line 280
Quoted 8 lines
scripts/kvm/vmxcap +3
-2@@ -275,5 +275,6 @@ controls = [ ), ] -for c in controls: - c.show() +if __name__ == '__main__': + for c in controls: + c.show()
yay
PATCH v4 5/6 scripts/modules/module_block: Use Python 3 interpreter & add pseudo-main
In reply to Philippe Mathieu-Daudé--- scripts/modules/module_block.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
scripts/modules/module_block.py +16 -15
@@ -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 + # 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)
Signature · 1 line
2.21.3
Re: [PATCH v4 5/6] scripts/modules/module_block: Use Python 3 interpreter & add pseudo-main
Quoted 24 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- scripts/modules/module_block.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)scripts/modules/module_block.py +1
-2@@ -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):
scripts/modules/module_block.py def print_bottom(fheader): · line 83
Quoted 10 lines
scripts/modules/module_block.py +2
-5@@ -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.
Quoted 15 lines
scripts/modules/module_block.py +7
-6+ # 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):
scripts/modules/module_block.py def print_bottom(fheader): · line 99
Quoted 10 lines
scripts/modules/module_block.py +6
-2+ 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:
PATCH v4 6/6 tests/migration/guestperf: Use Python 3 interpreter
In reply to Philippe Mathieu-Daudé--- tests/migration/guestperf-batch.py | 2 +- tests/migration/guestperf-plot.py | 2 +- tests/migration/guestperf.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
tests/migration/guestperf-batch.py +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # Migration test batch comparison invokation #
tests/migration/guestperf-plot.py +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # Migration test graph plotting command #
tests/migration/guestperf.py +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # Migration test direct invokation command #
Signature · 1 line
2.21.3
Re: [PATCH v4 6/6] tests/migration/guestperf: Use Python 3 interpreter
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Am 12.05.2020 um 12:32 hat Philippe Mathieu-Daudé geschrieben:
Quoted 6 lines
Trivial Python3 fixes, again...
Since v3:
- Fixed missingscripts/qemugdb/timers.py(kwolf)
- Cover more scripts
- Check for__main__in few scripts
I'm not sure if the __main__ check actually provides anything useful in source files of standalone tools that aren't supposed to be imported from somewhere else. But of course, it's not wrong either.
Philippe Mathieu-Daudé
AppliedQuoted 34 lines · Philippe Mathieu-Daudé
Trivial Python3 fixes, again...
Since v3:
- Fixed missingscripts/qemugdb/timers.py(kwolf)
- Cover more scripts
- Check for__main__in few scriptsSince v2:
- Remove patch updatingMAINTAINERSSince v1:
- Added Alex Bennée A-b tags
- Addressed John Snow review comments
- Use/usr/bin/env
- Do not modify os.path (dropped last patch)Philippe Mathieu-Daudé (6):
scripts/qemugdb: Remove shebang headerscripts/qemu-gdb: Use Python 3 interpreter
scripts/qmp: Use Python 3 interpreterscripts/kvm/vmxcap: Use Python 3 interpreter and add pseudo-main()scripts/modules/module_block: Use Python 3 interpreter & add
pseudo-main
tests/migration/guestperf: Use Python 3 interpreterscripts/kvm/vmxcap | 7 ++++--- scripts/modules/module_block.py | 31 +++++++++++++++--------------- scripts/qemu-gdb.py | 4 ++-- scripts/qemugdb/__init__.py | 3 +-- scripts/qemugdb/aio.py | 3 +-- scripts/qemugdb/coroutine.py | 3 +-- scripts/qemugdb/mtree.py | 4 +--- scripts/qemugdb/tcg.py | 1 - scripts/qemugdb/timers.py | 1 -
Quoted 8 lines
scripts/qmp/qom-get | 2 +- scripts/qmp/qom-list | 2 +- scripts/qmp/qom-set | 2 +- scripts/qmp/qom-tree | 2 +- tests/migration/guestperf-batch.py | 2 +- tests/migration/guestperf-plot.py | 2 +- tests/migration/guestperf.py | 2 +- 16 files changed, 33 insertions(+), 38 deletions(-)
Thanks, applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next