Skip to contentSkip to conversation

Python: Switch to externally hosted qemu.qmp dependency

RFC PATCH New John Snow 1 participant 10 messages Dec 17, 2021

lore
Share & tools
lore

John Snow

author
#0 lore raw

cover Python: Switch to externally hosted qemu.qmp dependency

Based-on: <[email protected]>

Hi, this series is part of an effort to publish the qemu.qmp package on PyPI. It is the last of three series to complete this work:

(1) Switch the new Async QMP library in to python/qemu/qmp
(2) Fork python/qemu/qmp out into its own repository, with updated GitLab CI/CD targets to build packages.
--> (3) Update qemu.git to install qemu.qmp from PyPI,
and then delete python/qemu/qmp.

This series is meant to apply to qemu.git after the standalone repository for qemu.qmp is established and the library is uploaded to PyPI.

However, I thought I'd share it now so that everyone can see what kind of work is involved post-split on the qemu.git end.

RFC notes:

- The version pinning and Pipenv patches will have to be redone later with proper versions and checksums and so on, but this is a workable example you can experiment with in the meantime.

- The testenv.py changes to use a VENV could be bolstered even further to use a checksum of requirements.txt to make that system a little bit more robust, but I wanted to share the WIP draft to get some early impressions.

... And that's it! These three series complete the split and leave us with a published QMP library on PyPI.

Happy New Years, everyone. See you in 2022 :)

John Snow (9):
Python: Update mypy dependency to >= 0.780
Python: update isort dependency scripts/qmp: Update 'qmp-shell' forwarder stub scripts/qmp: update remaining forwarder stubs scripts/qmp: delete qmp.py script stub
scripts: remove sys.path hacks for qemu/qemu.qmp iotests/testenv: initialize an iotests venv
Python: delete qemu.qmp
(WIP) Python: update Pipfile

 python/Pipfile.lock                    |  86 ++-
 python/qemu/qmp/__init__.py            |  59 --
 python/qemu/qmp/aqmp_tui.py            | 652 -----------------
 python/qemu/qmp/error.py               |  50 --
 python/qemu/qmp/events.py              | 717 -------------------
 python/qemu/qmp/legacy.py              | 319 ---------
 python/qemu/qmp/message.py             | 209 ------
 python/qemu/qmp/models.py              | 146 ----
 python/qemu/qmp/protocol.py            | 922 -------------------------
 python/qemu/qmp/py.typed               |   0
 python/qemu/qmp/qmp_client.py          | 655 ------------------
 python/qemu/qmp/qmp_shell.py           | 537 --------------
 python/qemu/qmp/util.py                | 217 ------
 python/qemu/utils/qom_fuse.py          |   1 -
 python/setup.cfg                       |  31 +-
 python/tests/protocol.py               | 583 ----------------
 scripts/device-crash-test              |  11 +-
 scripts/qmp/qemu-ga-client             |  40 +-
 scripts/qmp/qmp                        |  11 -
 scripts/qmp/qmp-shell                  |  39 +-
 scripts/qmp/qom-fuse                   |  40 +-
 scripts/qmp/qom-get                    |  40 +-
 scripts/qmp/qom-list                   |  40 +-
 scripts/qmp/qom-set                    |  40 +-
 scripts/qmp/qom-tree                   |  41 +-
 scripts/render_block_graph.py          |  13 +-
 scripts/simplebench/bench_block_job.py |  11 +-
 tests/qemu-iotests/requirements.txt    |   3 +
 tests/qemu-iotests/testenv.py          |  74 +-
 29 files changed, 412 insertions(+), 5175 deletions(-)
 delete mode 100644 python/qemu/qmp/__init__.py
 delete mode 100644 python/qemu/qmp/aqmp_tui.py
 delete mode 100644 python/qemu/qmp/error.py
 delete mode 100644 python/qemu/qmp/events.py
 delete mode 100644 python/qemu/qmp/legacy.py
 delete mode 100644 python/qemu/qmp/message.py
 delete mode 100644 python/qemu/qmp/models.py
 delete mode 100644 python/qemu/qmp/protocol.py
 delete mode 100644 python/qemu/qmp/py.typed
 delete mode 100644 python/qemu/qmp/qmp_client.py
 delete mode 100644 python/qemu/qmp/qmp_shell.py
 delete mode 100644 python/qemu/qmp/util.py
 delete mode 100644 python/tests/protocol.py
 delete mode 100755 scripts/qmp/qmp
 create mode 100644 tests/qemu-iotests/requirements.txt
Signature · 1 line
2.31.1
author
#1 lore raw

RFC PATCH 1/9 Python: Update mypy dependency to >= 0.780

A forthcoming commit makes use of the 'venv' package inside of iotests.py, which only has stubs available in the version of typeshed bundled with mypy 0.780 or greater, which increases our minimum dependency from 0.770.

---
 python/Pipfile.lock | 64 +++++++++++++++++++++++++++++++++------------
 python/setup.cfg    |  2 +-
 2 files changed, 49 insertions(+), 17 deletions(-)
python/Pipfile.lock +48 -16
index d2a7dbd88b..b60f3fa508 100644
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "784b327272db32403d5a488507853b5afba850ba26a5948e5b6a90c1baef2d9c"
+            "sha256": "b6cdebf9bfa760e4f8148949936aeeeed681ca910900e89be07e13424228f9a0"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -45,6 +45,14 @@
             "index": "pypi",
             "version": "==90.0"
         },
+        "backports.entry-points-selectable": {
+            "hashes": [
+                "sha256:7fceed9532a7aa2bd888654a7314f864a3c16a4e710b34a58cfc0f08114c663b",
+                "sha256:914b21a479fde881635f7af5adc7f6e38d6b274be32269070c53b698c60d5386"
+            ],
+            "markers": "python_version >= '2.7'",
+            "version": "==1.1.1"
+        },
         "distlib": {
             "hashes": [
                 "sha256:106fef6dc37dd8c0e2c0a60d3fca3e77460a48907f335fa28420463a6f799736",
@@ -136,23 +144,23 @@
         },
         "mypy": {
             "hashes": [
-                "sha256:15b948e1302682e3682f11f50208b726a246ab4e6c1b39f9264a8796bb416aa2",
-                "sha256:219a3116ecd015f8dca7b5d2c366c973509dfb9a8fc97ef044a36e3da66144a1",
-                "sha256:3b1fc683fb204c6b4403a1ef23f0b1fac8e4477091585e0c8c54cbdf7d7bb164",
-                "sha256:3beff56b453b6ef94ecb2996bea101a08f1f8a9771d3cbf4988a61e4d9973761",
-                "sha256:7687f6455ec3ed7649d1ae574136835a4272b65b3ddcf01ab8704ac65616c5ce",
-                "sha256:7ec45a70d40ede1ec7ad7f95b3c94c9cf4c186a32f6bacb1795b60abd2f9ef27",
-                "sha256:86c857510a9b7c3104cf4cde1568f4921762c8f9842e987bc03ed4f160925754",
-                "sha256:8a627507ef9b307b46a1fea9513d5c98680ba09591253082b4c48697ba05a4ae",
-                "sha256:8dfb69fbf9f3aeed18afffb15e319ca7f8da9642336348ddd6cab2713ddcf8f9",
-                "sha256:a34b577cdf6313bf24755f7a0e3f3c326d5c1f4fe7422d1d06498eb25ad0c600",
-                "sha256:a8ffcd53cb5dfc131850851cc09f1c44689c2812d0beb954d8138d4f5fc17f65",
-                "sha256:b90928f2d9eb2f33162405f32dde9f6dcead63a0971ca8a1b50eb4ca3e35ceb8",
-                "sha256:c56ffe22faa2e51054c5f7a3bc70a370939c2ed4de308c690e7949230c995913",
-                "sha256:f91c7ae919bbc3f96cd5e5b2e786b2b108343d1d7972ea130f7de27fdd547cf3"
+                "sha256:00cb1964a7476e871d6108341ac9c1a857d6bd20bf5877f4773ac5e9d92cd3cd",
+                "sha256:127de5a9b817a03a98c5ae8a0c46a20dc44442af6dcfa2ae7f96cb519b312efa",
+                "sha256:1f3976a945ad7f0a0727aafdc5651c2d3278e3c88dee94e2bf75cd3386b7b2f4",
+                "sha256:2f8c098f12b402c19b735aec724cc9105cc1a9eea405d08814eb4b14a6fb1a41",
+                "sha256:4ef13b619a289aa025f2273e05e755f8049bb4eaba6d703a425de37d495d178d",
+                "sha256:5d142f219bf8c7894dfa79ebfb7d352c4c63a325e75f10dfb4c3db9417dcd135",
+                "sha256:62eb5dd4ea86bda8ce386f26684f7f26e4bfe6283c9f2b6ca6d17faf704dcfad",
+                "sha256:64c36eb0936d0bfb7d8da49f92c18e312ad2e3ed46e5548ae4ca997b0d33bd59",
+                "sha256:75eed74d2faf2759f79c5f56f17388defd2fc994222312ec54ee921e37b31ad4",
+                "sha256:974bebe3699b9b46278a7f076635d219183da26e1a675c1f8243a69221758273",
+                "sha256:a5e5bb12b7982b179af513dddb06fca12285f0316d74f3964078acbfcf4c68f2",
+                "sha256:d31291df31bafb997952dc0a17ebb2737f802c754aed31dd155a8bfe75112c57",
+                "sha256:d3b4941de44341227ece1caaf5b08b23e42ad4eeb8b603219afb11e9d4cfb437",
+                "sha256:eadb865126da4e3c4c95bdb47fe1bb087a3e3ea14d39a3b13224b8a4d9f9a102"
             ],
             "index": "pypi",
-            "version": "==0.770"
+            "version": "==0.780"
         },
         "mypy-extensions": {
             "hashes": [
@@ -169,6 +177,14 @@
             "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
             "version": "==20.9"
         },
+        "platformdirs": {
+            "hashes": [
+                "sha256:367a5e80b3d04d2428ffa76d33f124cf11e8fff2acdaa9b43d545f5c7d661ef2",
+                "sha256:8868bbe3c3c80d42f20156f22e7131d2fb321f5bc86a2a345375c6481a67021d"
+            ],
+            "markers": "python_version >= '3.6'",
+            "version": "==2.4.0"
+        },
         "pluggy": {
             "hashes": [
                 "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0",
@@ -228,6 +244,14 @@
             "editable": true,
             "path": "."
         },
+        "setuptools": {
+            "hashes": [
+                "sha256:22c7348c6d2976a52632c67f7ab0cdf40147db7789f9aed18734643fe9cf3373",
+                "sha256:4ce92f1e1f8f01233ee9952c04f6b81d1e02939d6e1b488428154974a4d0783e"
+            ],
+            "markers": "python_version >= '3.6'",
+            "version": "==59.6.0"
+        },
         "six": {
             "hashes": [
                 "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
@@ -244,6 +268,14 @@
             "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
             "version": "==0.10.2"
         },
+        "tomli": {
+            "hashes": [
+                "sha256:05b6166bff487dc068d322585c7ea4ef78deed501cc124060e0f238e89a9231f",
+                "sha256:e3069e4be3ead9668e21cb9b074cd948f7b3113fd9c8bba083f48247aab8b11c"
+            ],
+            "markers": "python_version >= '3.6'",
+            "version": "==1.2.3"
+        },
         "tox": {
             "hashes": [
                 "sha256:c60692d92fe759f46c610ac04c03cf0169432d1ff8e981e8ae63e068d0954fc3",
python/setup.cfg +1 -1
index 911ae02de7..16f3236485 100644
@@ -40,7 +40,7 @@ devel =
     flake8 >= 3.6.0
     fusepy >= 2.0.4
     isort >= 5.1.2
-    mypy >= 0.770
+    mypy >= 0.780
     pylint >= 2.8.0
     tox >= 3.18.0
     urwid >= 2.1.2
Signature · 1 line
2.31.1
author
#2 lore raw

RFC PATCH 2/9 Python: update isort dependency

In reply to John Snow

A forthcoming commit that deletes python/qemu/qmp and begins using the dependency from PyPI instead changes the way older versions of isort process import priorities. Sticking to isort versions newer than 5.6.0 keep us consistent with the bleeding edge of isort releases.

---
 python/Pipfile.lock | 8 ++++----
 python/setup.cfg    | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
python/Pipfile.lock +4 -4
index b60f3fa508..2ca8a5c316 100644
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "b6cdebf9bfa760e4f8148949936aeeeed681ca910900e89be07e13424228f9a0"
+            "sha256": "2c01f0652bb57febf4590e9dd1344ddc4c3d2530b5df2ef909620876cfb9ab6d"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -101,11 +101,11 @@
         },
         "isort": {
             "hashes": [
-                "sha256:408e4d75d84f51b64d0824894afee44469eba34a4caee621dc53799f80d71ccc",
-                "sha256:64022dea6a06badfa09b300b4dfe8ba968114a737919e8ed50aea1c288f078aa"
+                "sha256:20544581447ccb6a80940c5cace8cbc32c0f58d82d67d34a182950fe7b93321b",
+                "sha256:ef200cc0ebd896c5bb0d7da9fd390392648c56c2099c2d2ff940ac94739f62aa"
             ],
             "index": "pypi",
-            "version": "==5.1.2"
+            "version": "==5.6.0"
         },
         "lazy-object-proxy": {
             "hashes": [
python/setup.cfg +1 -1
index 16f3236485..7907994c5a 100644
@@ -39,7 +39,7 @@ devel =
     avocado-framework >= 90.0
     flake8 >= 3.6.0
     fusepy >= 2.0.4
-    isort >= 5.1.2
+    isort >= 5.6.0
     mypy >= 0.780
     pylint >= 2.8.0
     tox >= 3.18.0
Signature · 1 line
2.31.1
author
#3 lore raw

RFC PATCH 3/9 scripts/qmp: Update 'qmp-shell' forwarder stub

In reply to John Snow

The text here is slightly different than the text in other forwarder stubs in this directory, because the only dependency needed here is outside of the QEMU source tree entirely.

---
 scripts/qmp/qmp-shell | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
scripts/qmp/qmp-shell +34 -5
index 4a20f97db7..1d30425547 100755
@@ -1,11 +1,40 @@
 #!/usr/bin/env python3
 
-import os
 import sys
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.qmp import qmp_shell
+try:
+    from qemu.qmp import qmp_shell
+    _HAVE_QMP = True
+except ModuleNotFoundError:
+    _HAVE_QMP = False
 
+bold = "\033[1m"
+end = "\033[0m"
+cmd = 'qmp-shell'
 
-if __name__ == '__main__':
-    qmp_shell.main()
+EMSG = f"""
+{bold}'{sys.argv[0]}' is just a forwarder, and is not necessary.{end}
+
+However, the 'qemu.qmp' package is not installed.
+
+To use the '{cmd}' command directly from the installed package,
+install the python package and then add (for a --user install)
+~/.local/bin/ to $PATH if it isn't already. Then, you should have access
+to the '{cmd}' command.
+
+For more information, please see ../../python/README.rst.
+
+maybe:
+ > pip3 install --user qemu.qmp
+ > export PATH=$PATH:~/.local/bin/
+ > {cmd} --help
+
+Alternatively, after installing the qemu.qmp package, this forwarder
+will work again. However, it will eventually be removed. I apologize for
+the inconvenience!"""
+
+if not _HAVE_QMP:
+    print(EMSG, file=sys.stderr)
+    sys.exit(1)
+
+qmp_shell.main()
Signature · 1 line
2.31.1
author
#4 lore raw

RFC PATCH 4/9 scripts/qmp: update remaining forwarder stubs

In reply to John Snow

The text for each forwarder is largely the same, though the qom-fuse stub instructs users to install the optional fuse dependency for the qemu package.

---
 scripts/qmp/qemu-ga-client | 40 ++++++++++++++++++++++++++++++++-----
 scripts/qmp/qom-fuse       | 40 ++++++++++++++++++++++++++++++++-----
 scripts/qmp/qom-get        | 40 ++++++++++++++++++++++++++++++++-----
 scripts/qmp/qom-list       | 40 ++++++++++++++++++++++++++++++++-----
 scripts/qmp/qom-set        | 40 ++++++++++++++++++++++++++++++++-----
 scripts/qmp/qom-tree       | 41 +++++++++++++++++++++++++++++++++-----
 6 files changed, 211 insertions(+), 30 deletions(-)
scripts/qmp/qemu-ga-client +35 -5
index 56edd0234a..f9c4087a56 100755
@@ -1,11 +1,41 @@
 #!/usr/bin/env python3
 
-import os
 import sys
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.utils import qemu_ga_client
+try:
+    from qemu.utils import qemu_ga_client
+    _HAVE_DEPS = True
+except ModuleNotFoundError:
+    _HAVE_DEPS = False
 
+bold = "\033[1m"
+end = "\033[0m"
+cmd = 'qemu-ga-client'
 
-if __name__ == '__main__':
-    sys.exit(qemu_ga_client.main())
+EMSG = f"""
+{bold}'{sys.argv[0]}' is just a forwarder, and is not necessary.{end}
+
+However, there are missing dependencies to run this script.
+
+To use the '{cmd}' command directly from the installed package,
+install the python package and then add (for a --user install)
+~/.local/bin/ to $PATH if it isn't already. Then, you should have access
+to the '{cmd}' command.
+
+For more information, please see ../../python/README.rst.
+
+maybe:
+ > cd ../../python/
+ > pip3 install --user .
+ > export PATH=$PATH:~/.local/bin/
+ > {cmd} --help
+
+Alternatively, after installing the qemu package, this forwarder
+will work again. However, it will eventually be removed. I apologize for
+the inconvenience!"""
+
+if not _HAVE_DEPS:
+    print(EMSG, file=sys.stderr)
+    sys.exit(1)
+
+sys.exit(qemu_ga_client.main())
scripts/qmp/qom-fuse +35 -5
index d453807b27..e9edf01550 100755
@@ -1,11 +1,41 @@
 #!/usr/bin/env python3
 
-import os
 import sys
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.utils.qom_fuse import QOMFuse
+try:
+    from qemu.utils.qom_fuse import QOMFuse
+    _HAVE_DEPS = True
+except ModuleNotFoundError:
+    _HAVE_DEPS = False
 
+bold = "\033[1m"
+end = "\033[0m"
+cmd = 'qom-fuse'
 
-if __name__ == '__main__':
-    sys.exit(QOMFuse.entry_point())
+EMSG = f"""
+{bold}'{sys.argv[0]}' is just a forwarder, and is not necessary.{end}
+
+However, there are missing dependencies to run this script.
+
+To use the '{cmd}' command directly from the installed package,
+install the python package and then add (for a --user install)
+~/.local/bin/ to $PATH if it isn't already. Then, you should have access
+to the '{cmd}' command.
+
+For more information, please see ../../python/README.rst.
+
+maybe:
+ > cd ../../python/
+ > pip3 install --user .[fuse]
+ > export PATH=$PATH:~/.local/bin/
+ > {cmd} --help
+
+Alternatively, after installing the qemu[fuse] package, this forwarder
+will work again. However, it will eventually be removed. I apologize for
+the inconvenience!"""
+
+if not _HAVE_DEPS:
+    print(EMSG, file=sys.stderr)
+    sys.exit(1)
+
+sys.exit(QOMFuse.entry_point())
scripts/qmp/qom-get +35 -5
index 04ebe052e8..9fa3e1c270 100755
@@ -1,11 +1,41 @@
 #!/usr/bin/env python3
 
-import os
 import sys
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.utils.qom import QOMGet
+try:
+    from qemu.utils.qom import QOMGet
+    _HAVE_DEPS = True
+except ModuleNotFoundError:
+    _HAVE_DEPS = False
 
+bold = "\033[1m"
+end = "\033[0m"
+cmd = 'qom-get'
 
-if __name__ == '__main__':
-    sys.exit(QOMGet.entry_point())
+EMSG = f"""
+{bold}'{sys.argv[0]}' is just a forwarder, and is not necessary.{end}
+
+However, there are missing dependencies to run this script.
+
+To use the '{cmd}' command directly from the installed package,
+install the python package and then add (for a --user install)
+~/.local/bin/ to $PATH if it isn't already. Then, you should have access
+to the '{cmd}' command.
+
+For more information, please see ../../python/README.rst.
+
+maybe:
+ > cd ../../python/
+ > pip3 install --user .
+ > export PATH=$PATH:~/.local/bin/
+ > {cmd} --help
+
+Alternatively, after installing the qemu package, this forwarder
+will work again. However, it will eventually be removed. I apologize for
+the inconvenience!"""
+
+if not _HAVE_DEPS:
+    print(EMSG, file=sys.stderr)
+    sys.exit(1)
+
+sys.exit(QOMGet.entry_point())
scripts/qmp/qom-list +35 -5
index 853b85a8d3..6c6e4074e9 100755
@@ -1,11 +1,41 @@
 #!/usr/bin/env python3
 
-import os
 import sys
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.utils.qom import QOMList
+try:
+    from qemu.utils.qom import QOMList
+    _HAVE_DEPS = True
+except ModuleNotFoundError:
+    _HAVE_DEPS = False
 
+bold = "\033[1m"
+end = "\033[0m"
+cmd = 'qom-list'
 
-if __name__ == '__main__':
-    sys.exit(QOMList.entry_point())
+EMSG = f"""
+{bold}'{sys.argv[0]}' is just a forwarder, and is not necessary.{end}
+
+However, there are missing dependencies to run this script.
+
+To use the '{cmd}' command directly from the installed package,
+install the python package and then add (for a --user install)
+~/.local/bin/ to $PATH if it isn't already. Then, you should have access
+to the '{cmd}' command.
+
+For more information, please see ../../python/README.rst.
+
+maybe:
+ > cd ../../python/
+ > pip3 install --user .
+ > export PATH=$PATH:~/.local/bin/
+ > {cmd} --help
+
+Alternatively, after installing the qemu package, this forwarder
+will work again. However, it will eventually be removed. I apologize for
+the inconvenience!"""
+
+if not _HAVE_DEPS:
+    print(EMSG, file=sys.stderr)
+    sys.exit(1)
+
+sys.exit(QOMList.entry_point())
scripts/qmp/qom-set +35 -5
index 06820feec4..bcdee0e2d5 100755
@@ -1,11 +1,41 @@
 #!/usr/bin/env python3
 
-import os
 import sys
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.utils.qom import QOMSet
+try:
+    from qemu.utils.qom import QOMSet
+    _HAVE_DEPS = True
+except ModuleNotFoundError:
+    _HAVE_DEPS = False
 
+bold = "\033[1m"
+end = "\033[0m"
+cmd = 'qom-set'
 
-if __name__ == '__main__':
-    sys.exit(QOMSet.entry_point())
+EMSG = f"""
+{bold}'{sys.argv[0]}' is just a forwarder, and is not necessary.{end}
+
+However, there are missing dependencies to run this script.
+
+To use the '{cmd}' command directly from the installed package,
+install the python package and then add (for a --user install)
+~/.local/bin/ to $PATH if it isn't already. Then, you should have access
+to the '{cmd}' command.
+
+For more information, please see ../../python/README.rst.
+
+maybe:
+ > cd ../../python/
+ > pip3 install --user .
+ > export PATH=$PATH:~/.local/bin/
+ > {cmd} --help
+
+Alternatively, after installing the qemu package, this forwarder
+will work again. However, it will eventually be removed. I apologize for
+the inconvenience!"""
+
+if not _HAVE_DEPS:
+    print(EMSG, file=sys.stderr)
+    sys.exit(1)
+
+sys.exit(QOMSet.entry_point())
scripts/qmp/qom-tree +36 -5

47 lines not on this page · raw message

Signature · 1 line
2.31.1
author
#5 lore raw

RFC PATCH 5/9 scripts/qmp: delete qmp.py script stub

In reply to John Snow

It's been stubbed out for quite some time and nobody yelped, so out it goes.

---
 scripts/qmp/qmp | 11 -----------
 1 file changed, 11 deletions(-)
 delete mode 100755 scripts/qmp/qmp
scripts/qmp/qmp deleted +0 -11
deleted file mode 100755
index 0f12307c87..0000000000
@@ -1,11 +0,0 @@
-#!/usr/bin/env python3
-
-import sys
-
-print('''This unmaintained and undocumented script was removed in preference
-for qmp-shell. The assumption is that most users are using either
-qmp-shell, socat, or pasting/piping JSON into stdio. The duplication of
-facilities here is unwanted, and the divergence of syntax harmful.''',
-      file=sys.stderr)
-
-sys.exit(1)
Signature · 1 line
2.31.1
author
#6 lore raw

RFC PATCH 6/9 scripts: remove sys.path hacks for qemu/qemu.qmp

In reply to John Snow

qemu.qmp can be found via the package index now. Direct the user to just install the package. When utilities from 'qemu' are needed, direct the user to install the package from that directory instead, which will pull in the 'qemu.qmp' package as a dependency.

---
 scripts/device-crash-test              | 11 ++++++++---
 scripts/render_block_graph.py          | 13 ++++++++++---
 scripts/simplebench/bench_block_job.py | 11 ++++++++---
 3 files changed, 26 insertions(+), 9 deletions(-)
scripts/device-crash-test +8 -3
index 4bfc68c008..5d21b6dfb1 100755
@@ -34,9 +34,14 @@ import random
 import argparse
 from itertools import chain
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python'))
-from qemu.machine import QEMUMachine
-from qemu.qmp import ConnectError
+try:
+    from qemu.machine import QEMUMachine
+    from qemu.qmp import ConnectError
+except ModuleNotFoundError:
+    target = os.path.realpath(__file__ + '/../../python')
+    print("script dependencies not found.")
+    print(f'try: pushd "{target}" && pip3 install [--user] . && popd')
+    sys.exit(1)
 
 logger = logging.getLogger('device-crash-test')
 dbg = logger.debug
scripts/render_block_graph.py +10 -3
index 26f43fef27..e7b89314ff 100755
@@ -24,9 +24,16 @@
 import json
 from graphviz import Digraph
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python'))
-from qemu.qmp import QMPError
-from qemu.qmp.legacy import QEMUMonitorProtocol
+try:
+    from qemu.qmp import QMPError
+    from qemu.qmp.legacy import QEMUMonitorProtocol
+except ModuleNotFoundError:
+    print(
+        "qemu.qmp python package not found.",
+        "try: pip3 install [--user] qemu.qmp",
+        sep='\n', file=sys.stderr
+    )
+    sys.exit(1)
 
 
 def perm(arr):
scripts/simplebench/bench_block_job.py +8 -3
index 56191db44b..ccb2f9ded1 100755
@@ -25,9 +25,14 @@
 import socket
 import json
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.machine import QEMUMachine
-from qemu.qmp import ConnectError
+try:
+    from qemu.machine import QEMUMachine
+    from qemu.qmp import ConnectError
+except ModuleNotFoundError:
+    target = os.path.realpath(__file__ + '/../../../python')
+    print("script dependencies not found.")
+    print(f'try: pushd "{target}" && pip3 install [--user] . && popd')
+    sys.exit(1)
 
 
 def bench_block_job(cmd, cmd_args, qemu_args):
Signature · 1 line
2.31.1
author
#7 lore raw

RFC PATCH 7/9 iotests/testenv: initialize an iotests venv

In reply to John Snow

Create a venv automatically when running iotests and install the QEMU namespace package to it, which will also pull in qemu.qmp from PyPI.

The venv created will always use the same python binary as the one used to launch the check process. Assuming that care is taken to run 'check' with the python executable specified by the QEMU configure script, this venv will use that same python binary.

When re-running the script with a different python binary, the virtual environment will be re-created to match.

Packages that need to be installed for successful runs of iotests are specified in requirements.txt. The "magic" here is that we can specify the in-tree repository for the 'qemu' package, whose own requirements (in python/setup.cfg) specify the now out-of-tree 'qemu.qmp' package.

As a bonus, iotest 297 is now easier to run than before.

---
 tests/qemu-iotests/requirements.txt |  3 ++
 tests/qemu-iotests/testenv.py       | 74 ++++++++++++++++++++++++++---
 2 files changed, 70 insertions(+), 7 deletions(-)
 create mode 100644 tests/qemu-iotests/requirements.txt
tests/qemu-iotests/requirements.txt new file +3 -0
new file mode 100644
index 0000000000..923e6b26a3
@@ -0,0 +1,3 @@
+../../python
+mypy >= 0.770
+pylint >= 2.8.0
tests/qemu-iotests/testenv.py +67 -7

120 lines not on this page · raw message

Signature · 1 line
2.31.1
author
#8 lore raw

RFC PATCH 8/9 Python: delete qemu.qmp

In reply to John Snow

qemu.qmp has been forked out into its own repository and can be installed independently, so it should no longer be included here in this tree.

---

Note: without re-locking Pipfile.lock, the CI venv won't actually have that dependency installed. The next patch adds it for the sake of the CI system passing, but a non-RFC version of this will want to pin qemu.qmp to 0.0.1 (which doesn't exist yet!) and then re-lock Pipfile.lock, and squash the following commit into this one.

---
 python/qemu/qmp/__init__.py   |  59 ---
 python/qemu/qmp/aqmp_tui.py   | 652 ------------------------
 python/qemu/qmp/error.py      |  50 --
 python/qemu/qmp/events.py     | 717 --------------------------
 python/qemu/qmp/legacy.py     | 319 ------------
 python/qemu/qmp/message.py    | 209 --------
 python/qemu/qmp/models.py     | 146 ------
 python/qemu/qmp/protocol.py   | 922 ----------------------------------
 python/qemu/qmp/py.typed      |   0
 python/qemu/qmp/qmp_client.py | 655 ------------------------
 python/qemu/qmp/qmp_shell.py  | 537 --------------------
 python/qemu/qmp/util.py       | 217 --------
 python/qemu/utils/qom_fuse.py |   1 -
 python/setup.cfg              |  27 +-
 python/tests/protocol.py      | 583 ---------------------
 15 files changed, 2 insertions(+), 5092 deletions(-)
 delete mode 100644 python/qemu/qmp/__init__.py
 delete mode 100644 python/qemu/qmp/aqmp_tui.py
 delete mode 100644 python/qemu/qmp/error.py
 delete mode 100644 python/qemu/qmp/events.py
 delete mode 100644 python/qemu/qmp/legacy.py
 delete mode 100644 python/qemu/qmp/message.py
 delete mode 100644 python/qemu/qmp/models.py
 delete mode 100644 python/qemu/qmp/protocol.py
 delete mode 100644 python/qemu/qmp/py.typed
 delete mode 100644 python/qemu/qmp/qmp_client.py
 delete mode 100644 python/qemu/qmp/qmp_shell.py
 delete mode 100644 python/qemu/qmp/util.py
 delete mode 100644 python/tests/protocol.py
python/qemu/qmp/__init__.py deleted +0 -59
deleted file mode 100644
index a19868b13d..0000000000
@@ -1,59 +0,0 @@
-"""
-QEMU Monitor Protocol (QMP) development library & tooling.
-
-This package provides a fairly low-level class for communicating
-asynchronously with QMP protocol servers, as implemented by QEMU, the
-QEMU Guest Agent, and the QEMU Storage Daemon.
-
-`QMPClient` provides the main functionality of this package. All errors
-raised by this library derive from `QMPError`, see `qmp.error` for
-additional detail. See `qmp.events` for an in-depth tutorial on
-managing QMP events.
-"""
-
-# Copyright (C) 2020, 2021 John Snow for Red Hat, Inc.
-#
-# Authors:
-#  John Snow <[email protected]>
-#
-# Based on earlier work by Luiz Capitulino <[email protected]>.
-#
-# This work is licensed under the terms of the GNU GPL, version 2.  See
-# the COPYING file in the top-level directory.
-
-import logging
-
-from .error import QMPError
-from .events import EventListener
-from .message import Message
-from .protocol import (
-    ConnectError,
-    Runstate,
-    SocketAddrT,
-    StateError,
-)
-from .qmp_client import ExecInterruptedError, ExecuteError, QMPClient
-
-
-# Suppress logging unless an application engages it.
-logging.getLogger('qemu.qmp').addHandler(logging.NullHandler())
-
-
-# The order of these fields impact the Sphinx documentation order.
-__all__ = (
-    # Classes, most to least important
-    'QMPClient',
-    'Message',
-    'EventListener',
-    'Runstate',
-
-    # Exceptions, most generic to most explicit
-    'QMPError',
-    'StateError',
-    'ConnectError',
-    'ExecuteError',
-    'ExecInterruptedError',
-
-    # Type aliases
-    'SocketAddrT',
-)
python/qemu/qmp/aqmp_tui.py deleted +0 -652

652 lines not on this page · raw message

python/qemu/qmp/error.py deleted +0 -50

50 lines not on this page · raw message

python/qemu/qmp/events.py deleted +0 -717

717 lines not on this page · raw message

python/qemu/qmp/legacy.py deleted +0 -319

319 lines not on this page · raw message

python/qemu/qmp/message.py deleted +0 -209

209 lines not on this page · raw message

python/qemu/qmp/models.py deleted +0 -146

146 lines not on this page · raw message

python/qemu/qmp/protocol.py deleted +0 -922

848 lines not on this page · raw message

python/qemu/qmp/py.typed deleted +0 -0
deleted file mode 100644
index e69de29bb2..0000000000
python/qemu/qmp/qmp_client.py deleted +0 -655

655 lines not on this page · raw message

python/qemu/qmp/qmp_shell.py deleted +0 -537

537 lines not on this page · raw message

python/qemu/qmp/util.py deleted +0 -217

217 lines not on this page · raw message

python/qemu/utils/qom_fuse.py +0 -1
index 8dcd59fcde..4877e4b78f 100644

Lines of this file are not shown. View the raw message.

python/setup.cfg +2 -25
index 7907994c5a..64ec4e7c14 100644

Lines of this file are not shown. View the raw message.

python/tests/protocol.py deleted +0 -583

583 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.31.1

Part of the diff is not shown here. View the raw message.

author
#9 lore raw

RFC PATCH 9/9 (WIP) Python: update Pipfile

In reply to John Snow

With qemu.qmp gone, we'll need to install it to the Pipenv so that those tests pass.

Important; if this still fails, check that you don't have any stale files in python/qemu/qmp/ which could interfere with this process.

---
 python/Pipfile.lock | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
python/Pipfile.lock +17 -1
index 2ca8a5c316..d08b5affa5 100644
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "2c01f0652bb57febf4590e9dd1344ddc4c3d2530b5df2ef909620876cfb9ab6d"
+            "sha256": "a844774b45a632621cae9259c187ecfed7b6336638366883acd3d2f46fcc2fa2"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -19,6 +19,14 @@
         "qemu": {
             "editable": true,
             "path": "."
+        },
+        "qemu.qmp": {
+            "hashes": [
+                "sha256:6ae30a8bb9ca9687c59ed3bfec6ff12d32c7d268227e5812f7e42af625687e45",
+                "sha256:829d1b4c3c35cbc3781839338040adbd11c6be0a9d15c6a433323ebb795cfae6"
+            ],
+            "index": "pypi",
+            "version": "==0.0.0a0"
         }
     },
     "develop": {
@@ -244,6 +252,14 @@
             "editable": true,
             "path": "."
         },
+        "qemu.qmp": {
+            "hashes": [
+                "sha256:6ae30a8bb9ca9687c59ed3bfec6ff12d32c7d268227e5812f7e42af625687e45",
+                "sha256:829d1b4c3c35cbc3781839338040adbd11c6be0a9d15c6a433323ebb795cfae6"
+            ],
+            "index": "pypi",
+            "version": "==0.0.0a0"
+        },
         "setuptools": {
             "hashes": [
                 "sha256:22c7348c6d2976a52632c67f7ab0cdf40147db7789f9aed18734643fe9cf3373",
Signature · 1 line
2.31.1