Skip to contentSkip to conversation

python: create installable package

PATCH Superseded John Snow 3 participants 47 messages Oct 20, 2020 – Oct 29, 2020

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

John Snow

author
#0 lore raw

v3 cover python: create installable package

Based-on: https://gitlab.com/jsnow/qemu/-/tree/python

This series factors the python/qemu directory as an installable package. It does not yet actually change the mechanics of how any other python source in the tree actually consumes it (yet), beyond the import path.

The point of this series is primarily to formalize our dependencies on mypy, flake8, isort, and pylint alongside versions that are known to work. It also adds explicitly pinned versions of these dependencies that should behave in a repeatable and known way for developers and CI environments both.

With the python tooling as a proper package, you can install this package in editable or production mode to a virtual environment, your local user environment, or your system packages. The primary benefit of this is to gain access to QMP tooling regardless of CWD, without needing to battle sys.path.

For example: when developing, you may go to qemu/python/ and invoke pipenv shell to activate a virtual environment that contains the qemu packages. This package will always reflect the current version of the source files in the tree. When you are finished, you can simply exit the shell to remove these packages from your python environment.

When not developing, you could install a version of this package to your environment outright to gain access to the QMP and QEMUMachine classes for lightweight scripting and testing by using pip: "pip install [--user] ."

Finally, this package is formatted in such a way that it COULD be uploaded to https://pypi.org/project/qemu and installed independently of qemu.git with pip install qemu, but that button remains unpushed.

TESTING THIS SERIES:

CD to qemu/python first, and then:

1. Try "pipenv shell" to get a venv with the package installed to it in editable mode. Ctrl+d exits this venv shell. While in this shell, any python script that uses "from qemu.[qmp|machine] import ..." should work correctly regardless of your CWD.

2. Try "pipenv sync --dev" to create/update the venv with the development packages without actually entering the venv. This should install isort, mypy, flake8 and pylint to the venv.

3. After the above sync, try "pipenv shell" again, and from the python project root, try any of the following:

- pylint qemu
- flake8 qemu
- isort -c qemu
- mypy qemu

4. Leave any venv you are in, and from the project root, try the following commands:

- pipenv run pylint qemu
- pipenv run flake8 qemu
- pipenv run isort -c qemu
- pipenv run mypy qemu

V3:
- Changed "qemu.core" to "qemu.qmp" and "qemu.machine",
Partly to accommodate forthcoming work which would benefit from a separate qemu.qmp namespace.
- Changed the initial version from 5.2.0a1 to 0.5.2.0a1, to allow for more rapid development while we smooth out the initial kinks.
- 001: Renamed patch title; differences implement the new names.
- 002: Readme changes for above.
- 003: Version change.
- 004: New readme for the new qmp directory.
- 006: A few more import exceptions for pylint, hopefully temporary.
- 009: Updated flake8 config comment to match qapi's
- 012: Added namespace_package configuration value

001/15:[down] 'python: create qemu packages'
002/15:[0009] [FC] 'python: add qemu package installer' 003/15:[0002] [FC] 'python: add VERSION file' 004/15:[0015] [FC] 'python: add directory structure README.rst files' 005/15:[----] [--] 'python: Add pipenv support' 006/15:[down] 'python: add pylint import exceptions' 007/15:[----] [--] 'python: move pylintrc into setup.cfg' 008/15:[----] [--] 'python: add pylint to pipenv' 009/15:[0002] [FC] 'python: move flake8 config to setup.cfg' 010/15:[----] [--] 'python: Add flake8 to pipenv' 011/15:[----] [-C] 'python: move mypy.ini into setup.cfg' 012/15:[0001] [FC] 'python: add mypy to pipenv' 013/15:[----] [--] 'python: move .isort.cfg into setup.cfg' 014/15:[----] [--] 'python/qemu: add isort to pipenv' 015/15:[----] [--] 'python/qemu: add qemu package itself to pipenv'

John Snow (15):
python: create qemu packages
python: add qemu package installer
python: add VERSION file
python: add directory structure README.rst files
python: Add pipenv support
python: add pylint import exceptions
python: move pylintrc into setup.cfg
python: add pylint to pipenv
python: move flake8 config to setup.cfg
python: Add flake8 to pipenv
python: move mypy.ini into setup.cfg
python: add mypy to pipenv
python: move .isort.cfg into setup.cfg python/qemu: add isort to pipenv python/qemu: add qemu package itself to pipenv

 python/PACKAGE.rst                          |  26 +++
 python/README.rst                           |  27 +++
 python/qemu/README.rst                      |   8 +
 python/qemu/machine/README.rst              |   9 +
 python/qemu/qmp/README.rst                  |   9 +
 python/Pipfile                              |  16 ++
 python/Pipfile.lock                         | 207 ++++++++++++++++++++
 python/VERSION                              |   1 +
 python/mypy.ini                             |   4 -
 python/qemu/.flake8                         |   2 -
 python/qemu/.isort.cfg                      |   7 -
 python/qemu/__init__.py                     |  11 --
 python/qemu/machine/__init__.py             |  44 +++++
 python/qemu/{ => machine}/accel.py          |   0
 python/qemu/{ => machine}/console_socket.py |   0
 python/qemu/{ => machine}/machine.py        |  16 +-
 python/qemu/{ => machine}/qtest.py          |   3 +-
 python/qemu/{qmp.py => qmp/__init__.py}     |  12 +-
 python/{qemu/pylintrc => setup.cfg}         |  67 ++++---
 python/setup.py                             |  23 +++
 tests/acceptance/boot_linux.py              |   3 +-
 tests/qemu-iotests/297                      |   2 +-
 tests/qemu-iotests/300                      |   4 +-
 tests/qemu-iotests/iotests.py               |   2 +-
 tests/vm/basevm.py                          |   3 +-
 25 files changed, 437 insertions(+), 69 deletions(-)
 create mode 100644 python/PACKAGE.rst
 create mode 100644 python/README.rst
 create mode 100644 python/qemu/README.rst
 create mode 100644 python/qemu/machine/README.rst
 create mode 100644 python/qemu/qmp/README.rst
 create mode 100644 python/Pipfile
 create mode 100644 python/Pipfile.lock
 create mode 100644 python/VERSION
 delete mode 100644 python/mypy.ini
 delete mode 100644 python/qemu/.flake8
 delete mode 100644 python/qemu/.isort.cfg
 delete mode 100644 python/qemu/__init__.py
 create mode 100644 python/qemu/machine/__init__.py
 rename python/qemu/{ => machine}/accel.py (100%)
 rename python/qemu/{ => machine}/console_socket.py (100%)
 rename python/qemu/{ => machine}/machine.py (98%)
 rename python/qemu/{ => machine}/qtest.py (98%)
 rename python/qemu/{qmp.py => qmp/__init__.py} (96%)
 rename python/{qemu/pylintrc => setup.cfg} (50%)
 mode change 100644 => 100755
 create mode 100755 python/setup.py
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH v3 1/15 python: create qemu packages

move python/qemu/*.py to python/qemu/[machine, qmp]/*.py and update import directives across the tree.

This is done to create a PEP420 namespace package, in which we may create subpackages. To do this, the namespace directory ("qemu") should not have any modules in it. Those files will go into new 'machine' and 'qmp' subpackages instead.

Implement machine/__init__.py making the top-level classes and functions from its various modules available directly inside the package. Change qmp.py to qmp/__init__.py similarly, such that all of the useful QMP library classes are available directly from "qemu.qmp" instead of "qemu.qmp.qmp".

---
 python/{qemu => }/.isort.cfg                |  0
 python/qemu/__init__.py                     | 11 ------
 python/qemu/{ => machine}/.flake8           |  0
 python/qemu/machine/__init__.py             | 41 +++++++++++++++++++++
 python/qemu/{ => machine}/accel.py          |  0
 python/qemu/{ => machine}/console_socket.py |  0
 python/qemu/{ => machine}/machine.py        | 16 +++++---
 python/qemu/{ => machine}/pylintrc          |  0
 python/qemu/{ => machine}/qtest.py          |  3 +-
 python/qemu/{qmp.py => qmp/__init__.py}     | 12 +++++-
 tests/acceptance/boot_linux.py              |  3 +-
 tests/qemu-iotests/297                      |  2 +-
 tests/qemu-iotests/300                      |  4 +-
 tests/qemu-iotests/iotests.py               |  2 +-
 tests/vm/basevm.py                          |  3 +-
 15 files changed, 71 insertions(+), 26 deletions(-)
 rename python/{qemu => }/.isort.cfg (100%)
 delete mode 100644 python/qemu/__init__.py
 rename python/qemu/{ => machine}/.flake8 (100%)
 create mode 100644 python/qemu/machine/__init__.py
 rename python/qemu/{ => machine}/accel.py (100%)
 rename python/qemu/{ => machine}/console_socket.py (100%)
 rename python/qemu/{ => machine}/machine.py (98%)
 rename python/qemu/{ => machine}/pylintrc (100%)
 rename python/qemu/{ => machine}/qtest.py (99%)
 rename python/qemu/{qmp.py => qmp/__init__.py} (96%)
python/.isort.cfg renamed from python/qemu/.isort.cfg +0 -0
similarity index 100%
rename from python/qemu/.isort.cfg
rename to python/.isort.cfg
python/qemu/__init__.py deleted +0 -11
deleted file mode 100644
index 4ca06c34a4..0000000000
@@ -1,11 +0,0 @@
-# QEMU library
-#
-# Copyright (C) 2015-2016 Red Hat Inc.
-# Copyright (C) 2012 IBM Corp.
-#
-# Authors:
-#  Fam Zheng <[email protected]>
-#
-# This work is licensed under the terms of the GNU GPL, version 2.  See
-# the COPYING file in the top-level directory.
-#
python/qemu/machine/.flake8 renamed from python/qemu/.flake8 +0 -0
similarity index 100%
rename from python/qemu/.flake8
rename to python/qemu/machine/.flake8
python/qemu/machine/__init__.py new file +41 -0

41 lines not on this page · raw message

python/qemu/machine/accel.py renamed from python/qemu/accel.py +0 -0
similarity index 100%
rename from python/qemu/accel.py
rename to python/qemu/machine/accel.py
python/qemu/machine/console_socket.py renamed from python/qemu/console_socket.py +0 -0
similarity index 100%
rename from python/qemu/console_socket.py
rename to python/qemu/machine/console_socket.py
python/qemu/machine/machine.py renamed from python/qemu/machine.py +11 -5
similarity index 98%
rename from python/qemu/machine.py
rename to python/qemu/machine/machine.py
index 6420f01bed..a5dc305539 100644
@@ -38,8 +38,14 @@
     Type,
 )
 
-from . import console_socket, qmp
-from .qmp import QMPMessage, QMPReturnValue, SocketAddrT
+from qemu.qmp import (
+    QEMUMonitorProtocol,
+    QMPMessage,
+    QMPReturnValue,
+    SocketAddrT,
+)
+
+from . import console_socket
 
 
 LOG = logging.getLogger(__name__)
@@ -139,7 +145,7 @@ def __init__(self,
         self._events: List[QMPMessage] = []
         self._iolog: Optional[str] = None
         self._qmp_set = True   # Enable QMP monitor by default.
-        self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] = None
+        self._qmp_connection: Optional[QEMUMonitorProtocol] = None
         self._qemu_full_args: Tuple[str, ...] = ()
         self._temp_dir: Optional[str] = None
         self._launched = False
@@ -314,7 +320,7 @@ def _pre_launch(self) -> None:
             if self._remove_monitor_sockfile:
                 assert isinstance(self._monitor_address, str)
                 self._remove_files.append(self._monitor_address)
-            self._qmp_connection = qmp.QEMUMonitorProtocol(
+            self._qmp_connection = QEMUMonitorProtocol(
                 self._monitor_address,
                 server=True,
                 nickname=self._name
@@ -534,7 +540,7 @@ def set_qmp_monitor(self, enabled: bool = True) -> None:
         self._qmp_set = enabled
 
     @property
-    def _qmp(self) -> qmp.QEMUMonitorProtocol:
+    def _qmp(self) -> QEMUMonitorProtocol:
         if self._qmp_connection is None:
             raise QEMUMachineError("Attempt to access QMP with no connection")
         return self._qmp_connection
python/qemu/machine/pylintrc renamed from python/qemu/pylintrc +0 -0
similarity index 100%
rename from python/qemu/pylintrc
rename to python/qemu/machine/pylintrc
python/qemu/machine/qtest.py renamed from python/qemu/qtest.py +2 -1
similarity index 99%
rename from python/qemu/qtest.py
rename to python/qemu/machine/qtest.py
index 39a0cf62fe..53926e434a 100644
@@ -26,8 +26,9 @@
     TextIO,
 )
 
+from qemu.qmp import SocketAddrT
+
 from .machine import QEMUMachine
-from .qmp import SocketAddrT
 
 
 class QEMUQtestProtocol:
python/qemu/qmp/__init__.py renamed from python/qemu/qmp.py +11 -1
similarity index 96%
rename from python/qemu/qmp.py
rename to python/qemu/qmp/__init__.py
index 2cd4d43036..9606248a3d 100644
@@ -1,4 +1,14 @@
-""" QEMU Monitor Protocol Python class """
+"""
+QEMU Monitor Protocol (QMP) development library & tooling.
+
+This package provides a fairly low-level class for communicating to QMP
+protocol servers, as implemented by QEMU, the QEMU Guest Agent, and the
+QEMU Storage Daemon. This library is not intended for production use.
+
+`QEMUMonitorProtocol` is the primary class of interest, and all errors
+raised derive from `QMPError`.
+"""
+
 # Copyright (C) 2009, 2010 Red Hat Inc.
 #
 # Authors:
tests/acceptance/boot_linux.py +1 -2
index 0055dc7cee..54f999e647 100644
@@ -12,8 +12,7 @@
 
 from avocado_qemu import Test, BUILD_DIR
 
-from qemu.accel import kvm_available
-from qemu.accel import tcg_available
+from qemu.machine import kvm_available, tcg_available
 
 from avocado.utils import cloudinit
 from avocado.utils import network
tests/qemu-iotests/297 +1 -1
index 5c5420712b..8236875222 100755
@@ -36,7 +36,7 @@ MYPYPATH=../../python/ mypy --warn-unused-configs --disallow-subclassing-any \
     --disallow-any-generics --disallow-incomplete-defs \
     --disallow-untyped-decorators --no-implicit-optional \
     --warn-redundant-casts --warn-unused-ignores \
-    --no-implicit-reexport iotests.py
+    --no-implicit-reexport --namespace-packages iotests.py
 
 # success, all done
 echo "*** done"
tests/qemu-iotests/300 +2 -2
index 5b75121b84..a41fac4e1d 100755
@@ -23,7 +23,7 @@ import random
 import re
 from typing import Dict, List, Optional, Union
 import iotests
-import qemu
+from qemu.machine import machine
 
 BlockBitmapMapping = List[Dict[str, Union[str, List[Dict[str, str]]]]]
 
@@ -454,7 +454,7 @@ class TestBlockBitmapMappingErrors(TestDirtyBitmapMigration):
         # the failed migration
         try:
             self.vm_b.shutdown()
-        except qemu.machine.AbnormalShutdown:
+        except machine.AbnormalShutdown:
             pass
 
     def test_aliased_bitmap_name_too_long(self) -> None:
tests/qemu-iotests/iotests.py +1 -1
index 63d2ace93c..6574afd735 100644
@@ -37,7 +37,7 @@
 
 # pylint: disable=import-error, wrong-import-position
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu import qtest
+from qemu.machine import qtest
 from qemu.qmp import QMPMessage
 
 # Use this logger for logging messages directly from the iotests module
tests/vm/basevm.py +1 -2
index 3fac20e929..b38969f61f 100644
@@ -19,8 +19,7 @@
 import time
 import datetime
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.accel import kvm_available
-from qemu.machine import QEMUMachine
+from qemu.machine import kvm_available, QEMUMachine
 import subprocess
 import hashlib
 import argparse
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH v3 01/15] python: create qemu packages

Quoted 105 lines · John Snow

move python/qemu/*.py to python/qemu/[machine, qmp]/*.py and update import directives across the tree.

This is done to create a PEP420 namespace package, in which we may create subpackages. To do this, the namespace directory ("qemu") should not have any modules in it. Those files will go into new 'machine' and 'qmp' subpackages instead.

Implement machine/__init__.py making the top-level classes and functions from its various modules available directly inside the package. Change qmp.py to qmp/__init__.py similarly, such that all of the useful QMP library classes are available directly from "qemu.qmp" instead of "qemu.qmp.qmp".

---
 python/{qemu => }/.isort.cfg                |  0
 python/qemu/__init__.py                     | 11 ------
 python/qemu/{ => machine}/.flake8           |  0
 python/qemu/machine/__init__.py             | 41 +++++++++++++++++++++
 python/qemu/{ => machine}/accel.py          |  0
 python/qemu/{ => machine}/console_socket.py |  0
 python/qemu/{ => machine}/machine.py        | 16 +++++---
 python/qemu/{ => machine}/pylintrc          |  0
 python/qemu/{ => machine}/qtest.py          |  3 +-
 python/qemu/{qmp.py => qmp/__init__.py}     | 12 +++++-
 tests/acceptance/boot_linux.py              |  3 +-
 tests/qemu-iotests/297                      |  2 +-
 tests/qemu-iotests/300                      |  4 +-
 tests/qemu-iotests/iotests.py               |  2 +-
 tests/vm/basevm.py                          |  3 +-
 15 files changed, 71 insertions(+), 26 deletions(-)
 rename python/{qemu => }/.isort.cfg (100%)
 delete mode 100644 python/qemu/__init__.py
 rename python/qemu/{ => machine}/.flake8 (100%)
 create mode 100644 python/qemu/machine/__init__.py
 rename python/qemu/{ => machine}/accel.py (100%)
 rename python/qemu/{ => machine}/console_socket.py (100%)
 rename python/qemu/{ => machine}/machine.py (98%)
 rename python/qemu/{ => machine}/pylintrc (100%)
 rename python/qemu/{ => machine}/qtest.py (99%)
 rename python/qemu/{qmp.py => qmp/__init__.py} (96%)
python/.isort.cfg renamed from python/qemu/.isort.cfg +0 -0
similarity index 100%
rename from python/qemu/.isort.cfg
rename to python/.isort.cfg
python/qemu/__init__.py deleted +0 -11
deleted file mode 100644
index 4ca06c34a4..0000000000
@@ -1,11 +0,0 @@
-# QEMU library
-#
-# Copyright (C) 2015-2016 Red Hat Inc.
-# Copyright (C) 2012 IBM Corp.
-#
-# Authors:
-#  Fam Zheng <[email protected]>
-#
-# This work is licensed under the terms of the GNU GPL, version 2.  See
-# the COPYING file in the top-level directory.
-#
python/qemu/machine/.flake8 renamed from python/qemu/.flake8 +0 -0
similarity index 100%
rename from python/qemu/.flake8
rename to python/qemu/machine/.flake8
python/qemu/machine/__init__.py new file +31 -0
new file mode 100644
index 0000000000..27b0b19abd
@@ -0,0 +1,41 @@
+"""
+QEMU development and testing library.
+
+This library provides a few high-level classes for driving QEMU from a
+test suite, not intended for production use.
+
+- QEMUMachine: Configure and Boot a QEMU VM
+ - QEMUQtestMachine: VM class, with a qtest socket.
+
+- QEMUQtestProtocol: Connect to, send/receive qtest messages.
+
+- list_accel: List available accelerators
+- kvm_available: Probe for KVM support
+- tcg_available: Probe for TCG support
+"""
+
+# Copyright (C) 2020 John Snow for Red Hat Inc.
+# Copyright (C) 2015-2016 Red Hat Inc.
+# Copyright (C) 2012 IBM Corp.
+#
+# Authors:
+#  John Snow <[email protected]>
+#  Fam Zheng <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+
+from .accel import kvm_available, list_accel, tcg_available
+from .machine import QEMUMachine
+from .qtest import QEMUQtestMachine, QEMUQtestProtocol

python/qemu/machine/__init__.py line 41

Quoted 10 lines
python/qemu/machine/__init__.py new file +10 -0
+
+
+__all__ = (
+    'list_accel',
+    'kvm_available',
+    'tcg_available',
+    'QEMUMachine',
+    'QEMUQtestProtocol',
+    'QEMUQtestMachine',
+)

How far would this approach go? I mean, should all future APIs be developed inside module under "qemu/machine", say "qemu/machine/foo.py" and their main functionality imported here? Or do you see this as a temporary state?

IMO, this is hard to maintain, and is a very easy path to future inconsistencies.

Quoted 109 lines
python/qemu/machine/accel.py renamed from python/qemu/accel.py +0 -0
similarity index 100%
rename from python/qemu/accel.py
rename to python/qemu/machine/accel.py
python/qemu/machine/console_socket.py renamed from python/qemu/console_socket.py +0 -0
similarity index 100%
rename from python/qemu/console_socket.py
rename to python/qemu/machine/console_socket.py
python/qemu/machine/machine.py renamed from python/qemu/machine.py +11 -5
similarity index 98%
rename from python/qemu/machine.py
rename to python/qemu/machine/machine.py
index 6420f01bed..a5dc305539 100644
@@ -38,8 +38,14 @@
     Type,
 )
 
-from . import console_socket, qmp
-from .qmp import QMPMessage, QMPReturnValue, SocketAddrT
+from qemu.qmp import (
+    QEMUMonitorProtocol,
+    QMPMessage,
+    QMPReturnValue,
+    SocketAddrT,
+)
+
+from . import console_socket
 
 
 LOG = logging.getLogger(__name__)
@@ -139,7 +145,7 @@ def __init__(self,
         self._events: List[QMPMessage] = []
         self._iolog: Optional[str] = None
         self._qmp_set = True   # Enable QMP monitor by default.
-        self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] = None
+        self._qmp_connection: Optional[QEMUMonitorProtocol] = None
         self._qemu_full_args: Tuple[str, ...] = ()
         self._temp_dir: Optional[str] = None
         self._launched = False
@@ -314,7 +320,7 @@ def _pre_launch(self) -> None:
             if self._remove_monitor_sockfile:
                 assert isinstance(self._monitor_address, str)
                 self._remove_files.append(self._monitor_address)
-            self._qmp_connection = qmp.QEMUMonitorProtocol(
+            self._qmp_connection = QEMUMonitorProtocol(
                 self._monitor_address,
                 server=True,
                 nickname=self._name
@@ -534,7 +540,7 @@ def set_qmp_monitor(self, enabled: bool = True) -> None:
         self._qmp_set = enabled
 
     @property
-    def _qmp(self) -> qmp.QEMUMonitorProtocol:
+    def _qmp(self) -> QEMUMonitorProtocol:
         if self._qmp_connection is None:
             raise QEMUMachineError("Attempt to access QMP with no connection")
         return self._qmp_connection
python/qemu/machine/pylintrc renamed from python/qemu/pylintrc +0 -0
similarity index 100%
rename from python/qemu/pylintrc
rename to python/qemu/machine/pylintrc
python/qemu/machine/qtest.py renamed from python/qemu/qtest.py +2 -1
similarity index 99%
rename from python/qemu/qtest.py
rename to python/qemu/machine/qtest.py
index 39a0cf62fe..53926e434a 100644
@@ -26,8 +26,9 @@
     TextIO,
 )
 
+from qemu.qmp import SocketAddrT
+
 from .machine import QEMUMachine
-from .qmp import SocketAddrT
 
 
 class QEMUQtestProtocol:
python/qemu/qmp/__init__.py renamed from python/qemu/qmp.py +11 -1
similarity index 96%
rename from python/qemu/qmp.py
rename to python/qemu/qmp/__init__.py
index 2cd4d43036..9606248a3d 100644
@@ -1,4 +1,14 @@
-""" QEMU Monitor Protocol Python class """
+"""
+QEMU Monitor Protocol (QMP) development library & tooling.
+
+This package provides a fairly low-level class for communicating to QMP
+protocol servers, as implemented by QEMU, the QEMU Guest Agent, and the
+QEMU Storage Daemon. This library is not intended for production use.
+
+`QEMUMonitorProtocol` is the primary class of interest, and all errors
+raised derive from `QMPError`.
+"""
+
 # Copyright (C) 2009, 2010 Red Hat Inc.
 #
 # Authors:
tests/acceptance/boot_linux.py +0 -0
index 0055dc7cee..54f999e647 100644

tests/acceptance/boot_linux.py line 16

Quoted 7 lines
tests/acceptance/boot_linux.py +1 -2
@@ -12,8 +12,7 @@
 
 from avocado_qemu import Test, BUILD_DIR
 
-from qemu.accel import kvm_available
-from qemu.accel import tcg_available
+from qemu.machine import kvm_available, tcg_available
 

I think this reveals a slight downgrade of the API caused by the usage of the symbols from "qemu.machine" namespace.

My point is that there are valid use cases for using "kvm_available" without using a "QEMUMachine". This presuposes that "qemu.machine" is named like that because "QEMUMachine" are the main actors of this namespace.

Naming is hard, (so don't assume I believe "utils" below is the best or even a good name), but I'd be more confortable using an API along the lines:

from qemu.utils.accel import kvm_available
kvm_available()

OR

from qemu.utils import accel
accel.kvm_available()

This would also remove the need to keep importing symbols into the current "qemu.machine" namespace.

Quoted 20 lines
tests/acceptance/boot_linux.py +0 -0
 from avocado.utils import cloudinit
 from avocado.utils import network
tests/qemu-iotests/297 +1 -1
index 5c5420712b..8236875222 100755
@@ -36,7 +36,7 @@ MYPYPATH=../../python/ mypy --warn-unused-configs --disallow-subclassing-any \
     --disallow-any-generics --disallow-incomplete-defs \
     --disallow-untyped-decorators --no-implicit-optional \
     --warn-redundant-casts --warn-unused-ignores \
-    --no-implicit-reexport iotests.py
+    --no-implicit-reexport --namespace-packages iotests.py
 
 # success, all done
 echo "*** done"
tests/qemu-iotests/300 +0 -0
index 5b75121b84..a41fac4e1d 100755

tests/qemu-iotests/300 import random · line 27

Quoted 6 lines
tests/qemu-iotests/300 +1 -1
@@ -23,7 +23,7 @@ import random
 import re
 from typing import Dict, List, Optional, Union
 import iotests
-import qemu
+from qemu.machine import machine
 

I believe this gives my previous comment some extra strength. I think this shows that "qemu.machine" containing "machine" really means that the first "machine" naming component doesn't really mean that.

"qemu.utils" is not perfect, but it's much more honest IMO.

Cheers,
- Cleber.

Quoted 41 lines
tests/qemu-iotests/300 +1 -1
 BlockBitmapMapping = List[Dict[str, Union[str, List[Dict[str, str]]]]]
 
@@ -454,7 +454,7 @@ class TestBlockBitmapMappingErrors(TestDirtyBitmapMigration):
         # the failed migration
         try:
             self.vm_b.shutdown()
-        except qemu.machine.AbnormalShutdown:
+        except machine.AbnormalShutdown:
             pass
 
     def test_aliased_bitmap_name_too_long(self) -> None:
tests/qemu-iotests/iotests.py +1 -1
index 63d2ace93c..6574afd735 100644
@@ -37,7 +37,7 @@
 
 # pylint: disable=import-error, wrong-import-position
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu import qtest
+from qemu.machine import qtest
 from qemu.qmp import QMPMessage
 
 # Use this logger for logging messages directly from the iotests module
tests/vm/basevm.py +1 -2
index 3fac20e929..b38969f61f 100644
@@ -19,8 +19,7 @@
 import time
 import datetime
 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.accel import kvm_available
-from qemu.machine import QEMUMachine
+from qemu.machine import kvm_available, QEMUMachine
 import subprocess
 import hashlib
 import argparse
Signature · 1 line
2.26.2
author
#3 lore raw

Re: [PATCH v3 01/15] python: create qemu packages

Quoted 112 lines · Cleber Rosa
Quoted 111 lines · John Snow

move python/qemu/*.py to python/qemu/[machine, qmp]/*.py and update import directives across the tree.

This is done to create a PEP420 namespace package, in which we may create subpackages. To do this, the namespace directory ("qemu") should not have any modules in it. Those files will go into new 'machine' and 'qmp' subpackages instead.

Implement machine/__init__.py making the top-level classes and functions from its various modules available directly inside the package. Change qmp.py to qmp/__init__.py similarly, such that all of the useful QMP library classes are available directly from "qemu.qmp" instead of "qemu.qmp.qmp".

---
  python/{qemu => }/.isort.cfg                |  0
  python/qemu/__init__.py                     | 11 ------
  python/qemu/{ => machine}/.flake8           |  0
  python/qemu/machine/__init__.py             | 41 +++++++++++++++++++++
  python/qemu/{ => machine}/accel.py          |  0
  python/qemu/{ => machine}/console_socket.py |  0
  python/qemu/{ => machine}/machine.py        | 16 +++++---
  python/qemu/{ => machine}/pylintrc          |  0
  python/qemu/{ => machine}/qtest.py          |  3 +-
  python/qemu/{qmp.py => qmp/__init__.py}     | 12 +++++-
  tests/acceptance/boot_linux.py              |  3 +-
  tests/qemu-iotests/297                      |  2 +-
  tests/qemu-iotests/300                      |  4 +-
  tests/qemu-iotests/iotests.py               |  2 +-
  tests/vm/basevm.py                          |  3 +-
  15 files changed, 71 insertions(+), 26 deletions(-)

rename python/{qemu => }/.isort.cfg (100%) delete mode 100644 python/qemu/__init__.py rename python/qemu/{ => machine}/.flake8 (100%) create mode 100644 python/qemu/machine/__init__.py rename python/qemu/{ => machine}/accel.py (100%) rename python/qemu/{ => machine}/console_socket.py (100%) rename python/qemu/{ => machine}/machine.py (98%) rename python/qemu/{ => machine}/pylintrc (100%) rename python/qemu/{ => machine}/qtest.py (99%) rename python/qemu/{qmp.py => qmp/__init__.py} (96%)

python/.isort.cfg renamed from python/qemu/.isort.cfg +0 -0
similarity index 100%
rename from python/qemu/.isort.cfg
rename to python/.isort.cfg
python/qemu/__init__.py deleted +0 -11
deleted file mode 100644
index 4ca06c34a4..0000000000
@@ -1,11 +0,0 @@
-# QEMU library
-#
-# Copyright (C) 2015-2016 Red Hat Inc.
-# Copyright (C) 2012 IBM Corp.
-#
-# Authors:
-#  Fam Zheng <[email protected]>
-#
-# This work is licensed under the terms of the GNU GPL, version 2.  See
-# the COPYING file in the top-level directory.
-#
python/qemu/machine/.flake8 renamed from python/qemu/.flake8 +0 -0
similarity index 100%
rename from python/qemu/.flake8
rename to python/qemu/machine/.flake8
python/qemu/machine/__init__.py new file +37 -0
new file mode 100644
index 0000000000..27b0b19abd
@@ -0,0 +1,41 @@
+"""
+QEMU development and testing library.
+
+This library provides a few high-level classes for driving QEMU from a
+test suite, not intended for production use.
+
+- QEMUMachine: Configure and Boot a QEMU VM
+ - QEMUQtestMachine: VM class, with a qtest socket.
+
+- QEMUQtestProtocol: Connect to, send/receive qtest messages.
+
+- list_accel: List available accelerators
+- kvm_available: Probe for KVM support
+- tcg_available: Probe for TCG support
+"""
+
+# Copyright (C) 2020 John Snow for Red Hat Inc.
+# Copyright (C) 2015-2016 Red Hat Inc.
+# Copyright (C) 2012 IBM Corp.
+#
+# Authors:
+#  John Snow <[email protected]>
+#  Fam Zheng <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+
+from .accel import kvm_available, list_accel, tcg_available
+from .machine import QEMUMachine
+from .qtest import QEMUQtestMachine, QEMUQtestProtocol
+
+
+__all__ = (
+    'list_accel',
+    'kvm_available',
+    'tcg_available',
Quoted 9 lines

python/qemu/machine/__init__.py line 41

Quoted 4 lines
python/qemu/machine/__init__.py new file +4 -0
+    'QEMUMachine',
+    'QEMUQtestProtocol',
+    'QEMUQtestMachine',
+)

How far would this approach go? I mean, should all future APIs be developed inside module under "qemu/machine", say "qemu/machine/foo.py" and their main functionality imported here? Or do you see this as a temporary state?

I assume any new functionality can be directly imported. Having this here doesn't prevent using the fully qualified module names.

i.e. you can still do "from qemu.machine.machine import QEMUMachine".

Offering root-level aliases seems like a very prevalent paradigm in popular third-party packages like 'requests'. Not justification in and of itself, but there's precedent.

Quoted 3 lines

IMO, this is hard to maintain, and is a very easy path to future inconsistencies.

Maybe. The alternative is to do what I did to QMP and stick it back inside of __init__.

What I don't like is:

from qemu.machine.machine import QEMUMachine

I prefer:

from qemu.machine import QEMUMachine

Of course, I also like help(qemu.machine) to show something useful, which is going to generally involve updating the docstring to explain what the major APIs here are anyway, so I think actually you cannot escape your fate of having to keep a list of APIs updated in a multi-module package.

Maybe you could make an argument that keeping both the docstring and the __all__ attribute in sync is an undue maintenance burden, but I'd need some more convincing.

Quoted 120 lines
Quoted 109 lines
python/qemu/machine/accel.py renamed from python/qemu/accel.py +0 -0
similarity index 100%
rename from python/qemu/accel.py
rename to python/qemu/machine/accel.py
python/qemu/machine/console_socket.py renamed from python/qemu/console_socket.py +0 -0
similarity index 100%
rename from python/qemu/console_socket.py
rename to python/qemu/machine/console_socket.py
python/qemu/machine/machine.py renamed from python/qemu/machine.py +11 -5
similarity index 98%
rename from python/qemu/machine.py
rename to python/qemu/machine/machine.py
index 6420f01bed..a5dc305539 100644
@@ -38,8 +38,14 @@
      Type,
  )
 
-from . import console_socket, qmp
-from .qmp import QMPMessage, QMPReturnValue, SocketAddrT
+from qemu.qmp import (
+    QEMUMonitorProtocol,
+    QMPMessage,
+    QMPReturnValue,
+    SocketAddrT,
+)
+
+from . import console_socket
 
 
  LOG = logging.getLogger(__name__)
@@ -139,7 +145,7 @@ def __init__(self,
          self._events: List[QMPMessage] = []
          self._iolog: Optional[str] = None
          self._qmp_set = True   # Enable QMP monitor by default.
-        self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] = None
+        self._qmp_connection: Optional[QEMUMonitorProtocol] = None
          self._qemu_full_args: Tuple[str, ...] = ()
          self._temp_dir: Optional[str] = None
          self._launched = False
@@ -314,7 +320,7 @@ def _pre_launch(self) -> None:
              if self._remove_monitor_sockfile:
                  assert isinstance(self._monitor_address, str)
                  self._remove_files.append(self._monitor_address)
-            self._qmp_connection = qmp.QEMUMonitorProtocol(
+            self._qmp_connection = QEMUMonitorProtocol(
                  self._monitor_address,
                  server=True,
                  nickname=self._name
@@ -534,7 +540,7 @@ def set_qmp_monitor(self, enabled: bool = True) -> None:
          self._qmp_set = enabled
 
      @property
-    def _qmp(self) -> qmp.QEMUMonitorProtocol:
+    def _qmp(self) -> QEMUMonitorProtocol:
          if self._qmp_connection is None:
              raise QEMUMachineError("Attempt to access QMP with no connection")
          return self._qmp_connection
python/qemu/machine/pylintrc renamed from python/qemu/pylintrc +0 -0
similarity index 100%
rename from python/qemu/pylintrc
rename to python/qemu/machine/pylintrc
python/qemu/machine/qtest.py renamed from python/qemu/qtest.py +2 -1
similarity index 99%
rename from python/qemu/qtest.py
rename to python/qemu/machine/qtest.py
index 39a0cf62fe..53926e434a 100644
@@ -26,8 +26,9 @@
      TextIO,
  )
 
+from qemu.qmp import SocketAddrT
+
  from .machine import QEMUMachine
-from .qmp import SocketAddrT
 
 
  class QEMUQtestProtocol:
python/qemu/qmp/__init__.py renamed from python/qemu/qmp.py +11 -1
similarity index 96%
rename from python/qemu/qmp.py
rename to python/qemu/qmp/__init__.py
index 2cd4d43036..9606248a3d 100644
@@ -1,4 +1,14 @@
-""" QEMU Monitor Protocol Python class """
+"""
+QEMU Monitor Protocol (QMP) development library & tooling.
+
+This package provides a fairly low-level class for communicating to QMP
+protocol servers, as implemented by QEMU, the QEMU Guest Agent, and the
+QEMU Storage Daemon. This library is not intended for production use.
+
+`QEMUMonitorProtocol` is the primary class of interest, and all errors
+raised derive from `QMPError`.
+"""
+
  # Copyright (C) 2009, 2010 Red Hat Inc.
  #
  # Authors:
tests/acceptance/boot_linux.py +0 -0
index 0055dc7cee..54f999e647 100644

tests/acceptance/boot_linux.py line 16

Quoted 7 lines
tests/acceptance/boot_linux.py +1 -2
@@ -12,8 +12,7 @@
 
  from avocado_qemu import Test, BUILD_DIR
 
-from qemu.accel import kvm_available
-from qemu.accel import tcg_available
+from qemu.machine import kvm_available, tcg_available
 

I think this reveals a slight downgrade of the API caused by the usage of the symbols from "qemu.machine" namespace.

Quoted 5 lines

My point is that there are valid use cases for using "kvm_available" without using a "QEMUMachine". This presuposes that "qemu.machine" is named like that because "QEMUMachine" are the main actors of this namespace.

No, the accel functions literally start a QEMU process and probe its output to determine what they support. This belongs directly alongside the machine code in my opinion.

(I also don't know why'd you call these functions unless you intended to create a machine based on what you found.

I see your point that it is not a method of the Machine class itself nor an extension thereof; but I think for the purpose of three small helper functions it's not worth creating an entirely new package to contain.

Nor is it worth watering down the "machine" name to something less specific to accommodate three tiny helper functions.

If I am considering "machine" the "package that knows how to start and interact with QEMU", then accel belongs here.

Quoted 4 lines

Naming is hard, (so don't assume I believe "utils" below is the best or even a good name), but I'd be more confortable using an API along the lines:

Quoted 8 lines

from qemu.utils.accel import kvm_available
kvm_available()

OR

from qemu.utils import accel
accel.kvm_available()

utils/tools I am reserving as a package for various debugging scripts and tools in the future that I don't intend to upload to PyPI, e.g. many of the "thematically loose" scripts in ./scripts.

Quoted 3 lines

This would also remove the need to keep importing symbols into the current "qemu.machine" namespace.

It would, but it's three functions. It doesn't warrant an entire package for a single module with three standalone functions.

That calculus may change in the future if we accumulate lots more miscellaneous thingies to make that more worthwhile!

Quoted 22 lines
Quoted 22 lines
tests/acceptance/boot_linux.py +0 -0
  from avocado.utils import cloudinit
  from avocado.utils import network
tests/qemu-iotests/297 +1 -1
index 5c5420712b..8236875222 100755
@@ -36,7 +36,7 @@ MYPYPATH=../../python/ mypy --warn-unused-configs --disallow-subclassing-any \
      --disallow-any-generics --disallow-incomplete-defs \
      --disallow-untyped-decorators --no-implicit-optional \
      --warn-redundant-casts --warn-unused-ignores \
-    --no-implicit-reexport iotests.py
+    --no-implicit-reexport --namespace-packages iotests.py
 
  # success, all done
  echo "*** done"
tests/qemu-iotests/300 +0 -0
index 5b75121b84..a41fac4e1d 100755
@@ -23,7 +23,7 @@ import random
  import re
  from typing import Dict, List, Optional, Union
Quoted 9 lines

tests/qemu-iotests/300 import random · line 27

Quoted 4 lines
tests/qemu-iotests/300 +1 -1
  import iotests
-import qemu
+from qemu.machine import machine
 

I believe this gives my previous comment some extra strength. I think this shows that "qemu.machine" containing "machine" really means that the first "machine" naming component doesn't really mean that.

Yeah, I don't like the duplication of 'machine' here either. I believe this test needs access to specific error classes which I didn't believe were important enough to receive an alias.

Might be that the correct thing to do is to stick machine.py in machine/__init__.py to avoid that duplication, just like I did with qmp.py.

Quoted 46 lines

"qemu.utils" is not perfect, but it's much more honest IMO.

Cheers,
- Cleber.

Quoted 41 lines
tests/qemu-iotests/300 +1 -1
  BlockBitmapMapping = List[Dict[str, Union[str, List[Dict[str, str]]]]]
 
@@ -454,7 +454,7 @@ class TestBlockBitmapMappingErrors(TestDirtyBitmapMigration):
          # the failed migration
          try:
              self.vm_b.shutdown()
-        except qemu.machine.AbnormalShutdown:
+        except machine.AbnormalShutdown:
              pass
 
      def test_aliased_bitmap_name_too_long(self) -> None:
tests/qemu-iotests/iotests.py +1 -1
index 63d2ace93c..6574afd735 100644
@@ -37,7 +37,7 @@
 
  # pylint: disable=import-error, wrong-import-position
  sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu import qtest
+from qemu.machine import qtest
  from qemu.qmp import QMPMessage
 
  # Use this logger for logging messages directly from the iotests module
tests/vm/basevm.py +1 -2
index 3fac20e929..b38969f61f 100644
@@ -19,8 +19,7 @@
  import time
  import datetime
  sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.accel import kvm_available
-from qemu.machine import QEMUMachine
+from qemu.machine import kvm_available, QEMUMachine
  import subprocess
  import hashlib
  import argparse
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH v3 01/15] python: create qemu packages

Quoted 123 lines · John Snow
Quoted 112 lines · Cleber Rosa
Quoted 111 lines · John Snow

move python/qemu/*.py to python/qemu/[machine, qmp]/*.py and update import directives across the tree.

This is done to create a PEP420 namespace package, in which we may create subpackages. To do this, the namespace directory ("qemu") should not have any modules in it. Those files will go into new 'machine' and 'qmp' subpackages instead.

Implement machine/__init__.py making the top-level classes and functions from its various modules available directly inside the package. Change qmp.py to qmp/__init__.py similarly, such that all of the useful QMP library classes are available directly from "qemu.qmp" instead of "qemu.qmp.qmp".

---
  python/{qemu => }/.isort.cfg                |  0
  python/qemu/__init__.py                     | 11 ------
  python/qemu/{ => machine}/.flake8           |  0
  python/qemu/machine/__init__.py             | 41 +++++++++++++++++++++
  python/qemu/{ => machine}/accel.py          |  0
  python/qemu/{ => machine}/console_socket.py |  0
  python/qemu/{ => machine}/machine.py        | 16 +++++---
  python/qemu/{ => machine}/pylintrc          |  0
  python/qemu/{ => machine}/qtest.py          |  3 +-
  python/qemu/{qmp.py => qmp/__init__.py}     | 12 +++++-
  tests/acceptance/boot_linux.py              |  3 +-
  tests/qemu-iotests/297                      |  2 +-
  tests/qemu-iotests/300                      |  4 +-
  tests/qemu-iotests/iotests.py               |  2 +-
  tests/vm/basevm.py                          |  3 +-
  15 files changed, 71 insertions(+), 26 deletions(-)

rename python/{qemu => }/.isort.cfg (100%) delete mode 100644 python/qemu/__init__.py rename python/qemu/{ => machine}/.flake8 (100%) create mode 100644 python/qemu/machine/__init__.py rename python/qemu/{ => machine}/accel.py (100%) rename python/qemu/{ => machine}/console_socket.py (100%) rename python/qemu/{ => machine}/machine.py (98%) rename python/qemu/{ => machine}/pylintrc (100%) rename python/qemu/{ => machine}/qtest.py (99%) rename python/qemu/{qmp.py => qmp/__init__.py} (96%)

python/.isort.cfg renamed from python/qemu/.isort.cfg +0 -0
similarity index 100%
rename from python/qemu/.isort.cfg
rename to python/.isort.cfg
python/qemu/__init__.py deleted +0 -11
deleted file mode 100644
index 4ca06c34a4..0000000000
@@ -1,11 +0,0 @@
-# QEMU library
-#
-# Copyright (C) 2015-2016 Red Hat Inc.
-# Copyright (C) 2012 IBM Corp.
-#
-# Authors:
-#  Fam Zheng <[email protected]>
-#
-# This work is licensed under the terms of the GNU GPL, version 2.  See
-# the COPYING file in the top-level directory.
-#
python/qemu/machine/.flake8 renamed from python/qemu/.flake8 +0 -0
similarity index 100%
rename from python/qemu/.flake8
rename to python/qemu/machine/.flake8
python/qemu/machine/__init__.py new file +37 -0
new file mode 100644
index 0000000000..27b0b19abd
@@ -0,0 +1,41 @@
+"""
+QEMU development and testing library.
+
+This library provides a few high-level classes for driving QEMU from a
+test suite, not intended for production use.
+
+- QEMUMachine: Configure and Boot a QEMU VM
+ - QEMUQtestMachine: VM class, with a qtest socket.
+
+- QEMUQtestProtocol: Connect to, send/receive qtest messages.
+
+- list_accel: List available accelerators
+- kvm_available: Probe for KVM support
+- tcg_available: Probe for TCG support
+"""
+
+# Copyright (C) 2020 John Snow for Red Hat Inc.
+# Copyright (C) 2015-2016 Red Hat Inc.
+# Copyright (C) 2012 IBM Corp.
+#
+# Authors:
+#  John Snow <[email protected]>
+#  Fam Zheng <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+
+from .accel import kvm_available, list_accel, tcg_available
+from .machine import QEMUMachine
+from .qtest import QEMUQtestMachine, QEMUQtestProtocol
+
+
+__all__ = (
+    'list_accel',
+    'kvm_available',
+    'tcg_available',
Quoted 9 lines

python/qemu/machine/__init__.py line 41

Quoted 4 lines
python/qemu/machine/__init__.py new file +4 -0
+    'QEMUMachine',
+    'QEMUQtestProtocol',
+    'QEMUQtestMachine',
+)

How far would this approach go? I mean, should all future APIs be developed inside module under "qemu/machine", say "qemu/machine/foo.py" and their main functionality imported here? Or do you see this as a temporary state?

Quoted 9 lines

I assume any new functionality can be directly imported. Having this here doesn't prevent using the fully qualified module names.

i.e. you can still do "from qemu.machine.machine import QEMUMachine".

Offering root-level aliases seems like a very prevalent paradigm in popular third-party packages like 'requests'. Not justification in and of itself, but there's precedent.

There's always someone doing something someway... I think the point here is to try to deliver something that makes the most sense to most users of the API. Not an easy task, but it's our task.

Quoted 142 lines
Quoted 3 lines

IMO, this is hard to maintain, and is a very easy path to future inconsistencies.

Maybe. The alternative is to do what I did to QMP and stick it back inside of __init__.

What I don't like is:

from qemu.machine.machine import QEMUMachine

I prefer:

from qemu.machine import QEMUMachine

Of course, I also like help(qemu.machine) to show something useful, which is going to generally involve updating the docstring to explain what the major APIs here are anyway, so I think actually you cannot escape your fate of having to keep a list of APIs updated in a multi-module package.

Maybe you could make an argument that keeping both the docstring and the __all__ attribute in sync is an undue maintenance burden, but I'd need some more convincing.

Quoted 111 lines
Quoted 102 lines
python/qemu/machine/accel.py renamed from python/qemu/accel.py +0 -0
similarity index 100%
rename from python/qemu/accel.py
rename to python/qemu/machine/accel.py
python/qemu/machine/console_socket.py renamed from python/qemu/console_socket.py +0 -0
similarity index 100%
rename from python/qemu/console_socket.py
rename to python/qemu/machine/console_socket.py
python/qemu/machine/machine.py renamed from python/qemu/machine.py +11 -5
similarity index 98%
rename from python/qemu/machine.py
rename to python/qemu/machine/machine.py
index 6420f01bed..a5dc305539 100644
@@ -38,8 +38,14 @@
      Type,
  )
-from . import console_socket, qmp
-from .qmp import QMPMessage, QMPReturnValue, SocketAddrT
+from qemu.qmp import (
+    QEMUMonitorProtocol,
+    QMPMessage,
+    QMPReturnValue,
+    SocketAddrT,
+)
+
+from . import console_socket
  LOG = logging.getLogger(__name__)
@@ -139,7 +145,7 @@ def __init__(self,
          self._events: List[QMPMessage] = []
          self._iolog: Optional[str] = None
          self._qmp_set = True   # Enable QMP monitor by default.
-        self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] = None
+        self._qmp_connection: Optional[QEMUMonitorProtocol] = None
          self._qemu_full_args: Tuple[str, ...] = ()
          self._temp_dir: Optional[str] = None
          self._launched = False
@@ -314,7 +320,7 @@ def _pre_launch(self) -> None:
              if self._remove_monitor_sockfile:
                  assert isinstance(self._monitor_address, str)
                  self._remove_files.append(self._monitor_address)
-            self._qmp_connection = qmp.QEMUMonitorProtocol(
+            self._qmp_connection = QEMUMonitorProtocol(
                  self._monitor_address,
                  server=True,
                  nickname=self._name
@@ -534,7 +540,7 @@ def set_qmp_monitor(self, enabled: bool = True) -> None:
          self._qmp_set = enabled
      @property
-    def _qmp(self) -> qmp.QEMUMonitorProtocol:
+    def _qmp(self) -> QEMUMonitorProtocol:
          if self._qmp_connection is None:
              raise QEMUMachineError("Attempt to access QMP with no connection")
          return self._qmp_connection
python/qemu/machine/pylintrc renamed from python/qemu/pylintrc +0 -0
similarity index 100%
rename from python/qemu/pylintrc
rename to python/qemu/machine/pylintrc
python/qemu/machine/qtest.py renamed from python/qemu/qtest.py +2 -1
similarity index 99%
rename from python/qemu/qtest.py
rename to python/qemu/machine/qtest.py
index 39a0cf62fe..53926e434a 100644
@@ -26,8 +26,9 @@
      TextIO,
  )
+from qemu.qmp import SocketAddrT
+
  from .machine import QEMUMachine
-from .qmp import SocketAddrT
  class QEMUQtestProtocol:
python/qemu/qmp/__init__.py renamed from python/qemu/qmp.py +11 -1
similarity index 96%
rename from python/qemu/qmp.py
rename to python/qemu/qmp/__init__.py
index 2cd4d43036..9606248a3d 100644
@@ -1,4 +1,14 @@
-""" QEMU Monitor Protocol Python class """
+"""
+QEMU Monitor Protocol (QMP) development library & tooling.
+
+This package provides a fairly low-level class for communicating to QMP
+protocol servers, as implemented by QEMU, the QEMU Guest Agent, and the
+QEMU Storage Daemon. This library is not intended for production use.
+
+`QEMUMonitorProtocol` is the primary class of interest, and all errors
+raised derive from `QMPError`.
+"""
+
  # Copyright (C) 2009, 2010 Red Hat Inc.
  #
  # Authors:
tests/acceptance/boot_linux.py +0 -0
index 0055dc7cee..54f999e647 100644

tests/acceptance/boot_linux.py line 14

Quoted 5 lines
tests/acceptance/boot_linux.py +1 -2
@@ -12,8 +12,7 @@
  from avocado_qemu import Test, BUILD_DIR
-from qemu.accel import kvm_available
-from qemu.accel import tcg_available
+from qemu.machine import kvm_available, tcg_available
 

I think this reveals a slight downgrade of the API caused by the usage of the symbols from "qemu.machine" namespace.

Quoted 5 lines

My point is that there are valid use cases for using "kvm_available" without using a "QEMUMachine". This presuposes that "qemu.machine" is named like that because "QEMUMachine" are the main actors of this namespace.

Quoted 4 lines

No, the accel functions literally start a QEMU process and probe its output to determine what they support. This belongs directly alongside the machine code in my opinion.

accel.kvm_available() may not even run QEMU at all... and when it does, it runs it just like your most mundane command line application, "grepping" its stdout.

Quoted 3 lines

(I also don't know why'd you call these functions unless you intended to create a machine based on what you found.

*If* this is an API that you intend others to leverage, you should reverse the question: "Is there any reason for not making this utility available and as obvious and as easily available as possible to be used by people whom I can't actually tell how they'd use it?".

For instance, I may want to write Python code that skips over a number of tests if I detect that KVM is not available. This code of mine, may be completely separate from actual code creating the QEMUMachines, or may even be compiled C code that I don't want to call because I know that KVM is not available.

And that's not hypothetical. I personally have a use case for that.

Quoted 5 lines

I see your point that it is not a method of the Machine class itself nor an extension thereof; but I think for the purpose of three small helper functions it's not worth creating an entirely new package to contain.

Not only that, but it's not even used by QEMUMachine itself.

Quoted 6 lines

Nor is it worth watering down the "machine" name to something less specific to accommodate three tiny helper functions.

If I am considering "machine" the "package that knows how to start and interact with QEMU", then accel belongs here.

That's pretty broad and generic. Do you mean that "machine" should know how to interact with, say, "info qtree"? Would a utility that outputs and parse that deserve to live under "machine"?

Please understand that these are the awkward, speculative and hard questions that we have to ask *if* the intention is to make an API available for general use.

Quoted 9 lines
Quoted 9 lines

Naming is hard, (so don't assume I believe "utils" below is the best or even a good name), but I'd be more confortable using an API along the lines:

from qemu.utils.accel import kvm_available
kvm_available()

OR

Quoted 8 lines
Quoted 3 lines

from qemu.utils import accel
accel.kvm_available()

utils/tools I am reserving as a package for various debugging scripts and tools in the future that I don't intend to upload to PyPI, e.g. many of the "thematically loose" scripts in ./scripts.

The *actual* name, if already "taken in advance", is not the core issue.

Quoted 41 lines
Quoted 3 lines

This would also remove the need to keep importing symbols into the current "qemu.machine" namespace.

It would, but it's three functions. It doesn't warrant an entire package for a single module with three standalone functions.

That calculus may change in the future if we accumulate lots more miscellaneous thingies to make that more worthwhile!

Quoted 21 lines
Quoted 21 lines
tests/acceptance/boot_linux.py +0 -0
  from avocado.utils import cloudinit
  from avocado.utils import network
tests/qemu-iotests/297 +1 -1
index 5c5420712b..8236875222 100755
@@ -36,7 +36,7 @@ MYPYPATH=../../python/ mypy --warn-unused-configs --disallow-subclassing-any \
      --disallow-any-generics --disallow-incomplete-defs \
      --disallow-untyped-decorators --no-implicit-optional \
      --warn-redundant-casts --warn-unused-ignores \
-    --no-implicit-reexport iotests.py
+    --no-implicit-reexport --namespace-packages iotests.py
  # success, all done
  echo "*** done"
tests/qemu-iotests/300 +0 -0
index 5b75121b84..a41fac4e1d 100755
@@ -23,7 +23,7 @@ import random
  import re
  from typing import Dict, List, Optional, Union
Quoted 9 lines

tests/qemu-iotests/300 import random · line 27

Quoted 4 lines
tests/qemu-iotests/300 +1 -1
  import iotests
-import qemu
+from qemu.machine import machine
 

I believe this gives my previous comment some extra strength. I think this shows that "qemu.machine" containing "machine" really means that the first "machine" naming component doesn't really mean that.

Quoted 7 lines

Yeah, I don't like the duplication of 'machine' here either. I believe this test needs access to specific error classes which I didn't believe were important enough to receive an alias.

Might be that the correct thing to do is to stick machine.py in machine/__init__.py to avoid that duplication, just like I did with qmp.py.

I agree this is a better approach wrt *machine.py* itself, from the API perspective.

In a broad sense (excluding qmp) you're proposing that current usage of:

"from qemu import myutility"

Becomes:

"from qemu.machine import myutility"

And "everything" (take it with a grain of salt), will live under "qemu.machine". I still think, as you put it, that the future will show that other modules not connected to "machine", but generally useful, will need a place to live.

This may be an opportunity to *keep* a place where contributors can put generally useful bits. But, if you want to recognize that current "from qemu import myutility" was an unintended naming side effect, and that namespace is really about *machine*, and broaden the meaning of "machine", OK.

Cheers,
- Cleber.

author
#5 lore raw

Re: [PATCH v3 01/15] python: create qemu packages

Quoted 129 lines · Cleber Rosa
Quoted 128 lines · John Snow
Quoted 112 lines · Cleber Rosa
Quoted 111 lines · John Snow

move python/qemu/*.py to python/qemu/[machine, qmp]/*.py and update import directives across the tree.

This is done to create a PEP420 namespace package, in which we may create subpackages. To do this, the namespace directory ("qemu") should not have any modules in it. Those files will go into new 'machine' and 'qmp' subpackages instead.

Implement machine/__init__.py making the top-level classes and functions from its various modules available directly inside the package. Change qmp.py to qmp/__init__.py similarly, such that all of the useful QMP library classes are available directly from "qemu.qmp" instead of "qemu.qmp.qmp".

---
   python/{qemu => }/.isort.cfg                |  0
   python/qemu/__init__.py                     | 11 ------
   python/qemu/{ => machine}/.flake8           |  0
   python/qemu/machine/__init__.py             | 41 +++++++++++++++++++++
   python/qemu/{ => machine}/accel.py          |  0
   python/qemu/{ => machine}/console_socket.py |  0
   python/qemu/{ => machine}/machine.py        | 16 +++++---
   python/qemu/{ => machine}/pylintrc          |  0
   python/qemu/{ => machine}/qtest.py          |  3 +-
   python/qemu/{qmp.py => qmp/__init__.py}     | 12 +++++-
   tests/acceptance/boot_linux.py              |  3 +-
   tests/qemu-iotests/297                      |  2 +-
   tests/qemu-iotests/300                      |  4 +-
   tests/qemu-iotests/iotests.py               |  2 +-
   tests/vm/basevm.py                          |  3 +-
   15 files changed, 71 insertions(+), 26 deletions(-)

rename python/{qemu => }/.isort.cfg (100%) delete mode 100644 python/qemu/__init__.py rename python/qemu/{ => machine}/.flake8 (100%) create mode 100644 python/qemu/machine/__init__.py rename python/qemu/{ => machine}/accel.py (100%) rename python/qemu/{ => machine}/console_socket.py (100%) rename python/qemu/{ => machine}/machine.py (98%) rename python/qemu/{ => machine}/pylintrc (100%) rename python/qemu/{ => machine}/qtest.py (99%) rename python/qemu/{qmp.py => qmp/__init__.py} (96%)

python/.isort.cfg renamed from python/qemu/.isort.cfg +0 -0
similarity index 100%
rename from python/qemu/.isort.cfg
rename to python/.isort.cfg
python/qemu/__init__.py deleted +0 -11
deleted file mode 100644
index 4ca06c34a4..0000000000
@@ -1,11 +0,0 @@
-# QEMU library
-#
-# Copyright (C) 2015-2016 Red Hat Inc.
-# Copyright (C) 2012 IBM Corp.
-#
-# Authors:
-#  Fam Zheng <[email protected]>
-#
-# This work is licensed under the terms of the GNU GPL, version 2.  See
-# the COPYING file in the top-level directory.
-#
python/qemu/machine/.flake8 renamed from python/qemu/.flake8 +0 -0
similarity index 100%
rename from python/qemu/.flake8
rename to python/qemu/machine/.flake8
python/qemu/machine/__init__.py new file +37 -0
new file mode 100644
index 0000000000..27b0b19abd
@@ -0,0 +1,41 @@
+"""
+QEMU development and testing library.
+
+This library provides a few high-level classes for driving QEMU from a
+test suite, not intended for production use.
+
+- QEMUMachine: Configure and Boot a QEMU VM
+ - QEMUQtestMachine: VM class, with a qtest socket.
+
+- QEMUQtestProtocol: Connect to, send/receive qtest messages.
+
+- list_accel: List available accelerators
+- kvm_available: Probe for KVM support
+- tcg_available: Probe for TCG support
+"""
+
+# Copyright (C) 2020 John Snow for Red Hat Inc.
+# Copyright (C) 2015-2016 Red Hat Inc.
+# Copyright (C) 2012 IBM Corp.
+#
+# Authors:
+#  John Snow <[email protected]>
+#  Fam Zheng <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+
+from .accel import kvm_available, list_accel, tcg_available
+from .machine import QEMUMachine
+from .qtest import QEMUQtestMachine, QEMUQtestProtocol
+
+
+__all__ = (
+    'list_accel',
+    'kvm_available',
+    'tcg_available',
Quoted 9 lines

python/qemu/machine/__init__.py line 41

Quoted 4 lines
python/qemu/machine/__init__.py new file +4 -0
+    'QEMUMachine',
+    'QEMUQtestProtocol',
+    'QEMUQtestMachine',
+)

How far would this approach go? I mean, should all future APIs be developed inside module under "qemu/machine", say "qemu/machine/foo.py" and their main functionality imported here? Or do you see this as a temporary state?

I assume any new functionality can be directly imported. Having this here doesn't prevent using the fully qualified module names.

i.e. you can still do "from qemu.machine.machine import QEMUMachine".

Quoted 9 lines
Quoted 4 lines

Offering root-level aliases seems like a very prevalent paradigm in popular third-party packages like 'requests'. Not justification in and of itself, but there's precedent.

There's always someone doing something someway... I think the point here is to try to deliver something that makes the most sense to most users of the API. Not an easy task, but it's our task.

Just gotta follow the patterns I see in prominent examples that are often held up as good citizens. In my experience, commonly used aliases for the purposes of ease-of-use is a common pattern.

I don't think this *hurts* anything, but I suppose there's deeper questions about what we want the imports to look like. OK, but I think this discussion about the use of __all__ winds up being unrelated to the actual matter at hand.

Quoted 160 lines
Quoted 142 lines
Quoted 3 lines

IMO, this is hard to maintain, and is a very easy path to future inconsistencies.

Maybe. The alternative is to do what I did to QMP and stick it back inside of __init__.

What I don't like is:

from qemu.machine.machine import QEMUMachine

I prefer:

from qemu.machine import QEMUMachine

Of course, I also like help(qemu.machine) to show something useful, which is going to generally involve updating the docstring to explain what the major APIs here are anyway, so I think actually you cannot escape your fate of having to keep a list of APIs updated in a multi-module package.

Maybe you could make an argument that keeping both the docstring and the __all__ attribute in sync is an undue maintenance burden, but I'd need some more convincing.

Quoted 111 lines
Quoted 102 lines
python/qemu/machine/accel.py renamed from python/qemu/accel.py +0 -0
similarity index 100%
rename from python/qemu/accel.py
rename to python/qemu/machine/accel.py
python/qemu/machine/console_socket.py renamed from python/qemu/console_socket.py +0 -0
similarity index 100%
rename from python/qemu/console_socket.py
rename to python/qemu/machine/console_socket.py
python/qemu/machine/machine.py renamed from python/qemu/machine.py +11 -5
similarity index 98%
rename from python/qemu/machine.py
rename to python/qemu/machine/machine.py
index 6420f01bed..a5dc305539 100644
@@ -38,8 +38,14 @@
       Type,
   )
-from . import console_socket, qmp
-from .qmp import QMPMessage, QMPReturnValue, SocketAddrT
+from qemu.qmp import (
+    QEMUMonitorProtocol,
+    QMPMessage,
+    QMPReturnValue,
+    SocketAddrT,
+)
+
+from . import console_socket
   LOG = logging.getLogger(__name__)
@@ -139,7 +145,7 @@ def __init__(self,
           self._events: List[QMPMessage] = []
           self._iolog: Optional[str] = None
           self._qmp_set = True   # Enable QMP monitor by default.
-        self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] = None
+        self._qmp_connection: Optional[QEMUMonitorProtocol] = None
           self._qemu_full_args: Tuple[str, ...] = ()
           self._temp_dir: Optional[str] = None
           self._launched = False
@@ -314,7 +320,7 @@ def _pre_launch(self) -> None:
               if self._remove_monitor_sockfile:
                   assert isinstance(self._monitor_address, str)
                   self._remove_files.append(self._monitor_address)
-            self._qmp_connection = qmp.QEMUMonitorProtocol(
+            self._qmp_connection = QEMUMonitorProtocol(
                   self._monitor_address,
                   server=True,
                   nickname=self._name
@@ -534,7 +540,7 @@ def set_qmp_monitor(self, enabled: bool = True) -> None:
           self._qmp_set = enabled
       @property
-    def _qmp(self) -> qmp.QEMUMonitorProtocol:
+    def _qmp(self) -> QEMUMonitorProtocol:
           if self._qmp_connection is None:
               raise QEMUMachineError("Attempt to access QMP with no connection")
           return self._qmp_connection
python/qemu/machine/pylintrc renamed from python/qemu/pylintrc +0 -0
similarity index 100%
rename from python/qemu/pylintrc
rename to python/qemu/machine/pylintrc
python/qemu/machine/qtest.py renamed from python/qemu/qtest.py +2 -1
similarity index 99%
rename from python/qemu/qtest.py
rename to python/qemu/machine/qtest.py
index 39a0cf62fe..53926e434a 100644
@@ -26,8 +26,9 @@
       TextIO,
   )
+from qemu.qmp import SocketAddrT
+
   from .machine import QEMUMachine
-from .qmp import SocketAddrT
   class QEMUQtestProtocol:
python/qemu/qmp/__init__.py renamed from python/qemu/qmp.py +11 -1
similarity index 96%
rename from python/qemu/qmp.py
rename to python/qemu/qmp/__init__.py
index 2cd4d43036..9606248a3d 100644
@@ -1,4 +1,14 @@
-""" QEMU Monitor Protocol Python class """
+"""
+QEMU Monitor Protocol (QMP) development library & tooling.
+
+This package provides a fairly low-level class for communicating to QMP
+protocol servers, as implemented by QEMU, the QEMU Guest Agent, and the
+QEMU Storage Daemon. This library is not intended for production use.
+
+`QEMUMonitorProtocol` is the primary class of interest, and all errors
+raised derive from `QMPError`.
+"""
+
   # Copyright (C) 2009, 2010 Red Hat Inc.
   #
   # Authors:
tests/acceptance/boot_linux.py +0 -0
index 0055dc7cee..54f999e647 100644

tests/acceptance/boot_linux.py line 14

Quoted 5 lines
tests/acceptance/boot_linux.py +1 -2
@@ -12,8 +12,7 @@
   from avocado_qemu import Test, BUILD_DIR
-from qemu.accel import kvm_available
-from qemu.accel import tcg_available
+from qemu.machine import kvm_available, tcg_available
 

I think this reveals a slight downgrade of the API caused by the usage of the symbols from "qemu.machine" namespace.

Quoted 5 lines

My point is that there are valid use cases for using "kvm_available" without using a "QEMUMachine". This presuposes that "qemu.machine" is named like that because "QEMUMachine" are the main actors of this namespace.

Quoted 4 lines

No, the accel functions literally start a QEMU process and probe its output to determine what they support. This belongs directly alongside the machine code in my opinion.

accel.kvm_available() may not even run QEMU at all... and when it does, it runs it just like your most mundane command line application, "grepping" its stdout.

Quoted 3 lines

(I also don't know why'd you call these functions unless you intended to create a machine based on what you found.

*If* this is an API that you intend others to leverage, you should reverse the question: "Is there any reason for not making this utility available and as obvious and as easily available as possible to be used by people whom I can't actually tell how they'd use it?".

Quoted 8 lines

For instance, I may want to write Python code that skips over a number of tests if I detect that KVM is not available. This code of mine, may be completely separate from actual code creating the QEMUMachines, or may even be compiled C code that I don't want to call because I know that KVM is not available.

And that's not hypothetical. I personally have a use case for that.

All of the usages in tests/acceptance pass a binary in. The vm/ tests are the ones that don't.

With tcg_available necessitating providing a binary, it's weird that kvm_available has an overloaded invocation where it avoids doing so. The generic detection for host KVM support likely ought to be in a different function.

(And that one, you are right, would have only the most tenuous relationship to a qemu.machine package.)

Quoted 8 lines
Quoted 5 lines

I see your point that it is not a method of the Machine class itself nor an extension thereof; but I think for the purpose of three small helper functions it's not worth creating an entirely new package to contain.

Not only that, but it's not even used by QEMUMachine itself.

But it's not wholly unrelated: I maintain the most obvious use for these is to probe a binary and adjust flags accordingly. I would go so far as to say that shipping qemu.machine without such a feature would create a deficit in that package!

Quoted 11 lines
Quoted 6 lines

Nor is it worth watering down the "machine" name to something less specific to accommodate three tiny helper functions.

If I am considering "machine" the "package that knows how to start and interact with QEMU", then accel belongs here.

That's pretty broad and generic. Do you mean that "machine" should know how to interact with, say, "info qtree"? Would a utility that outputs and parse that deserve to live under "machine"?

It is broad and generic. I am arguing explicitly against creating an entire package to house a single module which contains three utility functions. What I am really pressing on you to answer is: "What are they utility functions *for*?"

Answering that might give us good names. Without names, I can't respin the patches to your liking. :)

But, yes, that means I am considering "machine" as something very broad and generic. I believe that's correct until such time as we have justification to create something more targeted and focused. If you have a better name I'm open to it, but I did intent to intuit that the primary purpose of this package was to provide QEMUMachine and friends, because it is.

That's also why I have adopted Andrea's suggestion to start with a 0.x version: I am treating this domain as an incubation space, and not stable APIs -- precisely because this type of argument is not one I am sure needed to be solved up front. We can graduate packages out of this incubator.

What I had initially:

qemu.core, containing *everything*

What I have now:

qemu.qmp - QMP library and tools that rely on the QMP library
qemu.machine - machine.py, console_socket.py, qtest.py, accel helpers

What you want, I believe:

qemu.qmp - QMP library and misc QMP-using tools
qemu.machine - machine.py, console_socket.py, qtest.py
qemu.util - accel helpers

What I'm protesting against is creating a "utilities" package at all, because with no central thesis to its existence, I do not know how to version or maintain such a package.

It's my belief that keeping the subpackages tightly focused (qmp, machine) it will help guide what kind of API we want to develop for each.

Making a "util" package to house random bits and pieces seems like the sort of thing that will be very hard to maintain in a meaningful way; and it's something I'd like to avoid supporting for external usage.

Quoted 4 lines

Please understand that these are the awkward, speculative and hard questions that we have to ask *if* the intention is to make an API available for general use.

I did invite bikeshedding! Now's the time to do it, if ever there was one.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Naming is hard, (so don't assume I believe "utils" below is the best or even a good name), but I'd be more confortable using an API along the lines:

from qemu.utils.accel import kvm_available
kvm_available()

OR

from qemu.utils import accel
accel.kvm_available()

Quoted 7 lines
Quoted 4 lines

utils/tools I am reserving as a package for various debugging scripts and tools in the future that I don't intend to upload to PyPI, e.g. many of the "thematically loose" scripts in ./scripts.

The *actual* name, if already "taken in advance", is not the core issue.

Didn't mean to imply the name was an issue, it was the semantics. I do intend to create a type of "misc" subpackage, but it's one I won't support; functionally it's something for internal dev usage on the QEMU tree was my intent.

If you want accel functions to be supported and available outside the QEMU source tree, I am saying that I don't want to support a "util" package to do that.

Quoted 56 lines
Quoted 41 lines
Quoted 3 lines

This would also remove the need to keep importing symbols into the current "qemu.machine" namespace.

It would, but it's three functions. It doesn't warrant an entire package for a single module with three standalone functions.

That calculus may change in the future if we accumulate lots more miscellaneous thingies to make that more worthwhile!

Quoted 21 lines
Quoted 21 lines
tests/acceptance/boot_linux.py +0 -0
   from avocado.utils import cloudinit
   from avocado.utils import network
tests/qemu-iotests/297 +1 -1
index 5c5420712b..8236875222 100755
@@ -36,7 +36,7 @@ MYPYPATH=../../python/ mypy --warn-unused-configs --disallow-subclassing-any \
       --disallow-any-generics --disallow-incomplete-defs \
       --disallow-untyped-decorators --no-implicit-optional \
       --warn-redundant-casts --warn-unused-ignores \
-    --no-implicit-reexport iotests.py
+    --no-implicit-reexport --namespace-packages iotests.py
   # success, all done
   echo "*** done"
tests/qemu-iotests/300 +0 -0
index 5b75121b84..a41fac4e1d 100755
@@ -23,7 +23,7 @@ import random
   import re
   from typing import Dict, List, Optional, Union
Quoted 9 lines

tests/qemu-iotests/300 import random · line 27

Quoted 4 lines
tests/qemu-iotests/300 +1 -1
   import iotests
-import qemu
+from qemu.machine import machine
 

I believe this gives my previous comment some extra strength. I think this shows that "qemu.machine" containing "machine" really means that the first "machine" naming component doesn't really mean that.

Quoted 7 lines

Yeah, I don't like the duplication of 'machine' here either. I believe this test needs access to specific error classes which I didn't believe were important enough to receive an alias.

Might be that the correct thing to do is to stick machine.py in machine/__init__.py to avoid that duplication, just like I did with qmp.py.

I agree this is a better approach wrt *machine.py* itself, from the API perspective.

In a broad sense (excluding qmp) you're proposing that current usage of:

"from qemu import myutility"

Quoted 9 lines

Becomes:

"from qemu.machine import myutility"

And "everything" (take it with a grain of salt), will live under "qemu.machine". I still think, as you put it, that the future will show that other modules not connected to "machine", but generally useful, will need a place to live.

I mean, the only things we *have* that aren't directly connected to Machine are these three accel functions, and even those launch QEMU binaries to probe them for features for the purpose of .. passing flags to QEMUMachine.

Quoted 6 lines

This may be an opportunity to *keep* a place where contributors can put generally useful bits. But, if you want to recognize that current "from qemu import myutility" was an unintended naming side effect, and that namespace is really about *machine*, and broaden the meaning of "machine", OK.

You're right, it is the "removal" of a place where we can put random bits and pieces. That's a conscious decision, yes.

We can create that space (and I intend to, as intuited above), but in so doing I also intend to preclude it from any kind of API stability guarantees, visibility in our sphinx manuals, that sort of thing. I think you actually do want to keep using accel and want to support people using it, so it needs a place to live.

Reintroduction of a "core" package that we intend to support externally could work; but without a strong idea of what will go in there, I'd rather not make one pre-emptively.

I guess put another way:

I'd prefer accel helpers to be in the machine package, since they provide an obvious utility for helping to launch machines (though they may provide additional utility in further contexts), instead of creating a completely un-themed miscellaneous package to house just a few things, especially for callers who are *almost guaranteed* to be using the other subpackages already.

Quoted 3 lines

Cheers,
- Cleber.

All that said, I'm not truly married to the exact names I chose. Feel free to recommend some, but this is the best I could come up with. I think "qemu.machine" in particular could have a better name, but what to name it? I don't know.

--js

author
#6 lore raw

PATCH v3 2/15 python: add qemu package installer

In reply to John Snow

Add setup.cfg and setup.py, necessary for installing a package via pip. Add a rst document explaining the basics of what this package is for and who to contact for more information. This document will be used as the landing page for the package on PyPI.

I am not yet using a pyproject.toml style package manifest, because using pyproject.toml (and PEP-517) style packages means that pip is not able to install in "editable" or "develop" mode, which I consider necessary for the development of this package.

Use a light-weight setup.py instead.

---
 python/PACKAGE.rst | 26 ++++++++++++++++++++++++++
 python/setup.cfg   | 18 ++++++++++++++++++
 python/setup.py    | 23 +++++++++++++++++++++++
 3 files changed, 67 insertions(+)
 create mode 100644 python/PACKAGE.rst
 create mode 100755 python/setup.cfg
 create mode 100755 python/setup.py
python/PACKAGE.rst new file +26 -0
new file mode 100644
index 0000000000..b82f32f489
@@ -0,0 +1,26 @@
+QEMU Python Tooling
+===================
+
+This package provides QEMU tooling used by the QEMU project to build,
+configure, and test QEMU. It is not a fully-fledged SDK and it is subject
+to change at any time.
+
+Usage
+-----
+
+The ``qemu.qmp`` subpackage provides a library for communicating with
+QMP servers. The ``qemu.machine`` subpackage offers rudimentary
+facilities for launching and managing QEMU processes. Refer to each
+pacakge's documentation
+(``>>> help(qemu.qmp)``, ``>>> help(qemu.machine)``)
+for more information.
+
+Contributing
+------------
+
+This package is maintained by John Snow <[email protected]> as part of
+the QEMU source tree. Contributions are welcome and follow the `QEMU
+patch submission process
+<https://wiki.qemu.org/Contribute/SubmitAPatch>`_. There is a `Gitlab
+mirror <https://gitlab.com/jsnow/qemu/-/tree/python>`_, but
+contributions must be sent to the list for inclusion.
python/setup.cfg new file +18 -0
new file mode 100755
index 0000000000..12b99a796e
@@ -0,0 +1,18 @@
+[metadata]
+name = qemu
+maintainer = QEMU Developer Team
+maintainer_email = [email protected]
+url = https://www.qemu.org/
+download_url = https://www.qemu.org/download/
+description = QEMU Python Build, Debug and SDK tooling.
+long_description = file:PACKAGE.rst
+long_description_content_type = text/x-rst
+classifiers =
+    Development Status :: 3 - Alpha
+    License :: OSI Approved :: GNU General Public License v2 (GPLv2)
+    Natural Language :: English
+    Operating System :: OS Independent
+
+[options]
+python_requires = >= 3.6
+packages = find_namespace:
python/setup.py new file +23 -0
new file mode 100755
index 0000000000..e93d0075d1
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+"""
+QEMU tooling installer script
+Copyright (c) 2020 John Snow for Red Hat, Inc.
+"""
+
+import setuptools
+import pkg_resources
+
+
+def main():
+    """
+    QEMU tooling installer
+    """
+
+    # https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108
+    pkg_resources.require('setuptools>=39.2')
+
+    setuptools.setup()
+
+
+if __name__ == '__main__':
+    main()
Signature · 1 line
2.26.2
#7 lore raw

Re: [PATCH v3 02/15] python: add qemu package installer

Quoted 32 lines · John Snow

Add setup.cfg and setup.py, necessary for installing a package via pip. Add a rst document explaining the basics of what this package is for and who to contact for more information. This document will be used as the landing page for the package on PyPI.

I am not yet using a pyproject.toml style package manifest, because using pyproject.toml (and PEP-517) style packages means that pip is not able to install in "editable" or "develop" mode, which I consider necessary for the development of this package.

Use a light-weight setup.py instead.

---
 python/PACKAGE.rst | 26 ++++++++++++++++++++++++++
 python/setup.cfg   | 18 ++++++++++++++++++
 python/setup.py    | 23 +++++++++++++++++++++++
 3 files changed, 67 insertions(+)
 create mode 100644 python/PACKAGE.rst
 create mode 100755 python/setup.cfg
 create mode 100755 python/setup.py
python/PACKAGE.rst new file +4 -0
new file mode 100644
index 0000000000..b82f32f489
@@ -0,0 +1,26 @@
+QEMU Python Tooling
+===================
+
+This package provides QEMU tooling used by the QEMU project to build,

python/PACKAGE.rst line 14

Quoted 10 lines
python/PACKAGE.rst new file +10 -0
+configure, and test QEMU. It is not a fully-fledged SDK and it is subject
+to change at any time.
+
+Usage
+-----
+
+The ``qemu.qmp`` subpackage provides a library for communicating with
+QMP servers. The ``qemu.machine`` subpackage offers rudimentary
+facilities for launching and managing QEMU processes. Refer to each
+pacakge's documentation

Typo here: s/pacakge/package/

python/PACKAGE.rst line 24

Quoted 10 lines
python/PACKAGE.rst new file +10 -0
+(``>>> help(qemu.qmp)``, ``>>> help(qemu.machine)``)
+for more information.
+
+Contributing
+------------
+
+This package is maintained by John Snow <[email protected]> as part of
+the QEMU source tree. Contributions are welcome and follow the `QEMU
+patch submission process
+<https://wiki.qemu.org/Contribute/SubmitAPatch>`_. There is a `Gitlab

Git*L*ab. Given that we're also under a company named with two words, better given them that :)

python/PACKAGE.rst line 26

Quoted 2 lines
python/PACKAGE.rst new file +2 -0
+mirror <https://gitlab.com/jsnow/qemu/-/tree/python>`_, but
+contributions must be sent to the list for inclusion.

IMO it's not clear if this branch/mirror is your development work, a staging area, etc.

Quoted 11 lines
python/setup.cfg new file +5 -0
new file mode 100755
index 0000000000..12b99a796e
@@ -0,0 +1,18 @@
+[metadata]
+name = qemu
+maintainer = QEMU Developer Team
+maintainer_email = [email protected]
+url = https://www.qemu.org/

python/setup.cfg line 15

Quoted 10 lines
python/setup.cfg new file +10 -0
+download_url = https://www.qemu.org/download/
+description = QEMU Python Build, Debug and SDK tooling.
+long_description = file:PACKAGE.rst
+long_description_content_type = text/x-rst
+classifiers =
+    Development Status :: 3 - Alpha
+    License :: OSI Approved :: GNU General Public License v2 (GPLv2)
+    Natural Language :: English
+    Operating System :: OS Independent
+

I know the sky is the limit, but I miss the Python version classifier, at least:

Programming Language :: Python :: 3 :: Only

And optionally those:

Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9

Although it may be a good idea to add them along test jobs on those specific Python versions.

Quoted 16 lines
python/setup.cfg new file +3 -0
+[options]
+python_requires = >= 3.6
+packages = find_namespace:
python/setup.py new file +7 -0
new file mode 100755
index 0000000000..e93d0075d1
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+"""
+QEMU tooling installer script
+Copyright (c) 2020 John Snow for Red Hat, Inc.
+"""
+
+import setuptools

python/setup.py line 17

Quoted 10 lines
python/setup.py new file +10 -0
+import pkg_resources
+
+
+def main():
+    """
+    QEMU tooling installer
+    """
+
+    # https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108
+    pkg_resources.require('setuptools>=39.2')

Getting back to the "test jobs on those specific Python versions" I was really anxious that environments with Python 3.6 will fail to have such a "recent" setuptools version.

CentOS 8 has that specific version, while Ubuntu 18.04 has version 39.0. Ubuntu 20.04 has a recent enough version though. Given that all GitLab CI moved to 20.04, this should be safe.

- Cleber.

Quoted 9 lines
python/setup.py new file +6 -0
+
+    setuptools.setup()
+
+
+if __name__ == '__main__':
+    main()
Signature · 1 line
2.26.2
author
#8 lore raw

Re: [PATCH v3 02/15] python: add qemu package installer

Quoted 37 lines · Cleber Rosa
Quoted 36 lines · John Snow

Add setup.cfg and setup.py, necessary for installing a package via pip. Add a rst document explaining the basics of what this package is for and who to contact for more information. This document will be used as the landing page for the package on PyPI.

I am not yet using a pyproject.toml style package manifest, because using pyproject.toml (and PEP-517) style packages means that pip is not able to install in "editable" or "develop" mode, which I consider necessary for the development of this package.

Use a light-weight setup.py instead.

---
  python/PACKAGE.rst | 26 ++++++++++++++++++++++++++
  python/setup.cfg   | 18 ++++++++++++++++++
  python/setup.py    | 23 +++++++++++++++++++++++
  3 files changed, 67 insertions(+)

create mode 100644 python/PACKAGE.rst
create mode 100755 python/setup.cfg
create mode 100755 python/setup.py

python/PACKAGE.rst new file +8 -0
new file mode 100644
index 0000000000..b82f32f489
@@ -0,0 +1,26 @@
+QEMU Python Tooling
+===================
+
+This package provides QEMU tooling used by the QEMU project to build,
+configure, and test QEMU. It is not a fully-fledged SDK and it is subject
+to change at any time.
+
+Usage
Quoted 9 lines

python/PACKAGE.rst line 14

Quoted 6 lines
python/PACKAGE.rst new file +6 -0
+-----
+
+The ``qemu.qmp`` subpackage provides a library for communicating with
+QMP servers. The ``qemu.machine`` subpackage offers rudimentary
+facilities for launching and managing QEMU processes. Refer to each
+pacakge's documentation

Typo here: s/pacakge/package/

oops,

Quoted 5 lines
Quoted 5 lines
python/PACKAGE.rst new file +5 -0
+(``>>> help(qemu.qmp)``, ``>>> help(qemu.machine)``)
+for more information.
+
+Contributing
+------------
Quoted 9 lines

python/PACKAGE.rst line 24

Quoted 5 lines
python/PACKAGE.rst new file +5 -0
+
+This package is maintained by John Snow <[email protected]> as part of
+the QEMU source tree. Contributions are welcome and follow the `QEMU
+patch submission process
+<https://wiki.qemu.org/Contribute/SubmitAPatch>`_. There is a `Gitlab

Git*L*ab. Given that we're also under a company named with two words, better given them that :)

They can send me a paycheck if they want me to adhere to their brand standards!

(But, OK.)

Quoted 6 lines

python/PACKAGE.rst line 26

Quoted 2 lines
python/PACKAGE.rst new file +2 -0
+mirror <https://gitlab.com/jsnow/qemu/-/tree/python>`_, but
+contributions must be sent to the list for inclusion.

IMO it's not clear if this branch/mirror is your development work, a staging area, etc.

Fair enough. jsnow/qemu/python is intended as a staging area for patches that have been vetted on-list.

jsnow/qemu/master is a lazily-updated mirror. (I tend to update it every day as part of my development process, but there are days I don't write code.)

jsnow/qemu/python-* is development work; review branches, etc.

I'll try to rephrase this a bit. What I want to communicate:

- This package exists as a subfolder of a larger project
- I am responsible for maintaining this package, but not for the larger project
- Please contact *me* for problems with this package
- Contributions should go through qemu-devel (I will gently redirect contributors who may send pull requests to the qemu devel list.)

Quoted 13 lines
Quoted 13 lines
python/setup.cfg new file +7 -0
new file mode 100755
index 0000000000..12b99a796e
@@ -0,0 +1,18 @@
+[metadata]
+name = qemu
+maintainer = QEMU Developer Team
+maintainer_email = [email protected]
+url = https://www.qemu.org/
+download_url = https://www.qemu.org/download/
+description = QEMU Python Build, Debug and SDK tooling.
Quoted 9 lines

python/setup.cfg line 15

Quoted 8 lines
python/setup.cfg new file +8 -0
+long_description = file:PACKAGE.rst
+long_description_content_type = text/x-rst
+classifiers =
+    Development Status :: 3 - Alpha
+    License :: OSI Approved :: GNU General Public License v2 (GPLv2)
+    Natural Language :: English
+    Operating System :: OS Independent
+

Also ... licensing question, do we need *L*GPLv2, or does Python not have a "linking exception" problem?

I guess we can't really re-license these files anyway, so nevermind.

(I immediately regret asking this.)

Quoted 5 lines

I know the sky is the limit, but I miss the Python version classifier, at least:

Programming Language :: Python :: 3 :: Only

Sure.

Wait, why can you specify Python as a language? Is it possible to have non-Python packages on PyPI?

*CONCERNED*

Quoted 10 lines

And optionally those:

Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9

Although it may be a good idea to add them along test jobs on those specific Python versions.

Are these worth adding? I've got python_requires >= 3.6 down below. From my test of a blank package upload to PyPI, it seems to display prominently:

https://pypi.org/project/qemu/

Is there a tangible benefit that you are aware of?

Quoted 22 lines
Quoted 22 lines
python/setup.cfg new file +3 -0
+[options]
+python_requires = >= 3.6
+packages = find_namespace:
python/setup.py new file +13 -0
new file mode 100755
index 0000000000..e93d0075d1
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+"""
+QEMU tooling installer script
+Copyright (c) 2020 John Snow for Red Hat, Inc.
+"""
+
+import setuptools
+import pkg_resources
+
+
+def main():
+    """
+    QEMU tooling installer
Quoted 9 lines

python/setup.py line 17

Quoted 4 lines
python/setup.py new file +4 -0
+    """
+
+    # https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108
+    pkg_resources.require('setuptools>=39.2')

Getting back to the "test jobs on those specific Python versions" I was really anxious that environments with Python 3.6 will fail to have such a "recent" setuptools version.

Reasonable doubt. However, this isn't *required* to use the library (the QEMU code can continue to just set PYTHONPATH or sys.path as necessary) and bypasses the installer entirely.

That gives us some leeway apart from the usual version constraints; in order to independently use this library outside of the QEMU tree we may impose more modern setups -- as long as the minimum requirements for QEMU itself don't break.

Having a modern setuptools in order to install seems like less of a problem barrier; and it seemed like a good idea to make it explicitly fail instead of silently doing something weird if it didn't see/understand setup.cfg.

(And it seems like good practice to update pip in your venv, so I think we'll be OK except for the stodgiest of users, but sometimes you can't have new things on old systems without learning some new tricks!)

Quoted 6 lines

CentOS 8 has that specific version, while Ubuntu 18.04 has version 39.0. Ubuntu 20.04 has a recent enough version though. Given that all GitLab CI moved to 20.04, this should be safe.

- Cleber.

FWIW, for the purposes of running the linters, I am using Fedora32 and the python36 package.

Quoted 9 lines
Quoted 9 lines
python/setup.py new file +6 -0
+
+    setuptools.setup()
+
+
+if __name__ == '__main__':
+    main()
Signature · 1 line
2.26.2
#9 lore raw

Re: [PATCH v3 02/15] python: add qemu package installer

Quoted 16 lines · John Snow
Quoted 6 lines · Cleber Rosa

python/PACKAGE.rst line 26

Quoted 2 lines
python/PACKAGE.rst new file +2 -0
+mirror <https://gitlab.com/jsnow/qemu/-/tree/python>`_, but
+contributions must be sent to the list for inclusion.

IMO it's not clear if this branch/mirror is your development work, a staging area, etc.

Fair enough. jsnow/qemu/python is intended as a staging area for patches that have been vetted on-list.

jsnow/qemu/master is a lazily-updated mirror. (I tend to update it every day as part of my development process, but there are days I don't write code.)

jsnow/qemu/python-* is development work; review branches, etc.

Quoted 9 lines

I'll try to rephrase this a bit. What I want to communicate:

- This package exists as a subfolder of a larger project
- I am responsible for maintaining this package, but not for the larger project
- Please contact *me* for problems with this package
- Contributions should go through qemu-devel (I will gently redirect contributors who may send pull requests to the qemu devel list.)

OK, sounds good. I'll look at the exact rewording on v+1.

Quoted 23 lines
Quoted 13 lines
Quoted 13 lines
python/setup.cfg new file +7 -0
new file mode 100755
index 0000000000..12b99a796e
@@ -0,0 +1,18 @@
+[metadata]
+name = qemu
+maintainer = QEMU Developer Team
+maintainer_email = [email protected]
+url = https://www.qemu.org/
+download_url = https://www.qemu.org/download/
+description = QEMU Python Build, Debug and SDK tooling.
Quoted 9 lines

python/setup.cfg line 15

Quoted 8 lines
python/setup.cfg new file +8 -0
+long_description = file:PACKAGE.rst
+long_description_content_type = text/x-rst
+classifiers =
+    Development Status :: 3 - Alpha
+    License :: OSI Approved :: GNU General Public License v2 (GPLv2)
+    Natural Language :: English
+    Operating System :: OS Independent
+
Quoted 7 lines

Also ... licensing question, do we need *L*GPLv2, or does Python not have a "linking exception" problem?

I guess we can't really re-license these files anyway, so nevermind.

(I immediately regret asking this.)

I'll just pretend you never did.

Quoted 6 lines
Quoted 5 lines

I know the sky is the limit, but I miss the Python version classifier, at least:

Programming Language :: Python :: 3 :: Only

Quoted 7 lines

Sure.

Wait, why can you specify Python as a language? Is it possible to have non-Python packages on PyPI?

*CONCERNED*

I guess it has to do with packages that can interact or serve other languages. Or, that are (partially) written in another language?

Quoted 11 lines
Quoted 10 lines

And optionally those:

Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9

Although it may be a good idea to add them along test jobs on those specific Python versions.

Quoted 7 lines

Are these worth adding? I've got python_requires >= 3.6 down below. From my test of a blank package upload to PyPI, it seems to display prominently:

https://pypi.org/project/qemu/

Is there a tangible benefit that you are aware of?

AFAICT, the classifiers are about letting people search for packages that match a given criteria. It's all metadata, so the benefits are not super tangible. I've used those to keep track / document the Python versions that I know the project has been actively tested on, and that's the reason of my comment about (CI) test jobs.

Quoted 32 lines
Quoted 22 lines
Quoted 22 lines
python/setup.cfg new file +3 -0
+[options]
+python_requires = >= 3.6
+packages = find_namespace:
python/setup.py new file +13 -0
new file mode 100755
index 0000000000..e93d0075d1
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+"""
+QEMU tooling installer script
+Copyright (c) 2020 John Snow for Red Hat, Inc.
+"""
+
+import setuptools
+import pkg_resources
+
+
+def main():
+    """
+    QEMU tooling installer
Quoted 9 lines

python/setup.py line 17

Quoted 4 lines
python/setup.py new file +4 -0
+    """
+
+    # https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108
+    pkg_resources.require('setuptools>=39.2')

Getting back to the "test jobs on those specific Python versions" I was really anxious that environments with Python 3.6 will fail to have such a "recent" setuptools version.

Quoted 4 lines

Reasonable doubt. However, this isn't *required* to use the library (the QEMU code can continue to just set PYTHONPATH or sys.path as necessary) and bypasses the installer entirely.

Right, but I had the impression that activating it in develop mode (at least) was the intention down the line.

Quoted 5 lines

That gives us some leeway apart from the usual version constraints; in order to independently use this library outside of the QEMU tree we may impose more modern setups -- as long as the minimum requirements for QEMU itself don't break.

OK.

Quoted 4 lines

Having a modern setuptools in order to install seems like less of a problem barrier; and it seemed like a good idea to make it explicitly fail instead of silently doing something weird if it didn't see/understand setup.cfg.

Agreed.

Quoted 8 lines

(And it seems like good practice to update pip in your venv, so I think we'll be OK except for the stodgiest of users, but sometimes you can't have new things on old systems without learning some new tricks!)

Quoted 4 lines

CentOS 8 has that specific version, while Ubuntu 18.04 has version 39.0. Ubuntu 20.04 has a recent enough version though. Given that all GitLab CI moved to 20.04, this should be safe.

Quoted 6 lines
Quoted 2 lines

- Cleber.

FWIW, for the purposes of running the linters, I am using Fedora32 and the python36 package.

This is a minor suggestion: use CentOS 8 stock Python 3.6 packages, and then Fedora 33 with also stock Python 3.9. Even though all tools are pinned, it's still a good idea to test at least min/max (if not all) Python versions.

- Cleber.

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
python/setup.py new file +6 -0
+
+    setuptools.setup()
+
+
+if __name__ == '__main__':
+    main()
Signature · 1 line
2.26.2
author
#10 lore raw

Re: [PATCH v3 02/15] python: add qemu package installer

Quoted 95 lines · Cleber Rosa
Quoted 16 lines · John Snow
Quoted 6 lines · Cleber Rosa

python/PACKAGE.rst line 26

Quoted 2 lines
python/PACKAGE.rst new file +2 -0
+mirror <https://gitlab.com/jsnow/qemu/-/tree/python>`_, but
+contributions must be sent to the list for inclusion.

IMO it's not clear if this branch/mirror is your development work, a staging area, etc.

Fair enough. jsnow/qemu/python is intended as a staging area for patches that have been vetted on-list.

jsnow/qemu/master is a lazily-updated mirror. (I tend to update it every day as part of my development process, but there are days I don't write code.)

jsnow/qemu/python-* is development work; review branches, etc.

Quoted 9 lines

I'll try to rephrase this a bit. What I want to communicate:

- This package exists as a subfolder of a larger project
- I am responsible for maintaining this package, but not for the larger project
- Please contact *me* for problems with this package
- Contributions should go through qemu-devel (I will gently redirect contributors who may send pull requests to the qemu devel list.)

OK, sounds good. I'll look at the exact rewording on v+1.

Quoted 23 lines
Quoted 13 lines
Quoted 13 lines
python/setup.cfg new file +7 -0
new file mode 100755
index 0000000000..12b99a796e
@@ -0,0 +1,18 @@
+[metadata]
+name = qemu
+maintainer = QEMU Developer Team
+maintainer_email = [email protected]
+url = https://www.qemu.org/
+download_url = https://www.qemu.org/download/
+description = QEMU Python Build, Debug and SDK tooling.
Quoted 9 lines

python/setup.cfg line 15

Quoted 8 lines
python/setup.cfg new file +8 -0
+long_description = file:PACKAGE.rst
+long_description_content_type = text/x-rst
+classifiers =
+    Development Status :: 3 - Alpha
+    License :: OSI Approved :: GNU General Public License v2 (GPLv2)
+    Natural Language :: English
+    Operating System :: OS Independent
+
Quoted 7 lines

Also ... licensing question, do we need *L*GPLv2, or does Python not have a "linking exception" problem?

I guess we can't really re-license these files anyway, so nevermind.

(I immediately regret asking this.)

I'll just pretend you never did.

Quoted 6 lines
Quoted 5 lines

I know the sky is the limit, but I miss the Python version classifier, at least:

Programming Language :: Python :: 3 :: Only

Quoted 7 lines

Sure.

Wait, why can you specify Python as a language? Is it possible to have non-Python packages on PyPI?

*CONCERNED*

I guess it has to do with packages that can interact or serve other languages. Or, that are (partially) written in another language?

Quoted 16 lines
Quoted 10 lines

And optionally those:

Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9

Although it may be a good idea to add them along test jobs on those specific Python versions.

Are these worth adding? I've got python_requires >= 3.6 down below. From my test of a blank package upload to PyPI, it seems to display prominently:

https://pypi.org/project/qemu/

Quoted 9 lines
Quoted 2 lines

Is there a tangible benefit that you are aware of?

AFAICT, the classifiers are about letting people search for packages that match a given criteria. It's all metadata, so the benefits are not super tangible. I've used those to keep track / document the Python versions that I know the project has been actively tested on, and that's the reason of my comment about (CI) test jobs.

OK, let's add them alongside a tox/pytest configuration or something in the future when we add those versions as being supported.

I guess I can add the 3.6 version for starters, since it's explicitly supported?

Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 16 lines
python/setup.cfg new file +3 -0
+[options]
+python_requires = >= 3.6
+packages = find_namespace:
python/setup.py new file +7 -0
new file mode 100755
index 0000000000..e93d0075d1
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+"""
+QEMU tooling installer script
+Copyright (c) 2020 John Snow for Red Hat, Inc.
+"""
+
+import setuptools

python/setup.py line 17

Quoted 10 lines
python/setup.py new file +10 -0
+import pkg_resources
+
+
+def main():
+    """
+    QEMU tooling installer
+    """
+
+    # https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108
+    pkg_resources.require('setuptools>=39.2')

Getting back to the "test jobs on those specific Python versions" I was really anxious that environments with Python 3.6 will fail to have such a "recent" setuptools version.

Quoted 8 lines
Quoted 4 lines

Reasonable doubt. However, this isn't *required* to use the library (the QEMU code can continue to just set PYTHONPATH or sys.path as necessary) and bypasses the installer entirely.

Right, but I had the impression that activating it in develop mode (at least) was the intention down the line.

For builds at all?

I guess we could, yeah, if we wanted to start making a "build venv" and install it there. I think there's a lot of questions to work out there first, though. I am not really there yet, myself.

Right now, *right now*, all of this code is used only for testing and CI, so we've skirted around build requirements.

I did want to start picking up some other packages though, like 'qapi', for the purposes of applying the linter paradigm though ... and I figured I'd cross that bridge when I got there.

Right now, having a forwarder script with a sys.path hack works.

(Probably by the time we figure that out, setuptools 39 will be standard on all of our supported build platforms...)

Quoted 26 lines
Quoted 5 lines

That gives us some leeway apart from the usual version constraints; in order to independently use this library outside of the QEMU tree we may impose more modern setups -- as long as the minimum requirements for QEMU itself don't break.

OK.

Quoted 4 lines

Having a modern setuptools in order to install seems like less of a problem barrier; and it seemed like a good idea to make it explicitly fail instead of silently doing something weird if it didn't see/understand setup.cfg.

Agreed.

Quoted 11 lines

(And it seems like good practice to update pip in your venv, so I think we'll be OK except for the stodgiest of users, but sometimes you can't have new things on old systems without learning some new tricks!)

Quoted 6 lines

CentOS 8 has that specific version, while Ubuntu 18.04 has version 39.0. Ubuntu 20.04 has a recent enough version though. Given that all GitLab CI moved to 20.04, this should be safe.

- Cleber.

Quoted 9 lines
Quoted 3 lines

FWIW, for the purposes of running the linters, I am using Fedora32 and the python36 package.

This is a minor suggestion: use CentOS 8 stock Python 3.6 packages, and then Fedora 33 with also stock Python 3.9. Even though all tools are pinned, it's still a good idea to test at least min/max (if not all) Python versions.

I can use CentOS, sure. I don't think it matters tremendously whose Python 3.6 we use. I opted for Fedora because we package old python interpreters on purpose, which makes it easy to say "I want Python3.6 and not a drop older or newer."

I assume the same is true on CentOS. We can talk about this on the CI series; though I will likely merge these two series into one for future revisions.

I don't have a framework in mind for doing python version matrix testing yet. I guess tox is the canonical tool for that. We can cross that bridge when we get there, I guess. (We currently have: 0 tests for the qemu python library. oops!)

For the meantime, though, I think it's OK to only run the linter on Python 3.6: it's not a test of the package itself, it's just a specific environment that we use to enforce code quality. It so happens to be a Python 3.6 environment. Pinning it to a specific version of python there is useful because the linters *do* sometimes have different behavior depending on version; due largely in part to changes in the stdlib typing library.

Quoted 12 lines

- Cleber.

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
python/setup.py new file +6 -0
+
+    setuptools.setup()
+
+
+if __name__ == '__main__':
+    main()
Signature · 1 line
2.26.2
#11 lore raw

Re: [PATCH v3 02/15] python: add qemu package installer

In reply to John Snow
Quoted 12 lines · John Snow

Add setup.cfg and setup.py, necessary for installing a package via pip. Add a rst document explaining the basics of what this package is for and who to contact for more information. This document will be used as the landing page for the package on PyPI.

I am not yet using a pyproject.toml style package manifest, because using pyproject.toml (and PEP-517) style packages means that pip is not able to install in "editable" or "develop" mode, which I consider necessary for the development of this package.

Use a light-weight setup.py instead.

Quoted 8 lines
---
 python/PACKAGE.rst | 26 ++++++++++++++++++++++++++
 python/setup.cfg   | 18 ++++++++++++++++++
 python/setup.py    | 23 +++++++++++++++++++++++
 3 files changed, 67 insertions(+)
 create mode 100644 python/PACKAGE.rst
 create mode 100755 python/setup.cfg

I missed this earlier: setup.cfg does not need to have the execute bit on.

- Cleber.

author
#12 lore raw

Re: [PATCH v3 02/15] python: add qemu package installer

Quoted 22 lines · Cleber Rosa
Quoted 12 lines · John Snow

Add setup.cfg and setup.py, necessary for installing a package via pip. Add a rst document explaining the basics of what this package is for and who to contact for more information. This document will be used as the landing page for the package on PyPI.

I am not yet using a pyproject.toml style package manifest, because using pyproject.toml (and PEP-517) style packages means that pip is not able to install in "editable" or "develop" mode, which I consider necessary for the development of this package.

Use a light-weight setup.py instead.

Quoted 8 lines
---
  python/PACKAGE.rst | 26 ++++++++++++++++++++++++++
  python/setup.cfg   | 18 ++++++++++++++++++
  python/setup.py    | 23 +++++++++++++++++++++++
  3 files changed, 67 insertions(+)

create mode 100644 python/PACKAGE.rst
create mode 100755 python/setup.cfg

Quoted 5 lines

I missed this earlier: setup.cfg does not need to have the execute bit on.

- Cleber.

Fixed this locally already; it came along when I ran 'cp setup.py setup.cfg', obviously!

author
#13 lore raw

PATCH v3 3/15 python: add VERSION file

In reply to John Snow

Python infrastructure as it exists today is not capable reliably of single-sourcing a package version from a parent directory. The authors of pip are working to correct this, but as of today this is not possible to my knowledge.

The problem is that when using pip to build and install a python package, it copies files over to a temporary directory and performs its build there. This loses access to any information in the parent directory, including git itself.

Further, Python versions have a standard (PEP 440) that may or may not follow QEMU's versioning. In general, it does; but naturally QEMU does not follow PEP 440. To avoid any automatically-generated conflict, a manual version file is preferred.

I am proposing:

- Python tooling follows the QEMU version, indirectly, but with a major version of 0 to indicate that the API is not expected to be stable. This would mean version 0.5.2.0, 0.5.1.1, 0.5.3.0, etc.

- In the event that a Python package needs to be updated independently of the QEMU version, a pre-release alpha version should be preferred, but *only* after inclusion to the qemu development or stable branches.

e.g. 0.5.2.0a1, 0.5.2.0a2, and so on should be preferred prior to 5.2.0's release.

- The Python core tooling makes absolutely no version compatibility checks or constraints. It *may* work with releases of QEMU from the past or future, but it is not required to.

i.e., "qemu.machine" will always remain in lock-step with QEMU.

- We reserve the right to split the qemu package into independently versioned subpackages at a later date. This might allow for us to begin versioning QMP independently from QEMU at a later date, if we so choose.

Implement this versioning scheme by adding a VERSION file and setting it to 0.5.2.0a1.

---
 python/VERSION   | 1 +
 python/setup.cfg | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 python/VERSION
python/VERSION new file +1 -0
new file mode 100644
index 0000000000..ceef7e1ad0
@@ -0,0 +1 @@
+0.5.2.0a1
python/setup.cfg +1 -0
index 12b99a796e..260f7f4e94 100755
@@ -1,5 +1,6 @@
 [metadata]
 name = qemu
+version = file:VERSION
 maintainer = QEMU Developer Team
 maintainer_email = [email protected]
 url = https://www.qemu.org/
Signature · 1 line
2.26.2
Reviewed-by on v3 3/15
#14 lore raw

Re: [PATCH v3 03/15] python: add VERSION file

Quoted 41 lines · John Snow

Python infrastructure as it exists today is not capable reliably of single-sourcing a package version from a parent directory. The authors of pip are working to correct this, but as of today this is not possible to my knowledge.

The problem is that when using pip to build and install a python package, it copies files over to a temporary directory and performs its build there. This loses access to any information in the parent directory, including git itself.

Further, Python versions have a standard (PEP 440) that may or may not follow QEMU's versioning. In general, it does; but naturally QEMU does not follow PEP 440. To avoid any automatically-generated conflict, a manual version file is preferred.

I am proposing:

- Python tooling follows the QEMU version, indirectly, but with a major version of 0 to indicate that the API is not expected to be stable. This would mean version 0.5.2.0, 0.5.1.1, 0.5.3.0, etc.

- In the event that a Python package needs to be updated independently of the QEMU version, a pre-release alpha version should be preferred, but *only* after inclusion to the qemu development or stable branches.

e.g. 0.5.2.0a1, 0.5.2.0a2, and so on should be preferred prior to 5.2.0's release.

- The Python core tooling makes absolutely no version compatibility checks or constraints. It *may* work with releases of QEMU from the past or future, but it is not required to.

i.e., "qemu.machine" will always remain in lock-step with QEMU.

- We reserve the right to split the qemu package into independently versioned subpackages at a later date. This might allow for us to begin versioning QMP independently from QEMU at a later date, if we so choose.

Quoted 4 lines

Implement this versioning scheme by adding a VERSION file and setting it to 0.5.2.0a1.

I'd rather have the version to be sync'd with QEMU, but, I understand this is a more conservative approach that can maybe evolve into that.

author
#15 lore raw

Re: [PATCH v3 03/15] python: add VERSION file

Quoted 45 lines · Cleber Rosa
Quoted 44 lines · John Snow

Python infrastructure as it exists today is not capable reliably of single-sourcing a package version from a parent directory. The authors of pip are working to correct this, but as of today this is not possible to my knowledge.

The problem is that when using pip to build and install a python package, it copies files over to a temporary directory and performs its build there. This loses access to any information in the parent directory, including git itself.

Further, Python versions have a standard (PEP 440) that may or may not follow QEMU's versioning. In general, it does; but naturally QEMU does not follow PEP 440. To avoid any automatically-generated conflict, a manual version file is preferred.

I am proposing:

- Python tooling follows the QEMU version, indirectly, but with a major version of 0 to indicate that the API is not expected to be stable. This would mean version 0.5.2.0, 0.5.1.1, 0.5.3.0, etc.

- In the event that a Python package needs to be updated independently of the QEMU version, a pre-release alpha version should be preferred, but *only* after inclusion to the qemu development or stable branches.

e.g. 0.5.2.0a1, 0.5.2.0a2, and so on should be preferred prior to 5.2.0's release.

- The Python core tooling makes absolutely no version compatibility checks or constraints. It *may* work with releases of QEMU from the past or future, but it is not required to.

i.e., "qemu.machine" will always remain in lock-step with QEMU.

- We reserve the right to split the qemu package into independently versioned subpackages at a later date. This might allow for us to begin versioning QMP independently from QEMU at a later date, if we so choose.

Implement this versioning scheme by adding a VERSION file and setting it to 0.5.2.0a1.

Quoted 7 lines
Quoted 1 line

I'd rather have the version to be sync'd with QEMU, but, I understand this is a more conservative approach that can maybe evolve into that.

It's definitely me taking the cowardly way out. I did use the exact QEMU version in the last spin, because that seemed like the dumbest thing :)

I think qemu.machine would eventually evolve to track the QEMU version directly, whereas qemu.qmp would evolve to keep its own independent versioning system.

This is just, I guess, one more semantic nudge towards the idea that this is really an independent little component. I just want to give it some more time in the oven before I declare it truly and genuinely supported as its own project. Once it's on PyPI, I am beholden to more than the other QEMU contributors. Satisfying both crowds simultaneously seems like it will be tough.

--js

author
#16 lore raw

PATCH v3 4/15 python: add directory structure README.rst files

In reply to John Snow

Add short readmes to python/, python/qemu/, python/qemu/machine, and python/qemu/machine that explain the directory hierarchy. These readmes are visible when browsing the source on e.g. gitlab/github and are designed to help new developers/users quickly make sense of the source tree.

They are not designed for inclusion in a published manual.

---
 python/README.rst              | 27 +++++++++++++++++++++++++++
 python/qemu/README.rst         |  8 ++++++++
 python/qemu/machine/README.rst |  9 +++++++++
 python/qemu/qmp/README.rst     |  9 +++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 python/README.rst
 create mode 100644 python/qemu/README.rst
 create mode 100644 python/qemu/machine/README.rst
 create mode 100644 python/qemu/qmp/README.rst
python/README.rst new file +27 -0
new file mode 100644
index 0000000000..ff40e4c931
@@ -0,0 +1,27 @@
+QEMU Python Tooling
+===================
+
+This directory houses Python tooling used by the QEMU project to build,
+configure, and test QEMU. It is organized by namespace (``qemu``), and
+then by package (``qemu/machine``, ``qemu/qmp``).
+
+``setup.py`` is used by ``pip`` to install this tooling to the current
+environment. You will generally invoke it by doing one of the following:
+
+1. ``pip3 install .`` will install these packages to your current
+   environment. If you are inside a virtual environment, they will
+   install there. If you are not, it will attempt to install to the
+   global environment, which is not recommended.
+
+2. ``pip3 install --user .`` will install these packages to your user's
+   local python packages. If you are inside of a virtual environment,
+   this will fail.
+
+If you amend the ``-e`` argument, pip will install in "editable" mode;
+which installs a version of the package that uses symlinks to these
+files, such that the package always reflects the latest version in your
+git tree.
+
+See `Installing packages using pip and virtual environments
+<https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>`_
+for more information.
python/qemu/README.rst new file +8 -0
new file mode 100644
index 0000000000..31209c80a5
@@ -0,0 +1,8 @@
+QEMU Python Namespace
+=====================
+
+This directory serves as the root of a `Python PEP 420 implicit
+namespace package <<https://www.python.org/dev/peps/pep-0420/>`_.
+
+Each directory below is assumed to be an installable Python package that
+is available under the ``qemu.<package>`` namespace.
python/qemu/machine/README.rst new file +9 -0
new file mode 100644
index 0000000000..73ad23c501
@@ -0,0 +1,9 @@
+qemu.machine Package
+====================
+
+This package provides core utilities used for testing and debugging
+QEMU. It is used by the iotests, vm tests, and several other utilities
+in the ./scripts directory. It is not a fully-fledged SDK and it is
+subject to change at any time.
+
+See the documentation in ``__init__.py`` for more information.
python/qemu/qmp/README.rst new file +9 -0
new file mode 100644
index 0000000000..f35dffe582
@@ -0,0 +1,9 @@
+qemu.qmp Package
+================
+
+This package provides a library used for connecting to and communicating
+with QMP servers. It is used extensively by iotests, vm tests, and other
+utilities in the ./scripts directory. It is not a fully-fledged SDK and
+is subject to change at any time.
+
+See the documentation in ``__init__.py`` for more information.
Signature · 1 line
2.26.2
#17 lore raw

Re: [PATCH v3 04/15] python: add directory structure README.rst files

Quoted 40 lines · John Snow

Add short readmes to python/, python/qemu/, python/qemu/machine, and python/qemu/machine that explain the directory hierarchy. These readmes are visible when browsing the source on e.g. gitlab/github and are designed to help new developers/users quickly make sense of the source tree.

They are not designed for inclusion in a published manual.

---
 python/README.rst              | 27 +++++++++++++++++++++++++++
 python/qemu/README.rst         |  8 ++++++++
 python/qemu/machine/README.rst |  9 +++++++++
 python/qemu/qmp/README.rst     |  9 +++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 python/README.rst
 create mode 100644 python/qemu/README.rst
 create mode 100644 python/qemu/machine/README.rst
 create mode 100644 python/qemu/qmp/README.rst
python/README.rst new file +14 -0
new file mode 100644
index 0000000000..ff40e4c931
@@ -0,0 +1,27 @@
+QEMU Python Tooling
+===================
+
+This directory houses Python tooling used by the QEMU project to build,
+configure, and test QEMU. It is organized by namespace (``qemu``), and
+then by package (``qemu/machine``, ``qemu/qmp``).
+
+``setup.py`` is used by ``pip`` to install this tooling to the current
+environment. You will generally invoke it by doing one of the following:
+
+1. ``pip3 install .`` will install these packages to your current
+   environment. If you are inside a virtual environment, they will
+   install there. If you are not, it will attempt to install to the
+   global environment, which is not recommended.

python/README.rst line 24

Quoted 10 lines
python/README.rst new file +10 -0
+
+2. ``pip3 install --user .`` will install these packages to your user's
+   local python packages. If you are inside of a virtual environment,
+   this will fail.
+
+If you amend the ``-e`` argument, pip will install in "editable" mode;
+which installs a version of the package that uses symlinks to these
+files, such that the package always reflects the latest version in your
+git tree.
+

It actually uses *egg-link* files, which are not what people will understand by "symlinks".

Quoted 23 lines
python/README.rst new file +3 -0
+See `Installing packages using pip and virtual environments
+<https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>`_
+for more information.
python/qemu/README.rst new file +8 -0
new file mode 100644
index 0000000000..31209c80a5
@@ -0,0 +1,8 @@
+QEMU Python Namespace
+=====================
+
+This directory serves as the root of a `Python PEP 420 implicit
+namespace package <<https://www.python.org/dev/peps/pep-0420/>`_.
+
+Each directory below is assumed to be an installable Python package that
+is available under the ``qemu.<package>`` namespace.
python/qemu/machine/README.rst new file +0 -0
new file mode 100644
index 0000000000..73ad23c501

python/qemu/machine/README.rst line 8

Quoted 8 lines
python/qemu/machine/README.rst new file +8 -0
@@ -0,0 +1,9 @@
+qemu.machine Package
+====================
+
+This package provides core utilities used for testing and debugging
+QEMU. It is used by the iotests, vm tests, and several other utilities
+in the ./scripts directory. It is not a fully-fledged SDK and it is
+subject to change at any time.
+

I'm not sure if you intend to list all test types that use this, but the acceptance tests also do use them.

- Cleber.

author
#18 lore raw

Re: [PATCH v3 04/15] python: add directory structure README.rst files

Quoted 46 lines · Cleber Rosa
Quoted 45 lines · John Snow

Add short readmes to python/, python/qemu/, python/qemu/machine, and python/qemu/machine that explain the directory hierarchy. These readmes are visible when browsing the source on e.g. gitlab/github and are designed to help new developers/users quickly make sense of the source tree.

They are not designed for inclusion in a published manual.

---
  python/README.rst              | 27 +++++++++++++++++++++++++++
  python/qemu/README.rst         |  8 ++++++++
  python/qemu/machine/README.rst |  9 +++++++++
  python/qemu/qmp/README.rst     |  9 +++++++++
  4 files changed, 53 insertions(+)

create mode 100644 python/README.rst create mode 100644 python/qemu/README.rst create mode 100644 python/qemu/machine/README.rst create mode 100644 python/qemu/qmp/README.rst

python/README.rst new file +19 -0
new file mode 100644
index 0000000000..ff40e4c931
@@ -0,0 +1,27 @@
+QEMU Python Tooling
+===================
+
+This directory houses Python tooling used by the QEMU project to build,
+configure, and test QEMU. It is organized by namespace (``qemu``), and
+then by package (``qemu/machine``, ``qemu/qmp``).
+
+``setup.py`` is used by ``pip`` to install this tooling to the current
+environment. You will generally invoke it by doing one of the following:
+
+1. ``pip3 install .`` will install these packages to your current
+   environment. If you are inside a virtual environment, they will
+   install there. If you are not, it will attempt to install to the
+   global environment, which is not recommended.
+
+2. ``pip3 install --user .`` will install these packages to your user's
+   local python packages. If you are inside of a virtual environment,
+   this will fail.
+
Quoted 9 lines

python/README.rst line 24

Quoted 5 lines
python/README.rst new file +5 -0
+If you amend the ``-e`` argument, pip will install in "editable" mode;
+which installs a version of the package that uses symlinks to these
+files, such that the package always reflects the latest version in your
+git tree.
+

It actually uses *egg-link* files, which are not what people will understand by "symlinks".

Ehm, good point; I don't want to *lie* here. I think I do want to avoid the jargon though.

"that installs a forwarder pointing to these files" -- better?

Quoted 26 lines
Quoted 26 lines
python/README.rst new file +3 -0
+See `Installing packages using pip and virtual environments
+<https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>`_
+for more information.
python/qemu/README.rst new file +8 -0
new file mode 100644
index 0000000000..31209c80a5
@@ -0,0 +1,8 @@
+QEMU Python Namespace
+=====================
+
+This directory serves as the root of a `Python PEP 420 implicit
+namespace package <<https://www.python.org/dev/peps/pep-0420/>`_.
+
+Each directory below is assumed to be an installable Python package that
+is available under the ``qemu.<package>`` namespace.
python/qemu/machine/README.rst new file +3 -0
new file mode 100644
index 0000000000..73ad23c501
@@ -0,0 +1,9 @@
+qemu.machine Package
+====================
+
Quoted 9 lines

python/qemu/machine/README.rst line 8

Quoted 5 lines
python/qemu/machine/README.rst new file +5 -0
+This package provides core utilities used for testing and debugging
+QEMU. It is used by the iotests, vm tests, and several other utilities
+in the ./scripts directory. It is not a fully-fledged SDK and it is
+subject to change at any time.
+

I'm not sure if you intend to list all test types that use this, but the acceptance tests also do use them.

Wasn't a conscious omission, but didn't necessarily mean to make it comprehensive; I can add it while fixing the above feedback item too.

Quoted 2 lines

- Cleber.

Thanks!

author
#19 lore raw

PATCH v3 5/15 python: Add pipenv support

In reply to John Snow

pipenv is a tool used for managing virtual environments with pinned, explicit dependencies. It is used for precisely recreating python virtual environments.

pipenv uses two files to do this:

(1) Pipfile, which is similar in purpose and scope to what setup.py lists. It specifies the requisite minimum to get a functional environment for using this package.

(2) Pipfile.lock, which is similar in purpose to pip freeze > requirements.txt. It specifies a canonical virtual environment used for deployment or testing. This ensures that all users have repeatable results.

The primary benefit of using this tool is to ensure repeatable CI results with a known set of packages. Although I endeavor to support as many versions as I can, the fluid nature of the Python toolchain often means tailoring code for fairly specific versions.

Note that pipenv is *not* required to install or use this module; this is purely for the sake of repeatable testing by CI or developers.

Here, a "blank" pipfile is added with no dependencies, but specifies Python 3.6 for the virtual environment.

Pipfile will specify our version minimums, while Pipfile.lock specifies an exact loudout of packages that were known to operate correctly. This latter file provides the real value for easy setup of container images and CI environments.

---
 python/Pipfile | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 python/Pipfile
python/Pipfile new file +11 -0
new file mode 100644
index 0000000000..9534830b5e
@@ -0,0 +1,11 @@
+[[source]]
+name = "pypi"
+url = "https://pypi.org/simple"
+verify_ssl = true
+
+[dev-packages]
+
+[packages]
+
+[requires]
+python_version = "3.6"
Signature · 1 line
2.26.2
Reviewed-by on v3 5/15
#20 lore raw

Re: [PATCH v3 05/15] python: Add pipenv support

Quoted 26 lines · John Snow

pipenv is a tool used for managing virtual environments with pinned, explicit dependencies. It is used for precisely recreating python virtual environments.

pipenv uses two files to do this:

(1) Pipfile, which is similar in purpose and scope to what setup.py lists. It specifies the requisite minimum to get a functional environment for using this package.

(2) Pipfile.lock, which is similar in purpose to pip freeze > requirements.txt. It specifies a canonical virtual environment used for deployment or testing. This ensures that all users have repeatable results.

The primary benefit of using this tool is to ensure repeatable CI results with a known set of packages. Although I endeavor to support as many versions as I can, the fluid nature of the Python toolchain often means tailoring code for fairly specific versions.

Note that pipenv is *not* required to install or use this module; this is purely for the sake of repeatable testing by CI or developers.

Here, a "blank" pipfile is added with no dependencies, but specifies Python 3.6 for the virtual environment.

Quoted 6 lines

Pipfile will specify our version minimums, while Pipfile.lock specifies an exact loudout of packages that were known to operate correctly. This latter file provides the real value for easy setup of container images and CI environments.

author
#21 lore raw

PATCH v3 6/15 python: add pylint import exceptions

In reply to John Snow

Pylint 2.5.x and 2.6.x have regressions that make import checking inconsistent, see:

https: //github.com/PyCQA/pylint/issues/3609
https: //github.com/PyCQA/pylint/issues/3624
https: //github.com/PyCQA/pylint/issues/3651

Pinning to 2.4.4 is worse, because it mandates versions of shared dependencies that are too old for features we want in isort and mypy. Oh well.

---
 python/qemu/machine/__init__.py | 3 +++
 python/qemu/machine/machine.py  | 2 +-
 python/qemu/machine/qtest.py    | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)
python/qemu/machine/__init__.py +3 -0
index 27b0b19abd..15e466a8d3 100644
@@ -26,6 +26,9 @@
 # the COPYING file in the top-level directory.
 #
 
+# pylint: disable=import-error
+# see: https://github.com/PyCQA/pylint/issues/3624
+# see: https://github.com/PyCQA/pylint/issues/3651
 from .accel import kvm_available, list_accel, tcg_available
 from .machine import QEMUMachine
 from .qtest import QEMUQtestMachine, QEMUQtestProtocol
python/qemu/machine/machine.py +1 -1
index a5dc305539..88c51f5052 100644
@@ -38,7 +38,7 @@
     Type,
 )
 
-from qemu.qmp import (
+from qemu.qmp import (  # pylint: disable=import-error
     QEMUMonitorProtocol,
     QMPMessage,
     QMPReturnValue,
python/qemu/machine/qtest.py +1 -1
index 53926e434a..c3adf4e301 100644
@@ -26,7 +26,7 @@
     TextIO,
 )
 
-from qemu.qmp import SocketAddrT
+from qemu.qmp import SocketAddrT  # pylint: disable=import-error
 
 from .machine import QEMUMachine
 
Signature · 1 line
2.26.2
Reviewed-by on v3 6/15
#22 lore raw

Re: [PATCH v3 06/15] python: add pylint import exceptions

Quoted 7 lines · John Snow

Pylint 2.5.x and 2.6.x have regressions that make import checking inconsistent, see:

https: //github.com/PyCQA/pylint/issues/3609
https: //github.com/PyCQA/pylint/issues/3624
https: //github.com/PyCQA/pylint/issues/3651

Are these whitespaces on purpose?

Quoted 5 lines

Pinning to 2.4.4 is worse, because it mandates versions of shared dependencies that are too old for features we want in isort and mypy. Oh well.

Other than that,

author
#23 lore raw

Re: [PATCH v3 06/15] python: add pylint import exceptions

Quoted 11 lines · Cleber Rosa
Quoted 7 lines · John Snow

Pylint 2.5.x and 2.6.x have regressions that make import checking inconsistent, see:

https: //github.com/PyCQA/pylint/issues/3609
https: //github.com/PyCQA/pylint/issues/3624
https: //github.com/PyCQA/pylint/issues/3651

Are these whitespaces on purpose?

Uh, nope. How'd that happen?

Quoted 10 lines
Quoted 5 lines

Pinning to 2.4.4 is worse, because it mandates versions of shared dependencies that are too old for features we want in isort and mypy. Oh well.

Other than that,

author
#24 lore raw

PATCH v3 7/15 python: move pylintrc into setup.cfg

In reply to John Snow

Delete the empty settings now that it's sharing a home with settings for other tools.

pylint can now be run from this folder as "pylint qemu".

---
 python/qemu/machine/pylintrc | 58 ------------------------------------
 python/setup.cfg             | 29 ++++++++++++++++++
 2 files changed, 29 insertions(+), 58 deletions(-)
 delete mode 100644 python/qemu/machine/pylintrc
python/qemu/machine/pylintrc deleted +0 -58
deleted file mode 100644
index 3f69205000..0000000000
@@ -1,58 +0,0 @@
-[MASTER]
-
-[MESSAGES CONTROL]
-
-# Disable the message, report, category or checker with the given id(s). You
-# can either give multiple identifiers separated by comma (,) or put this
-# option multiple times (only on the command line, not in the configuration
-# file where it should appear only once). You can also use "--disable=all" to
-# disable everything first and then reenable specific checks. For example, if
-# you want to run only the similarities checker, you can use "--disable=all
-# --enable=similarities". If you want to run only the classes checker, but have
-# no Warning level messages displayed, use "--disable=all --enable=classes
-# --disable=W".
-disable=too-many-arguments,
-        too-many-instance-attributes,
-        too-many-public-methods,
-
-[REPORTS]
-
-[REFACTORING]
-
-[MISCELLANEOUS]
-
-[LOGGING]
-
-[BASIC]
-
-# Good variable names which should always be accepted, separated by a comma.
-good-names=i,
-           j,
-           k,
-           ex,
-           Run,
-           _,
-           fd,
-           c,
-[VARIABLES]
-
-[STRING]
-
-[SPELLING]
-
-[FORMAT]
-
-[SIMILARITIES]
-
-# Ignore imports when computing similarities.
-ignore-imports=yes
-
-[TYPECHECK]
-
-[CLASSES]
-
-[IMPORTS]
-
-[DESIGN]
-
-[EXCEPTIONS]
python/setup.cfg +29 -0
index 260f7f4e94..a65802d85e 100755
@@ -17,3 +17,32 @@ classifiers =
 [options]
 python_requires = >= 3.6
 packages = find_namespace:
+
+[pylint.messages control]
+# Disable the message, report, category or checker with the given id(s). You
+# can either give multiple identifiers separated by comma (,) or put this
+# option multiple times (only on the command line, not in the configuration
+# file where it should appear only once). You can also use "--disable=all" to
+# disable everything first and then reenable specific checks. For example, if
+# you want to run only the similarities checker, you can use "--disable=all
+# --enable=similarities". If you want to run only the classes checker, but have
+# no Warning level messages displayed, use "--disable=all --enable=classes
+# --disable=W".
+disable=too-many-arguments,
+        too-many-instance-attributes,
+        too-many-public-methods,
+
+[pylint.basic]
+# Good variable names which should always be accepted, separated by a comma.
+good-names=i,
+           j,
+           k,
+           ex,
+           Run,
+           _,
+           fd,
+           c,
+
+[pylint.similarities]
+# Ignore imports when computing similarities.
+ignore-imports=yes
Signature · 1 line
2.26.2
author
#26 lore raw

PATCH v3 8/15 python: add pylint to pipenv

In reply to John Snow

We are specifying >= pylint 2.6.x for two reasons:

1. For setup.cfg support, added in pylint 2.5.x
2. To clarify that we are using a version that has incompatibly dropped bad-whitespace checks.

---
 python/Pipfile      |   1 +
 python/Pipfile.lock | 127 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+)
 create mode 100644 python/Pipfile.lock
python/Pipfile +1 -0
index 9534830b5e..1e58986c89 100644
@@ -4,6 +4,7 @@ url = "https://pypi.org/simple"
 verify_ssl = true
 
 [dev-packages]
+pylint = ">=2.6.0"
 
 [packages]
 
python/Pipfile.lock new file +127 -0

127 lines not on this page · raw message

Signature · 1 line
2.26.2
Reviewed-by Tested-by on v3 8/15
#27 lore raw

Re: [PATCH v3 08/15] python: add pylint to pipenv

Quoted 8 lines · John Snow

We are specifying >= pylint 2.6.x for two reasons:

1. For setup.cfg support, added in pylint 2.5.x
2. To clarify that we are using a version that has incompatibly dropped bad-whitespace checks.

---

I'm not a huge fan of this level of verbosity that pipenv generates, but at the same time, I've been bitten too many times by not providing the entire dep tree in a "requirements.txt"-like style. And it is what pipenv uses, so there's no way around that.

author
#28 lore raw

Re: [PATCH v3 08/15] python: add pylint to pipenv

Quoted 7 lines · Cleber Rosa
Quoted 6 lines · John Snow

We are specifying >= pylint 2.6.x for two reasons:

1. For setup.cfg support, added in pylint 2.5.x
2. To clarify that we are using a version that has incompatibly dropped bad-whitespace checks.

Quoted 8 lines
Quoted 2 lines

---

I'm not a huge fan of this level of verbosity that pipenv generates, but at the same time, I've been bitten too many times by not providing the entire dep tree in a "requirements.txt"-like style. And it is what pipenv uses, so there's no way around that.

Unless we don't use Pipenv :)

Quoted 3 lines

I will say I'm open to using tools that aren't Pipenv -- this is just something I knew how to use in order to provide a fairly robust venv-recreation mechanism, so I am using it. Don't know what I don't know, otherwise.

I hear Poetry is nice, but I haven't looked into it yet.

Tox I believe also does venv-management to some extent, though my impression of it was that it was less specific about the environments than Pipenv was and allowed more wiggle room. Could be wrong.

Pipenv does not manage multiple environments either, unlike Tox, which can multiplex your environments for different versions of things. That's one point in favor, perhaps.

If you'd like to propose using something else, feel free to fork this branch and implement something else; it's probably quicker that way than to have me learn tox/poetry/etc.

What I was using Pipenv to solve here is this:

"Create a package list pinned to explicit versions that is not for the purpose of installing or using the package, but is for the purpose of recreating a precise testing environment. Use this environment to run the linters with precisely known tooling versions."

My initial read was that using pip and requirements.txt alone was insufficient for this purpose; so I have been using Pipenv for the purpose.

Suggestions/patches welcome.

--js

author
#29 lore raw

PATCH v3 9/15 python: move flake8 config to setup.cfg

In reply to John Snow

Update the comment concerning the flake8 exception to match commit 42c0dd12, whose commit message stated:

A note on the flake8 exception: flake8 will warn on *any* bare except, but pylint's is context-aware and will suppress the warning if you re-raise the exception.

---
 python/qemu/machine/.flake8 | 2 --
 python/setup.cfg            | 3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)
 delete mode 100644 python/qemu/machine/.flake8
python/qemu/machine/.flake8 deleted +0 -2
deleted file mode 100644
index 45d8146f3f..0000000000
@@ -1,2 +0,0 @@
-[flake8]
-extend-ignore = E722  # Pylint handles this, but smarter.
\ No newline at end of file
python/setup.cfg +3 -0
index a65802d85e..87506a4f10 100755
@@ -18,6 +18,9 @@ classifiers =
 python_requires = >= 3.6
 packages = find_namespace:
 
+[flake8]
+extend-ignore = E722  # Prefer pylint's bare-except checks to flake8's
+
 [pylint.messages control]
 # Disable the message, report, category or checker with the given id(s). You
 # can either give multiple identifiers separated by comma (,) or put this
Signature · 1 line
2.26.2
Reviewed-by on v3 9/15
#30 lore raw

Re: [PATCH v3 09/15] python: move flake8 config to setup.cfg

Quoted 9 lines · John Snow

Update the comment concerning the flake8 exception to match commit 42c0dd12, whose commit message stated:

A note on the flake8 exception: flake8 will warn on *any* bare except, but pylint's is context-aware and will suppress the warning if you re-raise the exception.

---

author
#31 lore raw

PATCH v3 10/15 python: Add flake8 to pipenv

In reply to John Snow

flake8 3.5.x does not support the --extend-ignore syntax used in the .flake8 file to gracefully extend default ignores, so 3.6.x is our minimum requirement. There is no known upper bound.

flake8 can be run from the python/ directory with no arguments.

---
 python/Pipfile      |  1 +
 python/Pipfile.lock | 42 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)
python/Pipfile +1 -0
index 1e58986c89..d1f7045f68 100644
@@ -4,6 +4,7 @@ url = "https://pypi.org/simple"
 verify_ssl = true
 
 [dev-packages]
+flake8 = ">=3.6.0"
 pylint = ">=2.6.0"
 
 [packages]
python/Pipfile.lock +41 -1

66 lines not on this page · raw message

Signature · 1 line
2.26.2
Reviewed-by Tested-by on v3 10/15
#32 lore raw

Re: [PATCH v3 10/15] python: Add flake8 to pipenv

Quoted 8 lines · John Snow

flake8 3.5.x does not support the --extend-ignore syntax used in the .flake8 file to gracefully extend default ignores, so 3.6.x is our minimum requirement. There is no known upper bound.

flake8 can be run from the python/ directory with no arguments.

---

author
#33 lore raw

PATCH v3 11/15 python: move mypy.ini into setup.cfg

In reply to John Snow

mypy supports reading its configuration values from a central project configuration file; do so.

---
 python/mypy.ini  | 4 ----
 python/setup.cfg | 5 +++++
 2 files changed, 5 insertions(+), 4 deletions(-)
 delete mode 100644 python/mypy.ini
python/mypy.ini deleted +0 -4
deleted file mode 100644
index 1a581c5f1e..0000000000
@@ -1,4 +0,0 @@
-[mypy]
-strict = True
-python_version = 3.6
-warn_unused_configs = True
python/setup.cfg +5 -0
index 87506a4f10..206e5a91dc 100755
@@ -21,6 +21,11 @@ packages = find_namespace:
 [flake8]
 extend-ignore = E722  # Prefer pylint's bare-except checks to flake8's
 
+[mypy]
+strict = True
+python_version = 3.6
+warn_unused_configs = True
+
 [pylint.messages control]
 # Disable the message, report, category or checker with the given id(s). You
 # can either give multiple identifiers separated by comma (,) or put this
Signature · 1 line
2.26.2
author
#35 lore raw

PATCH v3 12/15 python: add mypy to pipenv

In reply to John Snow

0.730 appears to be about the oldest version that works with the features we want, including nice human readable output (to make sure iotest 297 passes), and type-parameterized Popen generics.

0.770, however, supports adding 'strict' to the config file, so require at least 0.770.

Now that we are checking a namespace package, we need to tell mypy to allow PEP420 namespaces, so modify the mypy config as part of the move.

mypy can now be run from the python root by typing 'mypy qemu'.

---
 python/Pipfile      |  1 +
 python/Pipfile.lock | 37 ++++++++++++++++++++++++++++++++++++-
 python/setup.cfg    |  1 +
 3 files changed, 38 insertions(+), 1 deletion(-)
python/Pipfile +1 -0
index d1f7045f68..51c537b0d1 100644
@@ -5,6 +5,7 @@ verify_ssl = true
 
 [dev-packages]
 flake8 = ">=3.6.0"
+mypy = ">=0.770"
 pylint = ">=2.6.0"
 
 [packages]
python/Pipfile.lock +36 -1
index eb5ae75a0c..376f95a6a8 100644
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "9f6d4857a6c72ad40fc1ec1e58cdb76f187a2986ac4156f0027e5eb798ec69a9"
+            "sha256": "65f010a8f2e55e9870d2b7e0d8af129516097d23abf2504f396552748b067ade"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -83,6 +83,33 @@
             ],
             "version": "==0.6.1"
         },
+        "mypy": {
+            "hashes": [
+                "sha256:0a0d102247c16ce93c97066443d11e2d36e6cc2a32d8ccc1f705268970479324",
+                "sha256:0d34d6b122597d48a36d6c59e35341f410d4abfa771d96d04ae2c468dd201abc",
+                "sha256:2170492030f6faa537647d29945786d297e4862765f0b4ac5930ff62e300d802",
+                "sha256:2842d4fbd1b12ab422346376aad03ff5d0805b706102e475e962370f874a5122",
+                "sha256:2b21ba45ad9ef2e2eb88ce4aeadd0112d0f5026418324176fd494a6824b74975",
+                "sha256:72060bf64f290fb629bd4a67c707a66fd88ca26e413a91384b18db3876e57ed7",
+                "sha256:af4e9ff1834e565f1baa74ccf7ae2564ae38c8df2a85b057af1dbbc958eb6666",
+                "sha256:bd03b3cf666bff8d710d633d1c56ab7facbdc204d567715cb3b9f85c6e94f669",
+                "sha256:c614194e01c85bb2e551c421397e49afb2872c88b5830e3554f0519f9fb1c178",
+                "sha256:cf4e7bf7f1214826cf7333627cb2547c0db7e3078723227820d0a2490f117a01",
+                "sha256:da56dedcd7cd502ccd3c5dddc656cb36113dd793ad466e894574125945653cea",
+                "sha256:e86bdace26c5fe9cf8cb735e7cedfe7850ad92b327ac5d797c656717d2ca66de",
+                "sha256:e97e9c13d67fbe524be17e4d8025d51a7dca38f90de2e462243ab8ed8a9178d1",
+                "sha256:eea260feb1830a627fb526d22fbb426b750d9f5a47b624e8d5e7e004359b219c"
+            ],
+            "index": "pypi",
+            "version": "==0.790"
+        },
+        "mypy-extensions": {
+            "hashes": [
+                "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d",
+                "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"
+            ],
+            "version": "==0.4.3"
+        },
         "pycodestyle": {
             "hashes": [
                 "sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367",
@@ -149,6 +176,14 @@
             "markers": "implementation_name == 'cpython' and python_version < '3.8'",
             "version": "==1.4.1"
         },
+        "typing-extensions": {
+            "hashes": [
+                "sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918",
+                "sha256:99d4073b617d30288f569d3f13d2bd7548c3a7e4c8de87db09a9d29bb3a4a60c",
+                "sha256:dafc7639cde7f1b6e1acc0f457842a83e722ccca8eef5270af2d74792619a89f"
+            ],
+            "version": "==3.7.4.3"
+        },
         "wrapt": {
             "hashes": [
                 "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"
python/setup.cfg +1 -0
index 206e5a91dc..308805b43f 100755
@@ -25,6 +25,7 @@ extend-ignore = E722  # Prefer pylint's bare-except checks to flake8's
 strict = True
 python_version = 3.6
 warn_unused_configs = True
+namespace_packages = True
 
 [pylint.messages control]
 # Disable the message, report, category or checker with the given id(s). You
Signature · 1 line
2.26.2
Reviewed-by Tested-by on v3 12/15
#36 lore raw

Re: [PATCH v3 12/15] python: add mypy to pipenv

Quoted 7 lines · John Snow

0.730 appears to be about the oldest version that works with the features we want, including nice human readable output (to make sure iotest 297 passes), and type-parameterized Popen generics.

0.770, however, supports adding 'strict' to the config file, so require at least 0.770.

Quoted 7 lines

Now that we are checking a namespace package, we need to tell mypy to allow PEP420 namespaces, so modify the mypy config as part of the move.

mypy can now be run from the python root by typing 'mypy qemu'.

---

author
#37 lore raw

PATCH v3 13/15 python: move .isort.cfg into setup.cfg

In reply to John Snow
---
 python/.isort.cfg | 7 -------
 python/setup.cfg  | 8 ++++++++
 2 files changed, 8 insertions(+), 7 deletions(-)
 delete mode 100644 python/.isort.cfg
python/.isort.cfg deleted +0 -7
deleted file mode 100644
index 6d0fd6cc0d..0000000000
@@ -1,7 +0,0 @@
-[settings]
-force_grid_wrap=4
-force_sort_within_sections=True
-include_trailing_comma=True
-line_length=72
-lines_after_imports=2
-multi_line_output=3
\ No newline at end of file
python/setup.cfg +8 -0
index 308805b43f..08def52372 100755
@@ -55,3 +55,11 @@ good-names=i,
 [pylint.similarities]
 # Ignore imports when computing similarities.
 ignore-imports=yes
+
+[isort]
+force_grid_wrap=4
+force_sort_within_sections=True
+include_trailing_comma=True
+line_length=72
+lines_after_imports=2
+multi_line_output=3
Signature · 1 line
2.26.2
author
#39 lore raw

PATCH v3 14/15 python/qemu: add isort to pipenv

In reply to John Snow

isort 5.0.0 through 5.0.4 has a bug that causes it to misinterpret certain "from ..." clauses that are not related to imports.

Require 5.0.5 or greater.

isort can be run with 'isort -c qemu' from the python root.

---
 python/Pipfile      | 1 +
 python/Pipfile.lock | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
python/Pipfile +1 -0
index 51c537b0d1..75b96f29d8 100644
@@ -5,6 +5,7 @@ verify_ssl = true
 
 [dev-packages]
 flake8 = ">=3.6.0"
+isort = ">=5.0.5"
 mypy = ">=0.770"
 pylint = ">=2.6.0"
 
python/Pipfile.lock +2 -2
index 376f95a6a8..74563b444c 100644
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "65f010a8f2e55e9870d2b7e0d8af129516097d23abf2504f396552748b067ade"
+            "sha256": "b89c7a1b8a414f2a4cd708964123fb427d55419ee0b39e088bf2e7d4fbc11979"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -46,7 +46,7 @@
                 "sha256:dcab1d98b469a12a1a624ead220584391648790275560e1a43e54c5dceae65e7",
                 "sha256:dcaeec1b5f0eca77faea2a35ab790b4f3680ff75590bfcb7145986905aab2f58"
             ],
-            "markers": "python_version >= '3.6' and python_version < '4.0'",
+            "index": "pypi",
             "version": "==5.6.4"
         },
         "lazy-object-proxy": {
Signature · 1 line
2.26.2
Reviewed-by Tested-by on v3 14/15
#40 lore raw

Re: [PATCH v3 14/15] python/qemu: add isort to pipenv

Quoted 10 lines · John Snow

isort 5.0.0 through 5.0.4 has a bug that causes it to misinterpret certain "from ..." clauses that are not related to imports.

Require 5.0.5 or greater.

isort can be run with 'isort -c qemu' from the python root.

---

author
#41 lore raw

Re: [PATCH v3 14/15] python/qemu: add isort to pipenv

Quoted 6 lines · Cleber Rosa
Quoted 5 lines · John Snow

isort 5.0.0 through 5.0.4 has a bug that causes it to misinterpret certain "from ..." clauses that are not related to imports.

Require 5.0.5 or greater.

Quoted 9 lines
Quoted 5 lines

isort can be run with 'isort -c qemu' from the python root.

---

Good suggestion on isort, btw. I was afraid at first it was going to be annoying to integrate a fourth tool, but it wound up sliding in very nicely as you can see. :)

I like the effect it has already had on these and the QAPI patches.

--js

author
#42 lore raw

PATCH v3 15/15 python/qemu: add qemu package itself to pipenv

In reply to John Snow

This adds the python qemu packages themselves to the pipenv manifest. 'pipenv sync' will create a virtual environment sufficient to use the SDK. 'pipenv sync --dev' will create a virtual environment sufficient to use and test the SDK (with pylint, mypy, isort, flake8, etc.)

The qemu packages are installed in 'editable' mode; all changes made to the python package inside the git tree will be reflected in the installed package without reinstallation. This includes changes made via git pull and so on.

---
 python/Pipfile      | 1 +
 python/Pipfile.lock | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
python/Pipfile +1 -0
index 75b96f29d8..214fb175e7 100644
@@ -10,6 +10,7 @@ mypy = ">=0.770"
 pylint = ">=2.6.0"
 
 [packages]
+qemu = {editable = true,path = "."}
 
 [requires]
 python_version = "3.6"
python/Pipfile.lock +7 -2
index 74563b444c..386ca54ea6 100644
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "b89c7a1b8a414f2a4cd708964123fb427d55419ee0b39e088bf2e7d4fbc11979"
+            "sha256": "e38d142c3fadc2f2ed849e86f7ebd14e25974dc12228751490aef5a9ee074f2f"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -15,7 +15,12 @@
             }
         ]
     },
-    "default": {},
+    "default": {
+        "qemu": {
+            "editable": true,
+            "path": "."
+        }
+    },
     "develop": {
         "astroid": {
             "hashes": [
Signature · 1 line
2.26.2
Reviewed-by Tested-by on v3 15/15
#43 lore raw

Re: [PATCH v3 15/15] python/qemu: add qemu package itself to pipenv

Quoted 5 lines · John Snow

This adds the python qemu packages themselves to the pipenv manifest. 'pipenv sync' will create a virtual environment sufficient to use the SDK. 'pipenv sync --dev' will create a virtual environment sufficient to use and test the SDK (with pylint, mypy, isort, flake8, etc.)

Quoted 7 lines

The qemu packages are installed in 'editable' mode; all changes made to the python package inside the git tree will be reflected in the installed package without reinstallation. This includes changes made via git pull and so on.

---

author
#44 lore raw

Re: [PATCH v3 15/15] python/qemu: add qemu package itself to pipenv

Quoted 11 lines · Cleber Rosa
Quoted 10 lines · John Snow

This adds the python qemu packages themselves to the pipenv manifest. 'pipenv sync' will create a virtual environment sufficient to use the SDK. 'pipenv sync --dev' will create a virtual environment sufficient to use and test the SDK (with pylint, mypy, isort, flake8, etc.)

The qemu packages are installed in 'editable' mode; all changes made to the python package inside the git tree will be reflected in the installed package without reinstallation. This includes changes made via git pull and so on.

Quoted 6 lines
Quoted 2 lines

---

Thanks! It looks like the major questions remaining are:

- Seriously, how should we lay the files out, and what should the package names be?
- Do we want to use something besides pipenv?

And from the CI series, a whole heap of other questions ;)

Thanks for taking a look and testing. It took a non-trivial amount of time to get all of this corralled together in precisely the right way to make it work in a variety of environments, so I am hoping it's "close" to something that's going to work for everyone.

--js

author
#45 lore raw
In reply to John Snow

Ping O:-)

Looking for feedback from at least Cleber and Eduardo before I barge ahead and send a PR to include this on master. Additional packaging and versioning feedback from Dan would be nice.

(I know we have a very busy two weeks here; I will continue pinging, but I have every intention of merging this prior to 5.2.)

--js

Quoted 156 lines · John Snow

Based-on: https://gitlab.com/jsnow/qemu/-/tree/python

This series factors the python/qemu directory as an installable package. It does not yet actually change the mechanics of how any other python source in the tree actually consumes it (yet), beyond the import path.

Quoted 1 line

The point of this series is primarily to formalize our dependencies on

mypy, flake8, isort, and pylint alongside versions that are known to work. It also adds explicitly pinned versions of these dependencies that should behave in a repeatable and known way for developers and CI environments both.

With the python tooling as a proper package, you can install this package in editable or production mode to a virtual environment, your local user environment, or your system packages. The primary benefit of this is to gain access to QMP tooling regardless of CWD, without needing to battle sys.path.

For example: when developing, you may go to qemu/python/ and invoke pipenv shell to activate a virtual environment that contains the qemu packages. This package will always reflect the current version of the source files in the tree. When you are finished, you can simply exit the shell to remove these packages from your python environment.

When not developing, you could install a version of this package to your environment outright to gain access to the QMP and QEMUMachine classes for lightweight scripting and testing by using pip: "pip install [--user] ."

Finally, this package is formatted in such a way that it COULD be uploaded to https://pypi.org/project/qemu and installed independently of qemu.git with pip install qemu, but that button remains unpushed.

TESTING THIS SERIES:

CD to qemu/python first, and then:

1. Try "pipenv shell" to get a venv with the package installed to it in editable mode. Ctrl+d exits this venv shell. While in this shell, any python script that uses "from qemu.[qmp|machine] import ..." should work correctly regardless of your CWD.

2. Try "pipenv sync --dev" to create/update the venv with the development packages without actually entering the venv. This should install isort, mypy, flake8 and pylint to the venv.

3. After the above sync, try "pipenv shell" again, and from the python project root, try any of the following:

- pylint qemu
- flake8 qemu
- isort -c qemu
- mypy qemu

4. Leave any venv you are in, and from the project root, try the following commands:

- pipenv run pylint qemu
- pipenv run flake8 qemu
- pipenv run isort -c qemu
- pipenv run mypy qemu

V3:
- Changed "qemu.core" to "qemu.qmp" and "qemu.machine",
Partly to accommodate forthcoming work which would benefit from a separate qemu.qmp namespace.
- Changed the initial version from 5.2.0a1 to 0.5.2.0a1, to allow for more rapid development while we smooth out the initial kinks.
- 001: Renamed patch title; differences implement the new names.
- 002: Readme changes for above.
- 003: Version change.
- 004: New readme for the new qmp directory.
- 006: A few more import exceptions for pylint, hopefully temporary.
- 009: Updated flake8 config comment to match qapi's
- 012: Added namespace_package configuration value

001/15:[down] 'python: create qemu packages'
002/15:[0009] [FC] 'python: add qemu package installer' 003/15:[0002] [FC] 'python: add VERSION file' 004/15:[0015] [FC] 'python: add directory structure README.rst files' 005/15:[----] [--] 'python: Add pipenv support' 006/15:[down] 'python: add pylint import exceptions' 007/15:[----] [--] 'python: move pylintrc into setup.cfg' 008/15:[----] [--] 'python: add pylint to pipenv' 009/15:[0002] [FC] 'python: move flake8 config to setup.cfg' 010/15:[----] [--] 'python: Add flake8 to pipenv' 011/15:[----] [-C] 'python: move mypy.ini into setup.cfg' 012/15:[0001] [FC] 'python: add mypy to pipenv' 013/15:[----] [--] 'python: move .isort.cfg into setup.cfg' 014/15:[----] [--] 'python/qemu: add isort to pipenv' 015/15:[----] [--] 'python/qemu: add qemu package itself to pipenv'

John Snow (15):
python: create qemu packages
python: add qemu package installer
python: add VERSION file
python: add directory structure README.rst files
python: Add pipenv support
python: add pylint import exceptions
python: move pylintrc into setup.cfg
python: add pylint to pipenv
python: move flake8 config to setup.cfg
python: Add flake8 to pipenv
python: move mypy.ini into setup.cfg
python: add mypy to pipenv
python: move .isort.cfg into setup.cfg python/qemu: add isort to pipenv python/qemu: add qemu package itself to pipenv

  python/PACKAGE.rst                          |  26 +++
  python/README.rst                           |  27 +++
  python/qemu/README.rst                      |   8 +
  python/qemu/machine/README.rst              |   9 +
  python/qemu/qmp/README.rst                  |   9 +
  python/Pipfile                              |  16 ++
  python/Pipfile.lock                         | 207 ++++++++++++++++++++
  python/VERSION                              |   1 +
  python/mypy.ini                             |   4 -
  python/qemu/.flake8                         |   2 -
  python/qemu/.isort.cfg                      |   7 -
  python/qemu/__init__.py                     |  11 --
  python/qemu/machine/__init__.py             |  44 +++++
  python/qemu/{ => machine}/accel.py          |   0
  python/qemu/{ => machine}/console_socket.py |   0
  python/qemu/{ => machine}/machine.py        |  16 +-
  python/qemu/{ => machine}/qtest.py          |   3 +-
  python/qemu/{qmp.py => qmp/__init__.py}     |  12 +-
  python/{qemu/pylintrc => setup.cfg}         |  67 ++++---
  python/setup.py                             |  23 +++
  tests/acceptance/boot_linux.py              |   3 +-
  tests/qemu-iotests/297                      |   2 +-
  tests/qemu-iotests/300                      |   4 +-
  tests/qemu-iotests/iotests.py               |   2 +-
  tests/vm/basevm.py                          |   3 +-
  25 files changed, 437 insertions(+), 69 deletions(-)

create mode 100644 python/PACKAGE.rst
create mode 100644 python/README.rst
create mode 100644 python/qemu/README.rst
create mode 100644 python/qemu/machine/README.rst create mode 100644 python/qemu/qmp/README.rst create mode 100644 python/Pipfile
create mode 100644 python/Pipfile.lock
create mode 100644 python/VERSION
delete mode 100644 python/mypy.ini
delete mode 100644 python/qemu/.flake8
delete mode 100644 python/qemu/.isort.cfg
delete mode 100644 python/qemu/__init__.py create mode 100644 python/qemu/machine/__init__.py rename python/qemu/{ => machine}/accel.py (100%) rename python/qemu/{ => machine}/console_socket.py (100%) rename python/qemu/{ => machine}/machine.py (98%) rename python/qemu/{ => machine}/qtest.py (98%) rename python/qemu/{qmp.py => qmp/__init__.py} (96%) rename python/{qemu/pylintrc => setup.cfg} (50%) mode change 100644 => 100755
create mode 100755 python/setup.py

#46 lore raw
Quoted 8 lines · John Snow

Ping O:-)

Looking for feedback from at least Cleber and Eduardo before I barge ahead and send a PR to include this on master. Additional packaging and versioning feedback from Dan would be nice.

(I know we have a very busy two weeks here; I will continue pinging, but I have every intention of merging this prior to 5.2.)

Too pythonic for me, so I'll defer that to Python experts.

It would be nice to have this in 5.2 indeed...

Regards,

Phil.