python: create installable package
v6 cover python: create installable package
Based-on: <[email protected]>
CI: https://gitlab.com/jsnow/qemu/-/pipelines/302010131
GitLab: https://gitlab.com/jsnow/qemu/-/tree/python-package-mk3
MR: https://gitlab.com/jsnow/qemu/-/merge_requests/4
I invite you to leave review comments on my mock merge request on gitlab, submitted against my own mirror. I will, as always, also respond to feedback on-list.
ABOUT
=====
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 -- some import statements change in a few places.
RATIONALE
=========
The primary motivation of this series is primarily to formalize our dependencies on mypy, flake8, isort, and pylint alongside versions that are known to work. It does this using the setup.cfg and setup.py files. It also adds explicitly pinned versions (using Pipfile.lock) of these dependencies that should behave in a repeatable and known way for developers and CI environments both. Lastly, it enables those CI checks such that we can enforce Python coding quality checks via the CI tests.
An auxiliary motivation is that 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* and this series *will not* cause any such releases. We have time to debate finer points like API guarantees and versioning even after this series is merged.
Other bits of interest
----------------------
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 (and confounding other python analysis tools).
For example: when developing, you may go to qemu/python/ and run make venv followed by pipenv shell to activate a virtual environment that contains the qemu python packages. These packages will always reflect the current version of the source files in the tree. When you are finished, you can simply exit the shell (^d) 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] ."
TESTING THIS SERIES
===================
First of all, nothing should change. Without any intervention, everything should behave exactly as it did before. The only new information here comes from how to interact with and run the linters that will be enforcing code quality standards in this subdirectory.
There are various invocations available that will test subtly different combinations using subtly different environments. I am assuming some light knowledge of Python environments and installing Python packages here. If you have questions, I would be delighted to answer them.
To test the new tests, CD to ./python/ first, and then:
0. Try "make" or "make help" to get a sense of this series.
1. Try "make venv && 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 where the script is, or what your CWD is.
This will pull some packages from PyPI and install them into the virtual environment, leaving your normal environment untouched.
You will need Python 3.6 and pipenv installed on your system to do this step. For Fedora: "dnf install python36 pipenv" will do the trick. If you don't have this, skip down to #4 and onwards.
2. Try "make check" while still in the shell to run the Python linters using the venv built in the previous step. This will run avocado, which will in turn execute mypy, flake8, isort and pylint with the correct arguments.
3. Having exited the shell from above, try "make venv-check". This will create and update the venv if needed, then run 'make check' within the context of that shell. It should pass as long as the above did. You should be able to run "make distclean" prior to running "make venv-check" and have the entire process work start to finish.
4. Still outside of the venv, you may try running "make check". This will not install anything, but unless you have the right Python dependencies installed, these tests may fail for you. You might try using "pip install --user .[devel]" to install the development packages needed to run the tests successfully to your local user's python environment. Once done, you will probably want to "pip uninstall qemu" to remove the qemu packages to avoid them interfering with other things.
5. "make distclean" will delete the venv and any temporary files that may have been created by packaging, installing, testing, etc.
6. You may also (if you wish) create your own environment using a Python other than 3.6, bypassing pipenv. This may be useful for environments in which you simply do not have Python 3.6 readily available, or explicitly wish to test against a different version.
Using the Python of your choice:
- > make distclean (Remove the .venv, if you created one.)
- > /usr/bin/python3.9 -m venv .venv
- > source .venv/bin/activate (or activate.[fish|csh])
- `> make develop` (Installs linter deps to this venv) - `> make check` (Runs tests using current env) - `> deactivate` (Leaves the venv)
This *should* pass, and if it doesn't, it's a bug. Due to dependencies changing like shifting sands, it's impossible to promise support for every last combination of dependency and python version. This is why the "make venv-check" target uses Python 3 and a very explicit set of packages instead. Still, this form *should* pass.
7. If you are running Fedora or a distro that packages multiple Python versions, you can try running "make check-tox" to run the linters under all Python versions from Python 3.6 to 3.9. This will create a series of virtual environments under the .tox folder, leaving your existing environment unscathed. This should pass, provided you have the requisite Python versions on hand. When you are done, "make distclean" should remove any testing files.
CHANGELOG
=========
V6
--
``` 001/25:[----] [--] 'iotests/297: add --namespace-packages to mypy arguments' 002/25:[----] [-C] 'python: create qemu packages' 003/25:[----] [--] 'python: create utils sub-package' 004/25:[0005] [FC] 'python: add qemu package installer' 005/25:[0002] [FC] 'python: add VERSION file' 006/25:[----] [--] 'python: add directory structure README.rst files' 007/25:[down] 'python: add MANIFEST.in' 008/25:[0001] [FC] 'python: Add pipenv support' 009/25:[----] [--] 'python: add pylint import exceptions' 010/25:[----] [--] 'python: move pylintrc into setup.cfg' 011/25:[0083] [FC] 'python: add pylint to pipenv' 012/25:[----] [--] 'python: move flake8 config to setup.cfg' 013/25:[----] [--] 'python: add excluded dirs to flake8 config' 014/25:[0038] [FC] 'python: Add flake8 to pipenv' 015/25:[----] [--] 'python: move mypy.ini into setup.cfg' 016/25:[0050] [FC] 'python: add mypy to pipenv' 017/25:[----] [--] 'python: move .isort.cfg into setup.cfg' 018/25:[0006] [FC] 'python/qemu: add isort to pipenv' 019/25:[0004] [FC] 'python/qemu: add qemu package itself to pipenv' 020/25:[0014] [FC] 'python: add devel package requirements to setuptools' 021/25:[down] 'python: add avocado-framework and tests' 022/25:[0015] [FC] 'python: add Makefile for some common tasks' 023/25:[0018] [FC] 'python: add .gitignore' 024/25:[0004] [FC] 'gitlab: add python linters to CI' 025/25:[down] 'python: add tox support' ```
- 04: Changed maintainer blurb in PACKAGE.rst
- 05: VERSION is now 0.6.1a0
- 07: New, needed for both tox and using Pipenv to install the qemu package(s) in editable mode.
- 08: Add README entries explaining the purpose of the pipenv files.
- 11: pylint dependency was bumped to 2.7.0.
- 14: pipenv changes.
- 16: pipenv changes.
- 18: isort pinned at >= 5.1.2 now; see commit message.
- 19: pipenv changes.
- 20: Context differences from isort, pylint, and pipenv changes.
- 22:
- Add 'make develop'
- Add more README.rst entries.
- Change pytest invocation to avocado.
- 23:
- Add comments to gitignore, split ignores out by function/category
- Ignore vscode files. (I like vscode now!)
- 24: Use the 'needs' feature of Gitlab CI and move the test to 'test' stage
STATUS
=======
``` + [01] iotests-297-add-namespace # [RB] CR [SOB] JS + [02] python-create-qemu-packages # [SOB] JS + [03] python-create-utils-sub # [SOB] JS + [04] python-add-qemu-package # [SOB] JS + [05] python-add-version-file # [RB] CR [SOB] JS + [06] python-add-directory-structure # [SOB] JS + [07] python-add-manifest-in # [SOB] JS + [08] python-add-pipenv-support # [RB] CR [SOB] JS + [09] python-add-pylint-import # [RB] CR [SOB] JS + [10] python-move-pylintrc-into # [RB] CR [TB] CR [SOB] JS + [11] python-add-pylint-to-pipenv # [SOB] JS + [12] python-move-flake8-config-to # [RB] CR [SOB] JS + [13] python-add-excluded-dirs-to # [SOB] JS + [14] python-add-flake8-to-pipenv # [RB] CR [TB] CR [SOB] JS + [15] python-move-mypy-ini-into # [SOB] JS + [16] python-add-mypy-to-pipenv # [RB] CR [TB] CR [SOB] JS + [17] python-move-isort-cfg-into # [RB] CR [SOB] JS + [18] python-qemu-add-isort-to # [SOB] JS + [19] python-qemu-add-qemu-package # [RB] CR [TB] CR [SOB] JS + [20] python-add-devel-package # [SOB] JS + [21] python-add-avocado-framework # [SOB] JS + [22] python-add-makefile-for-some # [SOB] JS + [23] python-add-gitignore # [SOB] JS + [24] gitlab-add-python-linters-to # [SOB] JS > [25] python-add-tox-support # [SOB] JS ```
John Snow (25):
iotests/297: add --namespace-packages to mypy arguments
python: create qemu packages
python: create utils sub-package
python: add qemu package installer
python: add VERSION file
python: add directory structure README.rst files
python: add MANIFEST.in
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 excluded dirs to flake8 config
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: add devel package requirements to setuptools
python: add avocado-framework and tests
python: add Makefile for some common tasks
python: add .gitignore
gitlab: add python linters to CI
python: add tox support
python/PACKAGE.rst | 33 +++
python/README.rst | 53 +++++
python/qemu/README.rst | 8 +
python/qemu/machine/README.rst | 9 +
python/qemu/qmp/README.rst | 9 +
python/qemu/utils/README.rst | 7 +
.gitlab-ci.yml | 12 +
python/.gitignore | 20 ++
python/MANIFEST.in | 2 +
python/Makefile | 47 ++++
python/Pipfile | 13 ++
python/Pipfile.lock | 231 ++++++++++++++++++++
python/VERSION | 1 +
python/avocado.cfg | 10 +
python/mypy.ini | 4 -
python/qemu/.flake8 | 2 -
python/qemu/.isort.cfg | 7 -
python/qemu/__init__.py | 11 -
python/qemu/machine/__init__.py | 36 +++
python/qemu/{ => machine}/console_socket.py | 0
python/qemu/{ => machine}/machine.py | 16 +-
python/qemu/{ => machine}/qtest.py | 3 +-
python/qemu/pylintrc | 58 -----
python/qemu/{qmp.py => qmp/__init__.py} | 12 +-
python/qemu/utils/__init__.py | 23 ++
python/qemu/{ => utils}/accel.py | 0
python/setup.cfg | 79 +++++++
python/setup.py | 23 ++
python/tests/flake8.sh | 2 +
python/tests/isort.sh | 2 +
python/tests/mypy.sh | 2 +
python/tests/pylint.sh | 2 +
python/tox.ini | 13 ++
tests/acceptance/avocado_qemu/__init__.py | 4 +-
tests/acceptance/virtio-gpu.py | 2 +-
tests/docker/dockerfiles/fedora.docker | 2 +
tests/qemu-iotests/297 | 1 +
tests/qemu-iotests/300 | 4 +-
tests/qemu-iotests/iotests.py | 2 +-
tests/vm/aarch64vm.py | 2 +-
tests/vm/basevm.py | 2 +-
41 files changed, 672 insertions(+), 97 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/qemu/utils/README.rst
create mode 100644 python/.gitignore
create mode 100644 python/MANIFEST.in
create mode 100644 python/Makefile
create mode 100644 python/Pipfile
create mode 100644 python/Pipfile.lock
create mode 100644 python/VERSION
create mode 100644 python/avocado.cfg
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}/console_socket.py (100%)
rename python/qemu/{ => machine}/machine.py (98%)
rename python/qemu/{ => machine}/qtest.py (98%)
delete mode 100644 python/qemu/pylintrc
rename python/qemu/{qmp.py => qmp/__init__.py} (96%)
create mode 100644 python/qemu/utils/__init__.py
rename python/qemu/{ => utils}/accel.py (100%)
create mode 100644 python/setup.cfg
create mode 100755 python/setup.py
create mode 100755 python/tests/flake8.sh
create mode 100755 python/tests/isort.sh
create mode 100755 python/tests/mypy.sh
create mode 100755 python/tests/pylint.sh
create mode 100644 python/tox.iniSignature · 1 line
2.30.2
PATCH v6 1/25 iotests/297: add --namespace-packages to mypy arguments
mypy is kind of weird about how it handles imports. For legacy reasons, it won't load PEP 420 namespaces, because of logic implemented prior to that becoming a standard.
So, if you plan on using any, you have to pass
--namespace-packages. Alright, fine.
--- tests/qemu-iotests/297 | 1 + 1 file changed, 1 insertion(+)
tests/qemu-iotests/297 +1 -0
@@ -95,6 +95,7 @@ def run_linters(): '--warn-redundant-casts', '--warn-unused-ignores', '--no-implicit-reexport', + '--namespace-packages', filename), env=env, check=False,
Signature · 1 line
2.30.2
PATCH v6 2/25 python: create qemu packages
In reply to John Snowmove 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".
---
Note for reviewers: in the next patch, I add a utils sub-package and move qemu/machine/accel.py to qemu/utils/accel.py. If we like it that way, we can squash it in here if we want, or just leave it as its own follow-up patch, I am just leaving it as something that will be easy to un-do or change for now.
---
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/avocado_qemu/__init__.py | 4 +-
tests/acceptance/virtio-gpu.py | 2 +-
tests/qemu-iotests/300 | 4 +-
tests/qemu-iotests/iotests.py | 2 +-
tests/vm/aarch64vm.py | 2 +-
tests/vm/basevm.py | 3 +-
16 files changed, 73 insertions(+), 27 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
python/qemu/__init__.py deleted +0 -11
@@ -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
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
python/qemu/machine/console_socket.py renamed from python/qemu/console_socket.py +0 -0
python/qemu/machine/machine.py renamed from python/qemu/machine.py +11 -5
@@ -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
@@ -316,7 +322,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
@@ -543,7 +549,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
python/qemu/machine/qtest.py renamed from python/qemu/qtest.py +2 -1
@@ -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
@@ -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/avocado_qemu/__init__.py +2 -2
@@ -40,9 +40,9 @@ sys.path.append(os.path.join(SOURCE_DIR, 'python')) -from qemu.accel import kvm_available -from qemu.accel import tcg_available from qemu.machine import QEMUMachine +from qemu.machine import kvm_available +from qemu.machine import tcg_available def is_readable_executable_file(path): return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
tests/acceptance/virtio-gpu.py +1 -1
@@ -10,7 +10,7 @@ from avocado_qemu import exec_command_and_wait_for_pattern from avocado_qemu import is_readable_executable_file -from qemu.accel import kvm_available +from qemu.machine import kvm_available import os import socket
tests/qemu-iotests/300 +2 -2
@@ -28,7 +28,7 @@ import iotests # Import qemu after iotests.py has amended sys.path # pylint: disable=wrong-import-order -import qemu +from qemu.machine import machine BlockBitmapMapping = List[Dict[str, object]]
@@ -466,7 +466,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
@@ -39,7 +39,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/aarch64vm.py +1 -1
@@ -14,7 +14,7 @@ import sys import subprocess import basevm -from qemu.accel import kvm_available +from qemu.machine import kvm_available # This is the config needed for current version of QEMU. # This works for both kvm and tcg.
tests/vm/basevm.py +1 -2
@@ -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.30.2
Re: [PATCH v6 02/25] python: create qemu packages
Quoted 46 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__.pymaking the top-level classes and functions from its various modules available directly inside the package. Changeqmp.pytoqmp/__init__.pysimilarly, such that all of the useful QMP library classes are available directly from "qemu.qmp" instead of "qemu.qmp.qmp".Signed-off-by John Snow <[email protected]>---
Note for reviewers: in the next patch, I add a utils sub-package and move
qemu/machine/accel.pytoqemu/utils/accel.py. If we like it that way, we can squash it in here if we want, or just leave it as its own follow-up patch, I am just leaving it as something that will be easy to un-do or change for now.Signed-off-by John Snow <[email protected]>--- 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/avocado_qemu/__init__.py | 4 +- tests/acceptance/virtio-gpu.py | 2 +- tests/qemu-iotests/300 | 4 +- tests/qemu-iotests/iotests.py | 2 +- tests/vm/aarch64vm.py | 2 +- tests/vm/basevm.py | 3 +- 16 files changed, 73 insertions(+), 27 deletions(-) rename python/{qemu => }/.isort.cfg (100%) delete mode 100644 python/qemu/__init__.py
Quoted 9 lines
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%)Hi John,
Thanks for this! I went through it and it LGTM. I've tested it with iotests, acceptance and with a vm-build-fedora.
Re: [PATCH v6 02/25] python: create qemu packages
In reply to John SnowQuoted 47 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__.pymaking the top-level classes and functions from its various modules available directly inside the package. Changeqmp.pytoqmp/__init__.pysimilarly, such that all of the useful QMP library classes are available directly from "qemu.qmp" instead of "qemu.qmp.qmp".Signed-off-by John Snow <[email protected]>---
Note for reviewers: in the next patch, I add a utils sub-package and move
qemu/machine/accel.pytoqemu/utils/accel.py. If we like it that way, we can squash it in here if we want, or just leave it as its own follow-up patch, I am just leaving it as something that will be easy to un-do or change for now.Signed-off-by John Snow <[email protected]>--- 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/avocado_qemu/__init__.py | 4 +- tests/acceptance/virtio-gpu.py | 2 +- tests/qemu-iotests/300 | 4 +- tests/qemu-iotests/iotests.py | 2 +- tests/vm/aarch64vm.py | 2 +- tests/vm/basevm.py | 3 +- 16 files changed, 73 insertions(+), 27 deletions(-) rename python/{qemu => }/.isort.cfg (100%) delete mode 100644 python/qemu/__init__.py
Quoted 9 lines
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%)This improves a lot the organization of the code.
PATCH v6 3/25 python: create utils sub-package
In reply to John SnowCreate a space for miscellaneous things that don't belong strictly in "qemu.machine" nor "qemu.qmp" packages.
---
python/qemu/machine/__init__.py | 8 --------
python/qemu/utils/__init__.py | 23 +++++++++++++++++++++++
python/qemu/{machine => utils}/accel.py | 0
tests/acceptance/avocado_qemu/__init__.py | 4 ++--
tests/acceptance/virtio-gpu.py | 2 +-
tests/vm/aarch64vm.py | 2 +-
tests/vm/basevm.py | 3 ++-
7 files changed, 29 insertions(+), 13 deletions(-)
create mode 100644 python/qemu/utils/__init__.py
rename python/qemu/{machine => utils}/accel.py (100%)python/qemu/machine/__init__.py +0 -8
@@ -8,10 +8,6 @@ - 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-2021 John Snow for Red Hat Inc.
@@ -26,15 +22,11 @@ # 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', 'QEMUMachine', 'QEMUQtestProtocol', 'QEMUQtestMachine',
python/qemu/utils/__init__.py new file +23 -0
@@ -0,0 +1,23 @@ +""" +QEMU development and testing utilities + +This library provides a small handful of utilities for performing various tasks +not directly related to the launching of a VM. + +The only module included at present is accel; its public functions are +repeated here for your convenience: + +- list_accel: List available accelerators +- kvm_available: Probe for KVM support +- tcg_available: Prove for TCG support +""" + +# pylint: disable=import-error +from .accel import kvm_available, list_accel, tcg_available + + +__all__ = ( + 'list_accel', + 'kvm_available', + 'tcg_available', +)
python/qemu/utils/accel.py renamed from python/qemu/machine/accel.py +0 -0
tests/acceptance/avocado_qemu/__init__.py +2 -2
@@ -41,8 +41,8 @@ sys.path.append(os.path.join(SOURCE_DIR, 'python')) from qemu.machine import QEMUMachine -from qemu.machine import kvm_available -from qemu.machine import tcg_available +from qemu.utils import kvm_available +from qemu.utils import tcg_available def is_readable_executable_file(path): return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
tests/acceptance/virtio-gpu.py +1 -1
@@ -10,7 +10,7 @@ from avocado_qemu import exec_command_and_wait_for_pattern from avocado_qemu import is_readable_executable_file -from qemu.machine import kvm_available +from qemu.utils import kvm_available import os import socket
tests/vm/aarch64vm.py +1 -1
@@ -14,7 +14,7 @@ import sys import subprocess import basevm -from qemu.machine import kvm_available +from qemu.utils import kvm_available # This is the config needed for current version of QEMU. # This works for both kvm and tcg.
tests/vm/basevm.py +2 -1
@@ -19,7 +19,8 @@ import time import datetime sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) -from qemu.machine import kvm_available, QEMUMachine +from qemu.machine import QEMUMachine +from qemu.utils import kvm_available import subprocess import hashlib import argparse
Signature · 1 line
2.30.2
Re: [PATCH v6 03/25] python: create utils sub-package
Quoted 4 lines · John Snow
Create a space for miscellaneous things that don't belong strictly in "qemu.machine" nor "qemu.qmp" packages.
Signed-off-by John Snow <[email protected]>
Quoted 12 lines
---
python/qemu/machine/__init__.py | 8 --------
python/qemu/utils/__init__.py | 23 +++++++++++++++++++++++
python/qemu/{machine => utils}/accel.py | 0
tests/acceptance/avocado_qemu/__init__.py | 4 ++--
tests/acceptance/virtio-gpu.py | 2 +-
tests/vm/aarch64vm.py | 2 +-
tests/vm/basevm.py | 3 ++-
7 files changed, 29 insertions(+), 13 deletions(-)
create mode 100644 python/qemu/utils/__init__.py
rename python/qemu/{machine => utils}/accel.py (100%)As you mentioned in the previous patch notes, I would not mind a squash here. Either way:
Re: [PATCH v6 03/25] python: create utils sub-package
Quoted 5 lines · Cleber Rosa
As you mentioned in the previous patch notes, I would not mind a squash here. Either way:
Reviewed-by Cleber Rosa<[email protected]>Tested-by Cleber Rosa<[email protected]>
I will definitely do so, then. :)
Thanks for the reviews thus far!
--js
Re: [PATCH v6 03/25] python: create utils sub-package
In reply to John SnowQuoted 5 lines · John Snow
Create a space for miscellaneous things that don't belong strictly in "qemu.machine" nor "qemu.qmp" packages.
Signed-off-by John Snow <[email protected]>
Quoted 12 lines
---
python/qemu/machine/__init__.py | 8 --------
python/qemu/utils/__init__.py | 23 +++++++++++++++++++++++
python/qemu/{machine => utils}/accel.py | 0
tests/acceptance/avocado_qemu/__init__.py | 4 ++--
tests/acceptance/virtio-gpu.py | 2 +-
tests/vm/aarch64vm.py | 2 +-
tests/vm/basevm.py | 3 ++-
7 files changed, 29 insertions(+), 13 deletions(-)
create mode 100644 python/qemu/utils/__init__.py
rename python/qemu/{machine => utils}/accel.py (100%)Re: [PATCH v6 03/25] python: create utils sub-package
Quoted 19 lines · Willian Rampazzo
Quoted 14 lines · John Snow
Create a space for miscellaneous things that don't belong strictly in "qemu.machine" nor "qemu.qmp" packages.
Signed-off-by John Snow <[email protected]>--- python/qemu/machine/__init__.py | 8 -------- python/qemu/utils/__init__.py | 23 +++++++++++++++++++++++ python/qemu/{machine => utils}/accel.py | 0 tests/acceptance/avocado_qemu/__init__.py | 4 ++-- tests/acceptance/virtio-gpu.py | 2 +- tests/vm/aarch64vm.py | 2 +- tests/vm/basevm.py | 3 ++- 7 files changed, 29 insertions(+), 13 deletions(-)Quoted 3 lines
create mode 100644
python/qemu/utils/__init__.pyrename python/qemu/{machine =>utils}/accel.py(100%)
Quoted 2 lines
Reviewed-by Willian Rampazzo <[email protected]>
Thanks :) I've since squashed patches 2/3, so I will add your R-B to that combined patch.
--js
PATCH v6 4/25 python: add qemu package installer
In reply to John SnowAdd setup.cfg and setup.py, necessary for installing a package via pip. Add a ReST document (PACKAGE.rst) 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 "editable" installs are not defined (yet?) by PEP-517/518.
I consider editable installs crucial for development, though they have (apparently) always been somewhat poorly defined.
Pip now (19.2 and later) now supports editable installs for projects using pyproject.toml manifests, but might require the use of the --no-use-pep517 flag, which somewhat defeats the point.
For now, while the dust settles, stick with the de-facto setup.py/setup.cfg combination supported by setuptools. It will be worth re-evaluating this point again in the future when our supported build platforms all ship a fairly modern pip.
Additional reading on this matter:
https://github.com/pypa/packaging-problems/issues/256
https://github.com/pypa/pip/issues/6334
https://github.com/pypa/pip/issues/6375
https://github.com/pypa/pip/issues/6434
https://github.com/pypa/pip/issues/6438
--- python/PACKAGE.rst | 33 +++++++++++++++++++++++++++++++++ python/setup.cfg | 19 +++++++++++++++++++ python/setup.py | 23 +++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 python/PACKAGE.rst create mode 100644 python/setup.cfg create mode 100755 python/setup.py
python/PACKAGE.rst new file +33 -0
@@ -0,0 +1,33 @@ +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 +package'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>`_, which involves +sending patches to the QEMU development mailing list. + +John maintains a `GitLab staging branch +<https://gitlab.com/jsnow/qemu/-/tree/python>`_, and there is an +official `GitLab mirror <https://gitlab.com/qemu-project/qemu>`_. + +Please report bugs on the `QEMU issue tracker +<https://gitlab.com/qemu-project/qemu/-/issues>`_ and tag ``@jsnow`` in +the report.
python/setup.cfg new file +19 -0
@@ -0,0 +1,19 @@ +[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 + Programming Language :: Python :: 3 :: Only + +[options] +python_requires = >= 3.6 +packages = find_namespace:
python/setup.py new file +23 -0
@@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +""" +QEMU tooling installer script +Copyright (c) 2020-2021 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.30.2
Re: [PATCH v6 04/25] python: add qemu package installer
Quoted 11 lines · John Snow
Add setup.cfg and
setup.py, necessary for installing a package via pip. Add a ReST document (PACKAGE.rst) 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 "editable" installs are not defined (yet?) by PEP-517/518.
I consider editable installs crucial for development, though they have (apparently) always been somewhat poorly defined.
They are crucial for development indeed, so I agree with your overall choices here.
Quoted 4 lines
Pip now (19.2 and later) now supports editable installs for projects using pyproject.toml manifests, but might require the use of the --no-use-pep517 flag, which somewhat defeats the point.
Just to make it clear for other people reading this, it means that even with the very latest pip release (21.1.1), you *must* have a setup.py or setup.cfg file to use editable (development) installs[1] You can *not* rely solely on a pyproject.toml setup.
[1] https://github.com/pypa/pip/pull/9547/commits/7a95720e796a5e56481c1cc20b6ce6249c50f357
Quoted 5 lines
For now, while the dust settles, stick with the de-facto setup.py/setup.cfg combination supported by setuptools. It will be worth re-evaluating this point again in the future when our supported build platforms all ship a fairly modern pip.
Agreed, but let's not hold our breath given that even pip 21.1.1 still doesn't support that. My guesstimate is 6-12 months for the feature to be developed/merged, and let's say another 12 months for our supported build platforms to ship it.
Quoted 115 lines
Additional reading on this matter:
https://github.com/pypa/packaging-problems/issues/256
https://github.com/pypa/pip/issues/6334
https://github.com/pypa/pip/issues/6375
https://github.com/pypa/pip/issues/6434
https://github.com/pypa/pip/issues/6438Signed-off-by John Snow <[email protected]>--- python/PACKAGE.rst | 33 +++++++++++++++++++++++++++++++++ python/setup.cfg | 19 +++++++++++++++++++ python/setup.py | 23 +++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 python/PACKAGE.rst create mode 100644 python/setup.cfg create mode 100755 python/setup.pypython/PACKAGE.rst new file +33
-0@@ -0,0 +1,33 @@ +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 +package'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>`_, which involves +sending patches to the QEMU development mailing list. + +John maintains a `GitLab staging branch +<https://gitlab.com/jsnow/qemu/-/tree/python>`_, and there is an +official `GitLab mirror <https://gitlab.com/qemu-project/qemu>`_. + +Please report bugs on the `QEMU issue tracker +<https://gitlab.com/qemu-project/qemu/-/issues>`_ and tag ``@jsnow`` in +the report.python/setup.cfg new file +19
-0@@ -0,0 +1,19 @@ +[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 + Programming Language :: Python :: 3 :: Only + +[options] +python_requires = >= 3.6 +packages = find_namespace:python/setup.py new file +23
-0@@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +""" +QEMU tooling installer script +Copyright (c) 2020-2021 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.30.2
BTW, about the need to have a "setup.py", before pip 21.1.1:
$ rm setup.py $ pip install -e . ERROR: File "setup.py" not found. Directory cannot be installed in editable mode: /home/cleber/src/qemu/python
On pip 21.1.1:
$ pip install -e .
Obtaining file:///home/cleber/src/qemu/python
Installing collected packages: qemu
Running setup.py develop for qemu
Successfully installed qemu-0.0.0Side note: The "Running setup.py ..." message given by pip 21.1.1, even though there is *not* a "setup.py" is rather confusing.
Anyway, we may be able to drop setup.py either when we find pip 21.1.1 or later in our "common build environments", or if we require people hacking on the Python module to "pip install --upgrade pip".
I'll be repeating myself here, but I believe you made the right choices at this time, and based on my testing I can successfully install/develop using "python setup.py" and "pip", so:
Re: [PATCH v6 04/25] python: add qemu package installer
Quoted 176 lines · Cleber Rosa
Quoted 11 lines · John Snow
Add setup.cfg and
setup.py, necessary for installing a package via pip. Add a ReST document (PACKAGE.rst) 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 "editable" installs are not defined (yet?) by PEP-517/518.
I consider editable installs crucial for development, though they have (apparently) always been somewhat poorly defined.
They are crucial for development indeed, so I agree with your overall choices here.
Quoted 4 lines
Pip now (19.2 and later) now supports editable installs for projects using pyproject.toml manifests, but might require the use of the --no-use-pep517 flag, which somewhat defeats the point.
Just to make it clear for other people reading this, it means that even with the very latest pip release (21.1.1), you *must* have a
setup.pyor setup.cfg file to use editable (development) installs[1] You can *not* rely solely on a pyproject.toml setup.[1] https://github.com/pypa/pip/pull/9547/commits/7a95720e796a5e56481c1cc20b6ce6249c50f357
Quoted 5 lines
For now, while the dust settles, stick with the de-facto setup.py/setup.cfg combination supported by setuptools. It will be worth re-evaluating this point again in the future when our supported build platforms all ship a fairly modern pip.
Agreed, but let's not hold our breath given that even pip 21.1.1 still doesn't support that. My guesstimate is 6-12 months for the feature to be developed/merged, and let's say another 12 months for our supported build platforms to ship it.
Quoted 115 lines
Additional reading on this matter:
https://github.com/pypa/packaging-problems/issues/256
https://github.com/pypa/pip/issues/6334
https://github.com/pypa/pip/issues/6375
https://github.com/pypa/pip/issues/6434
https://github.com/pypa/pip/issues/6438Signed-off-by John Snow <[email protected]>--- python/PACKAGE.rst | 33 +++++++++++++++++++++++++++++++++ python/setup.cfg | 19 +++++++++++++++++++ python/setup.py | 23 +++++++++++++++++++++++ 3 files changed, 75 insertions(+)create mode 100644
python/PACKAGE.rst
create mode 100644 python/setup.cfg
create mode 100755python/setup.pypython/PACKAGE.rst new file +33
-0@@ -0,0 +1,33 @@ +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 +package'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>`_, which involves +sending patches to the QEMU development mailing list. + +John maintains a `GitLab staging branch +<https://gitlab.com/jsnow/qemu/-/tree/python>`_, and there is an +official `GitLab mirror <https://gitlab.com/qemu-project/qemu>`_. + +Please report bugs on the `QEMU issue tracker +<https://gitlab.com/qemu-project/qemu/-/issues>`_ and tag ``@jsnow`` in +the report.python/setup.cfg new file +19
-0@@ -0,0 +1,19 @@ +[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 + Programming Language :: Python :: 3 :: Only + +[options] +python_requires = >= 3.6 +packages = find_namespace:python/setup.py new file +23
-0@@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +""" +QEMU tooling installer script +Copyright (c) 2020-2021 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.30.2BTW, about the need to have a "
setup.py", before pip 21.1.1:$ rm setup.py $ pip install -e . ERROR: File "setup.py" not found. Directory cannot be installed in editable mode: /home/cleber/src/qemu/pythonOn pip 21.1.1:
$ pip install -e . Obtaining file:///home/cleber/src/qemu/python Installing collected packages: qemu Running setup.py develop for qemu Successfully installed qemu-0.0.0Side note: The "Running
setup.py..." message given by pip 21.1.1, even though there is *not* a "setup.py" is rather confusing.Anyway, we may be able to drop
setup.pyeither when we find pip 21.1.1 or later in our "common build environments", or if we require people hacking on the Python module to "pip install --upgrade pip".
Quoted 7 lines
I'll be repeating myself here, but I believe you made the right choices at this time, and based on my testing I can successfully install/develop using "python
setup.py" and "pip", so:Reviewed-by Cleber Rosa <[email protected]>Tested-by Cleber Rosa <[email protected]>
Great :)
I figured it would be helpful to outline the reasons in the commit message, at least, so that anyone who is curious about it in the future can find out exactly what we considered the blockers to be.
I'll update the commit message with an edited version of your reply here, just to add more information to the historical record.
--js
PATCH v6 5/25 python: add VERSION file
In reply to John SnowPython 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.
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, for now, 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.6.0.0a1.
--- python/VERSION | 1 + python/setup.cfg | 1 + 2 files changed, 2 insertions(+) create mode 100644 python/VERSION
python/VERSION new file +1 -0
@@ -0,0 +1 @@ +0.6.1.0a1
python/setup.cfg +1 -0
@@ -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.30.2
PATCH v6 6/25 python: add directory structure README.rst files
In reply to John SnowAdd short readmes to python/, python/qemu/, python/qemu/machine, python/qemu/qmp, and python/qemu/utils 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 | 41 ++++++++++++++++++++++++++++++++++ python/qemu/README.rst | 8 +++++++ python/qemu/machine/README.rst | 9 ++++++++ python/qemu/qmp/README.rst | 9 ++++++++ python/qemu/utils/README.rst | 7 ++++++ 5 files changed, 74 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 create mode 100644 python/qemu/utils/README.rst
python/README.rst new file +41 -0
@@ -0,0 +1,41 @@ +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 (e.g. ``qemu/machine``, ``qemu/qmp``, etc). + +``setup.py`` is used by ``pip`` to install this tooling to the current +environment. ``setup.cfg`` provides the packaging configuration used by +setup.py in a setuptools specific format. 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 append the ``-e`` argument, pip will install in "editable" mode; +which installs a version of the package that installs a forwarder +pointing 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. + + +Files in this directory +----------------------- + +- ``qemu/`` Python package source directory. +- ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org. +- ``README.rst`` you are here! +- ``VERSION`` contains the PEP-440 compliant version used to describe + this package; it is referenced by ``setup.cfg``. +- ``setup.cfg`` houses setuptools package configuration. +- ``setup.py`` is the setuptools installer used by pip; See above.
python/qemu/README.rst new file +8 -0
@@ -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
@@ -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, acceptance 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
@@ -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, +acceptance 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.
python/qemu/utils/README.rst new file +7 -0
@@ -0,0 +1,7 @@ +qemu.utils package +================== + +This package provides miscellaneous utilities used for testing and +debugging QEMU. It is used primarily by the vm and acceptance tests. + +See the documentation in ``__init__.py`` for more information.
Signature · 1 line
2.30.2
Re: [PATCH v6 06/25] python: add directory structure README.rst files
Quoted 28 lines · John Snow
Add short readmes to python/, python/qemu/, python/qemu/machine, python/qemu/qmp, and python/qemu/utils 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.
Signed-off-by John Snow <[email protected]>--- python/README.rst | 41 ++++++++++++++++++++++++++++++++++ python/qemu/README.rst | 8 +++++++ python/qemu/machine/README.rst | 9 ++++++++ python/qemu/qmp/README.rst | 9 ++++++++ python/qemu/utils/README.rst | 7 ++++++ 5 files changed, 74 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 create mode 100644 python/qemu/utils/README.rstpython/README.rst new file +0
-0
python/README.rst line 10
Quoted 10 lines
python/README.rst new file +10
-0@@ -0,0 +1,41 @@ +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 (e.g. ``qemu/machine``, ``qemu/qmp``, etc). + +``setup.py`` is used by ``pip`` to install this tooling to the current +environment. ``setup.cfg`` provides the packaging configuration used by +setup.py in a setuptools specific format. You will generally invoke it
For consistency, ``setup.py`` here? Also, I guess ``setuptools`` as it falls in the same category of ``pip``.
python/README.rst line 16
Quoted 6 lines
python/README.rst new file +6
-0+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.
Maybe some **emphasis** on **not**?
python/README.rst line 21
Quoted 5 lines
python/README.rst new file +5
-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. +
Maybe note that, if you are inside of a virtual environment, option #1 will probably be what users doing "--user" in a venv actually want.
Quoted 10 lines
python/README.rst new file +10
-0+If you append the ``-e`` argument, pip will install in "editable" mode; +which installs a version of the package that installs a forwarder +pointing 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/README.rst line 41
Quoted 10 lines
python/README.rst new file +10
-0+Files in this directory +----------------------- + +- ``qemu/`` Python package source directory. +- ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org. +- ``README.rst`` you are here! +- ``VERSION`` contains the PEP-440 compliant version used to describe + this package; it is referenced by ``setup.cfg``. +- ``setup.cfg`` houses setuptools package configuration. +- ``setup.py`` is the setuptools installer used by pip; See above.
Not only used by pip... but I understand the reason for limiting the amount of information given here.
Quoted 61 lines
python/qemu/README.rst new file +8
-0@@ -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@@ -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, acceptance 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@@ -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, +acceptance 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.python/qemu/utils/README.rst new file +7
-0@@ -0,0 +1,7 @@ +qemu.utils package +================== + +This package provides miscellaneous utilities used for testing and +debugging QEMU. It is used primarily by the vm and acceptance tests. + +See the documentation in ``__init__.py`` for more information.Signature · 1 line
2.30.2
With the ``setup.py`` and ``setuptools`` for consistency sake mentioned in my first comment, all other comments are suggestions, so:
Re: [PATCH v6 06/25] python: add directory structure README.rst files
Quoted 34 lines · Cleber Rosa
Quoted 33 lines · John Snow
Add short readmes to python/, python/qemu/, python/qemu/machine, python/qemu/qmp, and python/qemu/utils 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.
Signed-off-by John Snow <[email protected]>--- python/README.rst | 41 ++++++++++++++++++++++++++++++++++ python/qemu/README.rst | 8 +++++++ python/qemu/machine/README.rst | 9 ++++++++ python/qemu/qmp/README.rst | 9 ++++++++ python/qemu/utils/README.rst | 7 ++++++ 5 files changed, 74 insertions(+)create mode 100644
python/README.rstcreate mode 100644python/qemu/README.rstcreate mode 100644python/qemu/machine/README.rstcreate mode 100644python/qemu/qmp/README.rstcreate mode 100644python/qemu/utils/README.rstpython/README.rst new file +5
-0@@ -0,0 +1,41 @@ +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
Quoted 9 lines
python/README.rst line 10
Quoted 5 lines
python/README.rst new file +5
-0+then by package (e.g. ``qemu/machine``, ``qemu/qmp``, etc). + +``setup.py`` is used by ``pip`` to install this tooling to the current +environment. ``setup.cfg`` provides the packaging configuration used by +setup.py in a setuptools specific format. You will generally invoke itFor consistency, ``setup.py`` here? Also, I guess ``setuptools`` as it falls in the same category of ``pip``.
Kinda-sorta, but pip is a command line executable and setuptools isn't. Along those lines I'll fix setup.py but leave setuptools as-is.
Quoted 9 lines
python/README.rst line 16
Quoted 6 lines
python/README.rst new file +6
-0+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.Maybe some **emphasis** on **not**?
Sure :)
Quoted 9 lines
python/README.rst line 21
Quoted 5 lines
python/README.rst new file +5
-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. +Maybe note that, if you are inside of a virtual environment, option #1 will probably be what users doing "--user" in a venv actually want.
Yes. It's frequently annoying how this works, because it's hard to relay succinctly :)
I think at least newer versions of pip give you good warnings when you use --user for virtual environments at least.
Quoted 15 lines
Quoted 15 lines
python/README.rst new file +15
-0+If you append the ``-e`` argument, pip will install in "editable" mode; +which installs a version of the package that installs a forwarder +pointing 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. + + +Files in this directory +----------------------- + +- ``qemu/`` Python package source directory. +- ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org.
Quoted 9 lines
python/README.rst line 41
Quoted 5 lines
python/README.rst new file +5
-0+- ``README.rst`` you are here! +- ``VERSION`` contains the PEP-440 compliant version used to describe + this package; it is referenced by ``setup.cfg``. +- ``setup.cfg`` houses setuptools package configuration. +- ``setup.py`` is the setuptools installer used by pip; See above.Not only used by pip... but I understand the reason for limiting the amount of information given here.
Yes ... suggesting broadly that I don't really support using setuptools/setup.py alone to install the package, but instead expect and consider 'pip' to be the canonical/supported interface.
There are sometimes minor differences between how they handle things, so I wanted less emphasis on setuptools et al.
Quoted 56 lines
Quoted 56 lines
python/qemu/README.rst new file +8
-0@@ -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@@ -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, acceptance 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@@ -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, +acceptance 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.python/qemu/utils/README.rst new file +6
-0@@ -0,0 +1,7 @@ +qemu.utils package +================== + +This package provides miscellaneous utilities used for testing and +debugging QEMU. It is used primarily by the vm and acceptance tests. +
Quoted 9 lines
Quoted 5 lines
python/qemu/utils/README.rst new file +1
-0+See the documentation in ``__init__.py`` for more information.Signature · 1 line
2.30.2With the ``setup.py`` and ``setuptools`` for consistency sake mentioned in my first comment, all other comments are suggestions, so:
I took one of those two review comments, and acted on one of two of your suggestions.
Quoted 2 lines
Reviewed-by Cleber Rosa <[email protected]>
So technically I didn't meet your criteria for taking this RB :) Let me know if I can still apply it:
python/README.rst +4 -4
@@ -7,17 +7,17 @@ then by package (e.g. ``qemu/machine``, ``qemu/qmp``, etc). ``setup.py`` is used by ``pip`` to install this tooling to the current environment. ``setup.cfg`` provides the packaging configuration used by -setup.py in a setuptools specific format. You will generally invoke it -by doing one of the following: +``setup.py`` in a setuptools specific format. 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. + 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. + this will fail; you likely want the first invocation above. If you append the ``-e`` argument, pip will install in "editable" mode; which installs a version of the package that installs a forwarder
Re: [PATCH v6 06/25] python: add directory structure README.rst files
Quoted 45 lines · John Snow
Quoted 34 lines · Cleber Rosa
Quoted 33 lines · John Snow
Add short readmes to python/, python/qemu/, python/qemu/machine, python/qemu/qmp, and python/qemu/utils 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.
Signed-off-by John Snow <[email protected]>--- python/README.rst | 41 ++++++++++++++++++++++++++++++++++ python/qemu/README.rst | 8 +++++++ python/qemu/machine/README.rst | 9 ++++++++ python/qemu/qmp/README.rst | 9 ++++++++ python/qemu/utils/README.rst | 7 ++++++ 5 files changed, 74 insertions(+)create mode 100644
python/README.rstcreate mode 100644python/qemu/README.rstcreate mode 100644python/qemu/machine/README.rstcreate mode 100644python/qemu/qmp/README.rstcreate mode 100644python/qemu/utils/README.rstpython/README.rst new file +5
-0@@ -0,0 +1,41 @@ +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``), andQuoted 9 lines
python/README.rst line 10
Quoted 5 lines
python/README.rst new file +5
-0+then by package (e.g. ``qemu/machine``, ``qemu/qmp``, etc). + +``setup.py`` is used by ``pip`` to install this tooling to the current +environment. ``setup.cfg`` provides the packaging configuration used by +setup.py in a setuptools specific format. You will generally invoke itFor consistency, ``setup.py`` here? Also, I guess ``setuptools`` as it falls in the same category of ``pip``.
Quoted 3 lines
Kinda-sorta, but
pipis a command line executable and setuptools isn't. Along those lines I'll fixsetup.pybut leave setuptools as-is.
OK, fair enough.
Quoted 22 lines
Quoted 9 lines
python/README.rst line 16
Quoted 6 lines
python/README.rst new file +6
-0+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.Maybe some **emphasis** on **not**?
Sure :)
Quoted 9 lines
python/README.rst line 21
Quoted 5 lines
python/README.rst new file +5
-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. +Maybe note that, if you are inside of a virtual environment, option #1 will probably be what users doing "--user" in a venv actually want.
Quoted 6 lines
Yes. It's frequently annoying how this works, because it's hard to relay succinctly :)
I think at least newer versions of pip give you good warnings when you use --user for virtual environments at least.
True.
Quoted 25 lines
Quoted 15 lines
Quoted 15 lines
python/README.rst new file +15
-0+If you append the ``-e`` argument, pip will install in "editable" mode; +which installs a version of the package that installs a forwarder +pointing 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. + + +Files in this directory +----------------------- + +- ``qemu/`` Python package source directory. +- ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org.Quoted 9 lines
python/README.rst line 41
Quoted 5 lines
python/README.rst new file +5
-0+- ``README.rst`` you are here! +- ``VERSION`` contains the PEP-440 compliant version used to describe + this package; it is referenced by ``setup.cfg``. +- ``setup.cfg`` houses setuptools package configuration. +- ``setup.py`` is the setuptools installer used by pip; See above.Not only used by pip... but I understand the reason for limiting the amount of information given here.
Quoted 7 lines
Yes ... suggesting broadly that I don't really support using
setuptools/setup.pyalone to install the package, but instead expect and consider 'pip' to be the canonical/supported interface.There are sometimes minor differences between how they handle things, so I wanted less emphasis on setuptools et al.
Sure, I can definitely side with you here.
Quoted 85 lines
Quoted 56 lines
Quoted 56 lines
python/qemu/README.rst new file +8
-0@@ -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@@ -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, acceptance 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@@ -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, +acceptance 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.python/qemu/utils/README.rst new file +6
-0@@ -0,0 +1,7 @@ +qemu.utils package +================== + +This package provides miscellaneous utilities used for testing and +debugging QEMU. It is used primarily by the vm and acceptance tests. +Quoted 9 lines
Quoted 5 lines
python/qemu/utils/README.rst new file +1
-0+See the documentation in ``__init__.py`` for more information.Signature · 1 line
2.30.2With the ``setup.py`` and ``setuptools`` for consistency sake mentioned in my first comment, all other comments are suggestions, so:
I took one of those two review comments, and acted on one of two of your suggestions.
Quoted 2 lines
Reviewed-by Cleber Rosa <[email protected]>So technically I didn't meet your criteria for taking this RB :) Let me know if I can still apply it:
python/README.rst +0
-0@@ -7,17 +7,17 @@ then by package (e.g. ``qemu/machine``, ``qemu/qmp``,etc).
``setup.py`` is used by ``pip`` to install this tooling to the current environment. ``setup.cfg`` provides the packaging configuration used by
python/README.rst then by package (e.g. ``qemu/machine``, ``qemu/qmp``, etc). · line 11
Quoted 4 lines
python/README.rst +2
-2-setup.py in a setuptools specific format. You will generally invoke it -by doing one of the following: +``setup.py`` in a setuptools specific format. You will generally invoke +it by doing one of the following:
OK.
python/README.rst then by package (e.g. ``qemu/machine``, ``qemu/qmp``, etc). · line 16
Quoted 6 lines
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
python/README.rst +1
-1- global environment, which is not recommended. + global environment, which is **not recommended**.
Nice :)
python/README.rst then by package (e.g. ``qemu/machine``, ``qemu/qmp``, etc). · line 23
Quoted 7 lines
2. ``pip3 install --user .`` will install these packages to your user's local python packages. If you are inside of a virtual environment,
python/README.rst +1
-1- this will fail. + this will fail; you likely want the first invocation above. If you append the ``-e`` argument, pip will install in "editable" mode; which installs a version of the package that installs a forwarder
Cool! And, just to make sure, I'll give you not one but two:
:)
PATCH v6 7/25 python: add MANIFEST.in
In reply to John SnowWhen creating a source distribution via 'python3 setup.py sdist', the VERSION and PACKAGE.rst files aren't bundled by default. Create a MANIFEST.in file that instructs the build tools to include these so that installation from source dists won't fail.
(This invocation is required by 'tox', as well as by the tooling needed to upload packages to PyPI.)
--- python/README.rst | 2 ++ python/MANIFEST.in | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 python/MANIFEST.in
python/README.rst +2 -0
@@ -33,6 +33,8 @@ Files in this directory ----------------------- - ``qemu/`` Python package source directory. +- ``MANIFEST.in`` is read by python setuptools, it specifies additional files + that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org. - ``README.rst`` you are here! - ``VERSION`` contains the PEP-440 compliant version used to describe
python/MANIFEST.in new file +2 -0
@@ -0,0 +1,2 @@ +include VERSION +include PACKAGE.rst
Signature · 1 line
2.30.2
Re: [PATCH v6 07/25] python: add MANIFEST.in
Quoted 8 lines · John Snow
When creating a source distribution via 'python3
setup.pysdist', the VERSION andPACKAGE.rstfiles aren't bundled by default. Create a MANIFEST.in file that instructs the build tools to include these so that installation from source dists won't fail.(This invocation is required by 'tox', as well as by the tooling needed to upload packages to PyPI.)
Quoted 7 lines
Signed-off-by John Snow <[email protected]>--- python/README.rst | 2 ++ python/MANIFEST.in | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 python/MANIFEST.in
I was about to propose mypy.ini to be included here, but given that it's merged into setup.cfg later in this series:
---
Note to self (and to you) when generating the sdist, I get:
...
package init file 'qemu/__init__.py' not found (or not a regular file) package init file 'dist/__init__.py' not found (or not a regular file)
...
Which may not be too harmful, but deserves investigation.
Re: [PATCH v6 07/25] python: add MANIFEST.in
Quoted 20 lines · Cleber Rosa
Quoted 8 lines · John Snow
When creating a source distribution via 'python3
setup.pysdist', the VERSION andPACKAGE.rstfiles aren't bundled by default. Create a MANIFEST.in file that instructs the build tools to include these so that installation from source dists won't fail.(This invocation is required by 'tox', as well as by the tooling needed to upload packages to PyPI.)
Quoted 7 lines
Signed-off-by John Snow <[email protected]>--- python/README.rst | 2 ++ python/MANIFEST.in | 2 ++ 2 files changed, 4 insertions(+)create mode 100644 python/MANIFEST.in
I was about to propose mypy.ini to be included here, but given that it's merged into setup.cfg later in this series:
Quoted 8 lines
Reviewed-by Cleber Rosa <[email protected]>---
Note to self (and to you) when generating the sdist, I get:
...
package init file 'qemu/__init__.py' not found (or not a regular file)
I think this one is fine, it's just a consequence of PEP420.
Quoted 1 line
package init file '
dist/__init__.py' not found (or not a regular file)
This is kinda weird, but it only happens if you run sdist a *second* time, and it has created a dist/ folder. It shouldn't be trying to package its own dist folder ... !
After a 60 second look I don't know how to rectify this behavior, I will look into it.
Quoted 4 lines
...Which may not be too harmful, but deserves investigation.
fwiw clean run vs re-run:
run2 renamed from run1 +1 -3
@@ -1,11 +1,10 @@ running sdist running egg_info -creating qemu.egg-info writing qemu.egg-info/PKG-INFO writing dependency_links to qemu.egg-info/dependency_links.txt writing top-level names to qemu.egg-info/top_level.txt -writing manifest file 'qemu.egg-info/SOURCES.txt' package init file 'qemu/__init__.py' not found (or not a regular file) +package init file 'dist/__init__.py' not found (or not a regular file) reading manifest file 'qemu.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'qemu.egg-info/SOURCES.txt'
@@ -35,6 +34,5 @@ copying qemu/utils/__init__.py -> qemu-0.6.1.0a1/qemu/utils copying qemu/utils/accel.py -> qemu-0.6.1.0a1/qemu/utils Writing qemu-0.6.1.0a1/setup.cfg -creating dist Creating tar archive removing 'qemu-0.6.1.0a1' (and everything under it)
at the very least, it doesn't look like it does anything actively harmful, but it seems to want to find sources in the dist, so I should steer it towards exclusively the qemu/ folder.
Thanks for this, Cleber!
--js
PATCH v6 8/25 python: Add pipenv support
In reply to John Snowpipenv 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.cfg 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 *rock solid* 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 loadout 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/README.rst | 3 +++ python/Pipfile | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 python/Pipfile
python/README.rst +3 -0
@@ -36,6 +36,9 @@ Files in this directory - ``MANIFEST.in`` is read by python setuptools, it specifies additional files that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org. +- ``Pipfile`` is used by Pipenv to generate ``Pipfile.lock``. +- ``Pipfile.lock`` is a set of pinned package dependencies that this package + is tested under in our CI suite. It is used by ``make venv-check``. - ``README.rst`` you are here! - ``VERSION`` contains the PEP-440 compliant version used to describe this package; it is referenced by ``setup.cfg``.
python/Pipfile new file +11 -0
@@ -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.30.2
PATCH v6 9/25 python: add pylint import exceptions
In reply to John SnowPylint 2.5.x - 2.7.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
@@ -22,6 +22,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 .machine import QEMUMachine from .qtest import QEMUQtestMachine, QEMUQtestProtocol
python/qemu/machine/machine.py +1 -1
@@ -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
@@ -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.30.2
PATCH v6 10/25 python: move pylintrc into setup.cfg
In reply to John SnowDelete 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
@@ -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
@@ -18,3 +18,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.30.2
PATCH v6 11/25 python: add pylint to pipenv
In reply to John SnowWe are specifying >= pylint 2.7.x for several reasons:
1. For setup.cfg support, added in pylint 2.5.x
2. To specify a version that has incompatibly dropped bad-whitespace checks (2.6.x)
3. 2.7.x fixes "unsubscriptable" warnings in Python 3.9
--- python/Pipfile | 1 + python/Pipfile.lock | 130 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 python/Pipfile.lock
python/Pipfile +1 -0
@@ -4,6 +4,7 @@ url = "https://pypi.org/simple" verify_ssl = true [dev-packages] +pylint = ">=2.7.0" [packages]
python/Pipfile.lock new file +130 -0
130 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v6 11/25] python: add pylint to pipenv
Quoted 7 lines · John Snow
We are specifying >= pylint 2.7.x for several reasons:
1. For setup.cfg support, added in pylint 2.5.x
2. To specify a version that has incompatibly dropped bad-whitespace checks (2.6.x)
3. 2.7.x fixes "unsubscriptable" warnings in Python 3.9
Quoted 7 lines
Signed-off-by John Snow <[email protected]>--- python/Pipfile | 1 + python/Pipfile.lock | 130 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 python/Pipfile.lock
Works as expected:
$ pipenv run pylint --version pylint 2.7.2 astroid 2.5.2 Python 3.6.13 (default, Feb 25 2021, 00:00:00) [GCC 11.0.0 20210210 (Red Hat 11.0.0-0)]
PATCH v6 12/25 python: move flake8 config to setup.cfg
In reply to John SnowUpdate 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
@@ -1,2 +0,0 @@ -[flake8] -extend-ignore = E722 # Pylint handles this, but smarter.
python/setup.cfg +3 -0
@@ -19,6 +19,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.30.2
PATCH v6 13/25 python: add excluded dirs to flake8 config
In reply to John SnowInstruct flake8 to avoid certain well-known directories created by python tooling that it ought not check.
Note that at-present, nothing actually creates a ".venv" directory; but it is in such widespread usage as a de-facto location for a developer's virtual environment that it should be excluded anyway. A forthcoming commit canonizes this with a "make venv" command.
--- python/setup.cfg | 2 ++ 1 file changed, 2 insertions(+)
python/setup.cfg +2 -0
@@ -21,6 +21,8 @@ packages = find_namespace: [flake8] extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's +exclude = __pycache__, + .venv, [pylint.messages control] # Disable the message, report, category or checker with the given id(s). You
Signature · 1 line
2.30.2
Re: [PATCH v6 13/25] python: add excluded dirs to flake8 config
Quoted 18 lines · John Snow
Instruct flake8 to avoid certain well-known directories created by python tooling that it ought not check.
Note that at-present, nothing actually creates a ".venv" directory; but it is in such widespread usage as a de-facto location for a developer's virtual environment that it should be excluded anyway. A forthcoming commit canonizes this with a "make venv" command.
Signed-off-by John Snow <[email protected]>--- python/setup.cfg | 2 ++ 1 file changed, 2 insertions(+)python/setup.cfg +0
-0
python/setup.cfg packages = find_namespace: · line 26
Quoted 6 lines
python/setup.cfg +2
-0@@ -21,6 +21,8 @@ packages = find_namespace: [flake8] extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's +exclude = __pycache__, + .venv,
Given that the default set of exclusions (version control system files) are not expected here, it LGTM to reset it with these.
Re: [PATCH v6 13/25] python: add excluded dirs to flake8 config
Quoted 29 lines · Cleber Rosa
Quoted 18 lines · John Snow
Instruct flake8 to avoid certain well-known directories created by python tooling that it ought not check.
Note that at-present, nothing actually creates a ".venv" directory; but it is in such widespread usage as a de-facto location for a developer's virtual environment that it should be excluded anyway. A forthcoming commit canonizes this with a "make venv" command.
Signed-off-by John Snow <[email protected]>--- python/setup.cfg | 2 ++ 1 file changed, 2 insertions(+)python/setup.cfg +0
-0python/setup.cfg packages = find_namespace: · line 26
Quoted 6 lines
python/setup.cfg +2
-0@@ -21,6 +21,8 @@ packages = find_namespace: [flake8] extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's +exclude = __pycache__, + .venv,Given that the default set of exclusions (version control system files) are not expected here, it LGTM to reset it with these.
Quoted 2 lines
Reviewed-by Cleber Rosa <[email protected]>
Yep. Admittedly, I just excluded things that caused me trouble in practice. I could narrow the flake8 invocation to specify *only* the qemu/ folder, but in the event we added Python tests or other scripts I actually felt like leaving it "open" would be fine.
(This way, flake8 runs like how I expect it to by just running "flake8" with no arguments, which I saw as nice.)
The goal was something like: the less specific I make the flake8 invocation, the better, even though I expect the linter to be run only by "make check" eventually, as a courtesy to mid-advanced users, keeping those canonical invocations simple felt good.
Thanks!
--js
PATCH v6 14/25 python: Add flake8 to pipenv
In reply to John Snowflake8 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 | 55 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 3 deletions(-)
python/Pipfile +1 -0
@@ -4,6 +4,7 @@ url = "https://pypi.org/simple" verify_ssl = true [dev-packages] +flake8 = ">=3.6.0" pylint = ">=2.7.0" [packages]
python/Pipfile.lock +52 -3
92 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v6 15/25 python: move mypy.ini into setup.cfg
In reply to John Snowmypy 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
@@ -1,4 +0,0 @@ -[mypy] -strict = True -python_version = 3.6 -warn_unused_configs = True
python/setup.cfg +5 -0
@@ -24,6 +24,11 @@ extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's exclude = __pycache__, .venv, +[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.30.2
Re: [PATCH v6 15/25] python: move mypy.ini into setup.cfg
Quoted 9 lines · John Snow
mypy supports reading its configuration values from a central project configuration file; do so.
Signed-off-by John Snow <[email protected]>--- python/mypy.ini | 4 ---- python/setup.cfg | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) delete mode 100644 python/mypy.ini
PATCH v6 16/25 python: add mypy to pipenv
In reply to John Snow0.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 -p qemu'.
A note on mypy invocation: Running it as "mypy qemu/" changes the import path detection mechanisms in mypy slightly, and it will fail. See
https://github.com/python/mypy/issues/8584 for a decent entry point with more breadcrumbs on the various behaviors that contribute to this subtle difference.
--- python/Pipfile | 1 + python/Pipfile.lock | 37 ++++++++++++++++++++++++++++++++++++- python/setup.cfg | 1 + 3 files changed, 38 insertions(+), 1 deletion(-)
python/Pipfile +1 -0
@@ -5,6 +5,7 @@ verify_ssl = true [dev-packages] flake8 = ">=3.6.0" +mypy = ">=0.770" pylint = ">=2.7.0" [packages]
python/Pipfile.lock +36 -1
@@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "4a4a9c6e09d9c5ce670fe4d067052a743dc3eff93c4790f9da31a0db2a66f8fc" + "sha256": "5e5b76eb2f6d8e833b79d9f083f08e0087b3e663275a00b84a6799419aa8a776" }, "pipfile-spec": 6, "requires": {
@@ -84,6 +84,41 @@ ], "version": "==0.6.1" }, + "mypy": { + "hashes": [ + "sha256:0d0a87c0e7e3a9becdfbe936c981d32e5ee0ccda3e0f07e1ef2c3d1a817cf73e", + "sha256:25adde9b862f8f9aac9d2d11971f226bd4c8fbaa89fb76bdadb267ef22d10064", + "sha256:28fb5479c494b1bab244620685e2eb3c3f988d71fd5d64cc753195e8ed53df7c", + "sha256:2f9b3407c58347a452fc0736861593e105139b905cca7d097e413453a1d650b4", + "sha256:33f159443db0829d16f0a8d83d94df3109bb6dd801975fe86bacb9bf71628e97", + "sha256:3f2aca7f68580dc2508289c729bd49ee929a436208d2b2b6aab15745a70a57df", + "sha256:499c798053cdebcaa916eef8cd733e5584b5909f789de856b482cd7d069bdad8", + "sha256:4eec37370483331d13514c3f55f446fc5248d6373e7029a29ecb7b7494851e7a", + "sha256:552a815579aa1e995f39fd05dde6cd378e191b063f031f2acfe73ce9fb7f9e56", + "sha256:5873888fff1c7cf5b71efbe80e0e73153fe9212fafdf8e44adfe4c20ec9f82d7", + "sha256:61a3d5b97955422964be6b3baf05ff2ce7f26f52c85dd88db11d5e03e146a3a6", + "sha256:674e822aa665b9fd75130c6c5f5ed9564a38c6cea6a6432ce47eafb68ee578c5", + "sha256:7ce3175801d0ae5fdfa79b4f0cfed08807af4d075b402b7e294e6aa72af9aa2a", + "sha256:9743c91088d396c1a5a3c9978354b61b0382b4e3c440ce83cf77994a43e8c521", + "sha256:9f94aac67a2045ec719ffe6111df543bac7874cee01f41928f6969756e030564", + "sha256:a26f8ec704e5a7423c8824d425086705e381b4f1dfdef6e3a1edab7ba174ec49", + "sha256:abf7e0c3cf117c44d9285cc6128856106183938c68fd4944763003decdcfeb66", + "sha256:b09669bcda124e83708f34a94606e01b614fa71931d356c1f1a5297ba11f110a", + "sha256:cd07039aa5df222037005b08fbbfd69b3ab0b0bd7a07d7906de75ae52c4e3119", + "sha256:d23e0ea196702d918b60c8288561e722bf437d82cb7ef2edcd98cfa38905d506", + "sha256:d65cc1df038ef55a99e617431f0553cd77763869eebdf9042403e16089fe746c", + "sha256:d7da2e1d5f558c37d6e8c1246f1aec1e7349e4913d8fb3cb289a35de573fe2eb" + ], + "index": "pypi", + "version": "==0.812" + }, + "mypy-extensions": { + "hashes": [ + "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d", + "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8" + ], + "version": "==0.4.3" + }, "pycodestyle": { "hashes": [ "sha256:514f76d918fcc0b55c6680472f0a37970994e07bbb80725808c17089be302068",
python/setup.cfg +1 -0
@@ -28,6 +28,7 @@ exclude = __pycache__, 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.30.2
PATCH v6 17/25 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
@@ -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
python/setup.cfg +8 -0
@@ -58,3 +58,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.30.2
PATCH v6 18/25 python/qemu: add isort to pipenv
In reply to John Snowisort 5.0.0 through 5.0.4 has a bug that causes it to misinterpret certain "from ..." clauses that are not related to imports.
isort < 5.1.1 has a bug where it does not handle comments near import statements correctly.
Require 5.1.2 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
@@ -5,6 +5,7 @@ verify_ssl = true [dev-packages] flake8 = ">=3.6.0" +isort = ">=5.1.2" mypy = ">=0.770" pylint = ">=2.7.0"
python/Pipfile.lock +2 -2
@@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "5e5b76eb2f6d8e833b79d9f083f08e0087b3e663275a00b84a6799419aa8a776" + "sha256": "e1f54e4d7fc287bdff731659614f5f9bbea2f1aee122ba04506ab26c4007440e" }, "pipfile-spec": 6, "requires": {
@@ -46,7 +46,7 @@ "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6", "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d" ], - "markers": "python_version >= '3.6' and python_version < '4.0'", + "index": "pypi", "version": "==5.8.0" }, "lazy-object-proxy": {
Signature · 1 line
2.30.2
Re: [PATCH v6 18/25] python/qemu: add isort to pipenv
Quoted 8 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.
isort < 5.1.1 has a bug where it does not handle comments near import statements correctly.
Require 5.1.2 or greater.
Quoted 7 lines
isort can be run with 'isort -c qemu' from the python root.
Signed-off-by John Snow <[email protected]>--- python/Pipfile | 1 + python/Pipfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
Re: [PATCH v6 18/25] python/qemu: add isort to pipenv
Quoted 11 lines · Cleber Rosa
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.
isort < 5.1.1 has a bug where it does not handle comments near import statements correctly.
Require 5.1.2 or greater.
isort can be run with 'isort -c qemu' from the python root.
Quoted 8 lines
Quoted 5 lines
Signed-off-by John Snow <[email protected]>--- python/Pipfile | 1 + python/Pipfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)Reviewed-by Cleber Rosa <[email protected]>
Thanks. I have also updated the commit message a little bit:
isort can be run (in "check" mode) with 'isort -c qemu' from the python root. isort can also be used to fix/rewrite import order automatically by using 'isort qemu'.
--js
Re: [PATCH v6 18/25] python/qemu: add isort to pipenv
Quoted 21 lines · John Snow
Quoted 11 lines · Cleber Rosa
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.
isort < 5.1.1 has a bug where it does not handle comments near import statements correctly.
Require 5.1.2 or greater.
isort can be run with 'isort -c qemu' from the python root.
Quoted 8 lines
Quoted 5 lines
Signed-off-by John Snow <[email protected]>--- python/Pipfile | 1 + python/Pipfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)Reviewed-by Cleber Rosa <[email protected]>
Quoted 7 lines
Thanks. I have also updated the commit message a little bit:
isort can be run (in "check" mode) with 'isort -c qemu' from the python root. isort can also be used to fix/rewrite import order automatically by using 'isort qemu'.
--js
OK, sounds even better!
- Cleber.
PATCH v6 19/25 python/qemu: add qemu package itself to pipenv
In reply to John SnowThis 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
@@ -10,6 +10,7 @@ mypy = ">=0.770" pylint = ">=2.7.0" [packages] +qemu = {editable = true,path = "."} [requires] python_version = "3.6"
python/Pipfile.lock +7 -2
@@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "e1f54e4d7fc287bdff731659614f5f9bbea2f1aee122ba04506ab26c4007440e" + "sha256": "986164b4c690953890066f288b48c3d84c63df86fc8fa30a26e9001d5b0968e0" }, "pipfile-spec": 6, "requires": {
@@ -15,7 +15,12 @@ } ] }, - "default": {}, + "default": { + "qemu": { + "editable": true, + "path": "." + } + }, "develop": { "astroid": { "hashes": [
Signature · 1 line
2.30.2
PATCH v6 20/25 python: add devel package requirements to setuptools
In reply to John Snowsetuptools doesn't have a formal understanding of development requires, but it has an optional feataures section. Fine; add a "devel" feature and add the requirements to it.
To avoid duplication, we can modify pipenv to install qemu[devel] instead. This enables us to run invocations like "pip install -e .[devel]" and test the package on bleeding-edge packages beyond those specified in Pipfile.lock.
Importantly, this also allows us to install the qemu development packages in a non-networked mode: pip3 install --no-index -e .[devel] will now fail if the proper development dependencies are not already met. This can be useful for automated build scripts where fetching network packages may be undesirable.
--- python/Pipfile | 5 +---- python/Pipfile.lock | 14 +++++++++----- python/setup.cfg | 9 +++++++++ 3 files changed, 19 insertions(+), 9 deletions(-)
python/Pipfile +1 -4
@@ -4,10 +4,7 @@ url = "https://pypi.org/simple" verify_ssl = true [dev-packages] -flake8 = ">=3.6.0" -isort = ">=5.1.2" -mypy = ">=0.770" -pylint = ">=2.7.0" +qemu = {editable = true, extras = ["devel"], path = "."} [packages] qemu = {editable = true,path = "."}
python/Pipfile.lock +9 -5
@@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "986164b4c690953890066f288b48c3d84c63df86fc8fa30a26e9001d5b0968e0" + "sha256": "eff562a688ebc6f3ffe67494dbb804b883e2159ad81c4d55d96da9f7aec13e91" }, "pipfile-spec": 6, "requires": {
@@ -35,7 +35,7 @@ "sha256:12d05ab02614b6aee8df7c36b97d1a3b2372761222b19b58621355e82acddcff", "sha256:78873e372b12b093da7b5e5ed302e8ad9e988b38b063b61ad937f26ca58fc5f0" ], - "index": "pypi", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", "version": "==3.9.0" }, "importlib-metadata": {
@@ -51,7 +51,7 @@ "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6", "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d" ], - "index": "pypi", + "markers": "python_version >= '3.6' and python_version < '4.0'", "version": "==5.8.0" }, "lazy-object-proxy": {
@@ -114,7 +114,7 @@ "sha256:d65cc1df038ef55a99e617431f0553cd77763869eebdf9042403e16089fe746c", "sha256:d7da2e1d5f558c37d6e8c1246f1aec1e7349e4913d8fb3cb289a35de573fe2eb" ], - "index": "pypi", + "markers": "python_version >= '3.5'", "version": "==0.812" }, "mypy-extensions": {
@@ -145,9 +145,13 @@ "sha256:0e21d3b80b96740909d77206d741aa3ce0b06b41be375d92e1f3244a274c1f8a", "sha256:d09b0b07ba06bcdff463958f53f23df25e740ecd81895f7d2699ec04bbd8dc3b" ], - "index": "pypi", + "markers": "python_version ~= '3.6'", "version": "==2.7.2" }, + "qemu": { + "editable": true, + "path": "." + }, "toml": { "hashes": [ "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
python/setup.cfg +9 -0
@@ -19,6 +19,15 @@ classifiers = python_requires = >= 3.6 packages = find_namespace: +[options.extras_require] +# Run `pipenv lock` when changing these requirements. +devel = + flake8 >= 3.6.0 + isort >= 5.1.2 + mypy >= 0.770 + pylint >= 2.7.0 + + [flake8] extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's exclude = __pycache__,
Signature · 1 line
2.30.2
Re: [PATCH v6 20/25] python: add devel package requirements to setuptools
Quoted 9 lines · John Snow
setuptools doesn't have a formal understanding of development requires, but it has an optional feataures section. Fine; add a "devel" feature and add the requirements to it.
To avoid duplication, we can modify pipenv to install qemu[devel] instead. This enables us to run invocations like "pip install -e .[devel]" and test the package on bleeding-edge packages beyond those specified in Pipfile.lock.
Quoted 6 lines
Importantly, this also allows us to install the qemu development packages in a non-networked mode:
pip3 install --no-index -e .[devel]will now fail if the proper development dependencies are not already met. This can be useful for automated build scripts where fetching network packages may be undesirable.
This is a fairly exotic feature of setuptools, with very very few packages that I know about using it. With most users (I believe) relying on pipenv to get the exact packages, the setuptools/pip use case may fall into obscurity IMO.
So my suggestion is: consider better exposing the fact that this is available (a documentation section perhaps).
Quoted 7 lines
Signed-off-by John Snow <[email protected]>--- python/Pipfile | 5 +---- python/Pipfile.lock | 14 +++++++++----- python/setup.cfg | 9 +++++++++ 3 files changed, 19 insertions(+), 9 deletions(-)
Either way,
Re: [PATCH v6 20/25] python: add devel package requirements to setuptools
Quoted 17 lines · Cleber Rosa
Quoted 9 lines · John Snow
setuptools doesn't have a formal understanding of development requires, but it has an optional feataures section. Fine; add a "devel" feature and add the requirements to it.
To avoid duplication, we can modify pipenv to install qemu[devel] instead. This enables us to run invocations like "pip install -e .[devel]" and test the package on bleeding-edge packages beyond those specified in Pipfile.lock.
Quoted 6 lines
Importantly, this also allows us to install the qemu development packages in a non-networked mode:
pip3 install --no-index -e .[devel]will now fail if the proper development dependencies are not already met. This can be useful for automated build scripts where fetching network packages may be undesirable.
Quoted 5 lines
This is a fairly exotic feature of setuptools, with very very few packages that I know about using it. With most users (I believe) relying on pipenv to get the exact packages, the setuptools/pip use case may fall into obscurity IMO.
Fair enough.
The intent is:
- Pipenv is more for CI, to deploy a consistent set of frozen packages that are known to behave in an extremely stable manner. My hope is to avoid breaking changes introduced unknowingly by pylint et al.
- pip install qemu[devel] is intended more for external/normal use by developers. It grabs the latest and greatest and it may indeed break as dependencies change beyond my awareness.
Some packages like aiohttp use that optional dependency feature to install optional modules -- pip install aiohttp[speedups] installs optional dependencies that allow that module to work much faster, but aren't required.
Since these linting tools aren't *required* just to *use* the package, I am doing users a courtesy by listing them as optional. That way, they aren't pulled in when using "pip install qemu", and if I have to pin on specific sub-versions etc, it won't include conflict dependencies for people using other projects that DO declare a hard requirement on those packages.
I can amend the PACKAGE.rst file to mention this usage, though it's only useful for folks developing the package.
(Still, part of the ploy here is to attract outside help on developing the QEMU SDK, pull requests welcome etc, so it's worth a documentation blurb for now.)
Quoted 11 lines
So my suggestion is: consider better exposing the fact that this is available (a documentation section perhaps).
Quoted 7 lines
Signed-off-by John Snow <[email protected]>--- python/Pipfile | 5 +---- python/Pipfile.lock | 14 +++++++++----- python/setup.cfg | 9 +++++++++ 3 files changed, 19 insertions(+), 9 deletions(-)
Quoted 4 lines
Either way,
Reviewed-by Cleber Rosa <[email protected]>
Thanks! I am taking your R-B and I have applied the following diff.
Note that the PACKAGE.rst blurb references qemu[devel] instead because the PACKAGE.rst file is what is displayed theoretically on PyPI. That exact invocation will fail currently, because it's not on PyPI yet.
A little weird, but I *think* it's correct.
python/PACKAGE.rst +4 -0
@@ -31,3 +31,7 @@ official `GitLab mirror <https://gitlab.com/qemu-project/qemu>`_. Please report bugs on the `QEMU issue tracker <https://gitlab.com/qemu-project/qemu/-/issues>`_ and tag ``@jsnow`` in the report. + +Optional packages necessary for running code quality analysis for this +package can be installed with the optional dependency group "devel": +``pip install qemu[devel]``.
python/README.rst +4 -0
@@ -24,6 +24,10 @@ which installs a version of the package that installs a forwarder pointing to these files, such that the package always reflects the latest version in your git tree. +Installing ".[devel]" instead of "." will additionally pull in required +packages for testing this package. They are not runtime requirements, +and are not needed to simply use these libraries. + See `Installing packages using pip and virtual environments
<https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>`_
for more information.
Cleber Rosa
Reviewed-byRe: [PATCH v6 20/25] python: add devel package requirements to setuptools
Quoted 48 lines · John Snow
Quoted 17 lines · Cleber Rosa
Quoted 9 lines · John Snow
setuptools doesn't have a formal understanding of development requires, but it has an optional feataures section. Fine; add a "devel" feature and add the requirements to it.
To avoid duplication, we can modify pipenv to install qemu[devel] instead. This enables us to run invocations like "pip install -e .[devel]" and test the package on bleeding-edge packages beyond those specified in Pipfile.lock.
Quoted 6 lines
Importantly, this also allows us to install the qemu development packages in a non-networked mode:
pip3 install --no-index -e .[devel]will now fail if the proper development dependencies are not already met. This can be useful for automated build scripts where fetching network packages may be undesirable.Quoted 5 lines
This is a fairly exotic feature of setuptools, with very very few packages that I know about using it. With most users (I believe) relying on pipenv to get the exact packages, the setuptools/pip use case may fall into obscurity IMO.
Fair enough.
The intent is:
- Pipenv is more for CI, to deploy a consistent set of frozen packages that are known to behave in an extremely stable manner. My hope is to avoid breaking changes introduced unknowingly by pylint et al.
- pip install qemu[devel] is intended more for external/normal use by developers. It grabs the latest and greatest and it may indeed break as dependencies change beyond my awareness.
Some packages like aiohttp use that optional dependency feature to install optional modules --
pip install aiohttp[speedups]installs optional dependencies that allow that module to work much faster, but aren't required.Since these linting tools aren't *required* just to *use* the package, I am doing users a courtesy by listing them as optional. That way, they aren't pulled in when using "pip install qemu", and if I have to pin on specific sub-versions etc, it won't include conflict dependencies for people using other projects that DO declare a hard requirement on those packages.
Quoted 7 lines
I can amend the
PACKAGE.rstfile to mention this usage, though it's only useful for folks developing the package.(Still, part of the ploy here is to attract outside help on developing the QEMU SDK, pull requests welcome etc, so it's worth a documentation blurb for now.)
Yep, I agree with your reasoning here. I just felt like an extra bit of documentation would do the trick.
Quoted 53 lines
Quoted 11 lines
So my suggestion is: consider better exposing the fact that this is available (a documentation section perhaps).
Quoted 7 lines
Signed-off-by John Snow <[email protected]>--- python/Pipfile | 5 +---- python/Pipfile.lock | 14 +++++++++----- python/setup.cfg | 9 +++++++++ 3 files changed, 19 insertions(+), 9 deletions(-)Quoted 4 lines
Either way,
Reviewed-by Cleber Rosa <[email protected]>Thanks! I am taking your R-B and I have applied the following diff.
Note that the
PACKAGE.rstblurb references qemu[devel] instead because thePACKAGE.rstfile is what is displayed theoretically on PyPI. That exact invocation will fail currently, because it's not on PyPI yet.A little weird, but I *think* it's correct.
python/PACKAGE.rst +0
-0@@ -31,3 +31,7 @@ official `GitLab mirror<https://gitlab.com/qemu-project/qemu>`_.
Please report bugs on the `QEMU issue tracker
<https://gitlab.com/qemu-project/qemu/-/issues>`_ and tag ``@jsnow`` in the report.python/PACKAGE.rst +4
-0+ +Optional packages necessary for running code quality analysis for this +package can be installed with the optional dependency group "devel": +``pip install qemu[devel]``.python/README.rst +0
-0@@ -24,6 +24,10 @@ which installs a version of the package that installs aforwarder
pointing to these files, such that the package always reflects the latest version in your git tree.python/README.rst +4
-0+Installing ".[devel]" instead of "." will additionally pull in required +packages for testing this package. They are not runtime requirements, +and are not needed to simply use these libraries. + See `Installing packages using pip and virtual environments
Quoted 2 lines
<https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>`_
for more information.
Looks great to me. And, let me be clear about it:
PATCH v6 21/25 python: add avocado-framework and tests
In reply to John SnowTry using avocado to manage our various tests; even though right now they're only invoking shell scripts and not really running any python-native code.
Create tests/, and add shell scripts which call out to mypy, flake8, pylint and isort to enforce the standards in this directory.
Add avocado-framework to the setup.cfg development dependencies, and add avocado.cfg to store some preferences for how we'd like the test output to look.
Finally, add avocado-framework to the Pipfile environment and lock the new dependencies. We are using avocado >= 87.0 here to take advantage of some features that Cleber has helpfully added to make the test output here *very* friendly and easy to read for developers that might chance upon the output in Gitlab CI.
[Note: ALL of the dependencies get updated to the most modern versions that exist at the time of this writing. No way around it that I have seen. Not ideal, but so it goes.]
Provided you have the right development dependencies (mypy, flake8, isort, pylint, and now avocado-framework) You should be able to run "avocado --config avocado.cfg run tests/" from the python folder to run all of these linters with the correct arguments.
(A forthcoming commit adds the much easier 'make check'.)
--- python/README.rst | 2 + python/Pipfile.lock | 104 ++++++++++++++++++++++------------------- python/avocado.cfg | 10 ++++ python/setup.cfg | 1 + python/tests/flake8.sh | 2 + python/tests/isort.sh | 2 + python/tests/mypy.sh | 2 + python/tests/pylint.sh | 2 + 8 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 python/avocado.cfg create mode 100755 python/tests/flake8.sh create mode 100755 python/tests/isort.sh create mode 100755 python/tests/mypy.sh create mode 100755 python/tests/pylint.sh
python/README.rst +2 -0
@@ -33,6 +33,8 @@ Files in this directory ----------------------- - ``qemu/`` Python package source directory. +- ``tests/`` Python package tests directory. +- ``avocado.cfg`` Configuration for the Avocado test-runner. - ``MANIFEST.in`` is read by python setuptools, it specifies additional files that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org.
python/Pipfile.lock +56 -48
142 lines not on this page · raw message
python/avocado.cfg new file +10 -0
@@ -0,0 +1,10 @@ +[simpletests] +# Don't show stdout/stderr in the test *summary* +status.failure_fields = ['status'] + +[job] +# Don't show the full debug.log output; only select stdout/stderr. +output.testlogs.logfiles = ['stdout', 'stderr'] + +# Show full stdout/stderr only on tests that FAIL +output.testlogs.statuses = ['FAIL']
python/setup.cfg +1 -0
@@ -26,6 +26,7 @@ devel = isort >= 5.1.2 mypy >= 0.770 pylint >= 2.7.0 + avocado-framework >= 87.0 [flake8]
python/tests/flake8.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m flake8
python/tests/isort.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m isort -c qemu/
python/tests/mypy.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m mypy -p qemu
python/tests/pylint.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m pylint qemu/
Signature · 1 line
2.30.2
Re: [PATCH v6 21/25] python: add avocado-framework and tests
Quoted 29 lines · John Snow
Try using avocado to manage our various tests; even though right now they're only invoking shell scripts and not really running any python-native code.
Create tests/, and add shell scripts which call out to mypy, flake8, pylint and isort to enforce the standards in this directory.
Add avocado-framework to the setup.cfg development dependencies, and add avocado.cfg to store some preferences for how we'd like the test output to look.
Finally, add avocado-framework to the Pipfile environment and lock the new dependencies. We are using avocado >= 87.0 here to take advantage of some features that Cleber has helpfully added to make the test output here *very* friendly and easy to read for developers that might chance upon the output in Gitlab CI.
[Note: ALL of the dependencies get updated to the most modern versions that exist at the time of this writing. No way around it that I have seen. Not ideal, but so it goes.]
Provided you have the right development dependencies (mypy, flake8, isort, pylint, and now avocado-framework) You should be able to run "avocado --config avocado.cfg run tests/" from the python folder to run all of these linters with the correct arguments.
(A forthcoming commit adds the much easier 'make check'.)
Signed-off-by John Snow <[email protected]>
Quoted 16 lines
--- python/README.rst | 2 + python/Pipfile.lock | 104 ++++++++++++++++++++++------------------- python/avocado.cfg | 10 ++++ python/setup.cfg | 1 + python/tests/flake8.sh | 2 + python/tests/isort.sh | 2 + python/tests/mypy.sh | 2 + python/tests/pylint.sh | 2 + 8 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 python/avocado.cfg create mode 100755 python/tests/flake8.sh create mode 100755 python/tests/isort.sh create mode 100755 python/tests/mypy.sh create mode 100755 python/tests/pylint.sh
With the patches from your "Python: delint python library" series:
$ pipenv run avocado --config avocado.cfg run tests/
JOB ID : b27b48eded8b405c6672e61e3d1561407fca9d5e
JOB LOG : /home/cleber/avocado/job-results/job-2021-05-25T14.56-b27b48e/job.log
(1/4) tests/flake8.sh: PASS (0.67 s)
(2/4) tests/isort.sh: PASS (0.37 s)
(3/4) tests/mypy.sh: PASS (0.39 s)
(4/4) tests/pylint.sh: PASS (4.85 s)
RESULTS : PASS 4 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME : 6.75 sPATCH v6 22/25 python: add Makefile for some common tasks
In reply to John SnowAdd "make venv" to create the pipenv-managed virtual environment that contains our explicitly pinned dependencies.
Add "make check" to run the python linters [in the host execution environment].
Add "make venv-check" which combines the above two: create/update the venv, then run the linters in that explicitly managed environment.
Add "make develop" which canonizes the runes needed to get both the linting pre-requisites (the "[devel]" part), and the editable live-install (the "-e" part) of these python libraries.
make clean: delete miscellaneous python packaging output possibly created by pipenv, pip, or other python packaging utilities
make distclean: delete the above, the .venv, and the editable "qemu" package forwarder (qemu.egg-info) if there is one.
--- python/README.rst | 3 +++ python/Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 python/Makefile
python/README.rst +3 -0
@@ -35,6 +35,9 @@ Files in this directory - ``qemu/`` Python package source directory. - ``tests/`` Python package tests directory. - ``avocado.cfg`` Configuration for the Avocado test-runner. + Used by ``make check`` et al. +- ``Makefile`` provides some common testing/installation invocations. + Try ``make help`` to see available targets. - ``MANIFEST.in`` is read by python setuptools, it specifies additional files that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org.
python/Makefile new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v6 22/25] python: add Makefile for some common tasks
Quoted 54 lines · John Snow
Add "make venv" to create the pipenv-managed virtual environment that contains our explicitly pinned dependencies.
Add "make check" to run the python linters [in the host execution environment].
Add "make venv-check" which combines the above two: create/update the venv, then run the linters in that explicitly managed environment.
Add "make develop" which canonizes the runes needed to get both the linting pre-requisites (the "[devel]" part), and the editable live-install (the "-e" part) of these python libraries.
make clean: delete miscellaneous python packaging output possibly created by pipenv, pip, or other python packaging utilities
make distclean: delete the above, the .venv, and the editable "qemu" package forwarder (qemu.egg-info) if there is one.
Signed-off-by John Snow <[email protected]>--- python/README.rst | 3 +++ python/Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 python/Makefilepython/README.rst +3
-0@@ -35,6 +35,9 @@ Files in this directory - ``qemu/`` Python package source directory. - ``tests/`` Python package tests directory. - ``avocado.cfg`` Configuration for the Avocado test-runner. + Used by ``make check`` et al. +- ``Makefile`` provides some common testing/installation invocations. + Try ``make help`` to see available targets. - ``MANIFEST.in`` is read by python setuptools, it specifies additional files that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org.python/Makefile new file +8
-0@@ -0,0 +1,42 @@ +.PHONY: help venv venv-check check clean distclean develop + +help: + @echo "python packaging help:" + @echo "" + @echo "make venv: Create pipenv's virtual environment." + @echo " NOTE: Requires Python 3.6 and pipenv." + @echo " Will download packages from PyPI."
python/Makefile line 18
Quoted 10 lines
python/Makefile new file +10
-0+ @echo " Hint: (On Fedora): 'sudo dnf install python36 pipenv'" + @echo "" + @echo "make venv-check: run linters using pipenv's virtual environment." + @echo " Hint: If you don't know which test to run, run this one!" + @echo "" + @echo "make develop: Install deps for 'make check', and" + @echo " the qemu libs in editable/development mode." + @echo "" + @echo "make check: run linters using the current environment." + @echo ""
Let's observe how this will be used (or misused). I fear most people will jump into make check, even though you have described make venv-check as the primary choice.
We have a precedent with make check-acceptance that will create a venv and use it by default, so we can consider that as a fallback strategy based on user feedback.
Quoted 12 lines
python/Makefile new file +12
-0+ @echo "make clean: remove build output." + @echo "" + @echo "make distclean: remove venv files, qemu package forwarder, and" + @echo " everything from 'make clean'." + +venv: .venv +.venv: Pipfile.lock + @PIPENV_VENV_IN_PROJECT=1 pipenv sync --dev --keep-outdated + @touch .venv + +venv-check: venv + @pipenv run make check
python/Makefile line 40
Quoted 10 lines
python/Makefile new file +10
-0+ +develop: + pip3 install -e .[devel] + +check: + @avocado --config avocado.cfg run tests/ + +clean: + rm -rf build/ dist/ +
Usually python3 setup.py clean --all would be the better choice here, but, it doesn't clean dist/, so I'm OK with this.
Quoted 6 lines
python/Makefile new file +2
-0+distclean: clean + rm -rf qemu.egg-info/ .venv/Signature · 1 line
2.30.2
Re: [PATCH v6 22/25] python: add Makefile for some common tasks
Quoted 70 lines · Cleber Rosa
Quoted 54 lines · John Snow
Add "make venv" to create the pipenv-managed virtual environment that contains our explicitly pinned dependencies.
Add "make check" to run the python linters [in the host execution environment].
Add "make venv-check" which combines the above two: create/update the venv, then run the linters in that explicitly managed environment.
Add "make develop" which canonizes the runes needed to get both the linting pre-requisites (the "[devel]" part), and the editable live-install (the "-e" part) of these python libraries.
make clean: delete miscellaneous python packaging output possibly created by pipenv, pip, or other python packaging utilities
make distclean: delete the above, the .venv, and the editable "qemu" package forwarder (qemu.egg-info) if there is one.
Signed-off-by John Snow <[email protected]>--- python/README.rst | 3 +++ python/Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)create mode 100644 python/Makefile
python/README.rst +3
-0@@ -35,6 +35,9 @@ Files in this directory - ``qemu/`` Python package source directory. - ``tests/`` Python package tests directory. - ``avocado.cfg`` Configuration for the Avocado test-runner. + Used by ``make check`` et al. +- ``Makefile`` provides some common testing/installation invocations. + Try ``make help`` to see available targets. - ``MANIFEST.in`` is read by python setuptools, it specifies additional files that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org.python/Makefile new file +8
-0@@ -0,0 +1,42 @@ +.PHONY: help venv venv-check check clean distclean develop + +help: + @echo "python packaging help:" + @echo "" + @echo "make venv: Create pipenv's virtual environment." + @echo " NOTE: Requires Python 3.6 and pipenv." + @echo " Will download packages from PyPI."python/Makefile line 18
Quoted 10 lines
python/Makefile new file +10
-0+ @echo " Hint: (On Fedora): 'sudo dnf install python36 pipenv'" + @echo "" + @echo "make venv-check: run linters using pipenv's virtual environment." + @echo " Hint: If you don't know which test to run, run this one!" + @echo "" + @echo "make develop: Install deps for 'make check', and" + @echo " the qemu libs in editable/development mode." + @echo "" + @echo "make check: run linters using the current environment." + @echo ""Let's observe how this will be used (or misused). I fear most people will jump into
make check, even though you have describedmake venv-checkas the primary choice.
Quoted 4 lines
We have a precedent with
make check-acceptancethat will create a venv and use it by default, so we can consider that as a fallback strategy based on user feedback.
Right, I see. Though, I did intentionally want to make it clear which of these invocations created an environment and which did not.
Unlike the acceptance tests, it might make sense to run these tests both inside and outside of that venv, so I opted to make the default "make" target "make help".
The Gitlab CI will run the right one, after all -- and I do still expect the regular 'make check' to pass, so I am not as sure that it's a crucial failure if someone runs the "wrong one".
Quoted 17 lines
Quoted 17 lines
python/Makefile new file +17
-0+ @echo "make clean: remove build output." + @echo "" + @echo "make distclean: remove venv files, qemu package forwarder, and" + @echo " everything from 'make clean'." + +venv: .venv +.venv: Pipfile.lock + @PIPENV_VENV_IN_PROJECT=1 pipenv sync --dev --keep-outdated + @touch .venv + +venv-check: venv + @pipenv run make check + +develop: + pip3 install -e .[devel] + +check:
Quoted 9 lines
python/Makefile line 40
Quoted 5 lines
python/Makefile new file +5
-0+ @avocado --config avocado.cfg run tests/ + +clean: + rm -rf build/ dist/ +Usually
python3 setup.py clean --allwould be the better choice here, but, it doesn't cleandist/, so I'm OK with this.
Hm, I should probably move the 'dist' down into 'distclean' anyway, and I will replace the clean invocation with the one you suggest.
Quoted 10 lines
Quoted 6 lines
python/Makefile new file +2
-0+distclean: clean + rm -rf qemu.egg-info/ .venv/Signature · 1 line
2.30.2Reviewed-by Cleber Rosa <[email protected]>Tested-by Cleber Rosa <[email protected]>
Re: [PATCH v6 22/25] python: add Makefile for some common tasks
Quoted 114 lines · John Snow
Quoted 70 lines · Cleber Rosa
Quoted 54 lines · John Snow
Add "make venv" to create the pipenv-managed virtual environment that contains our explicitly pinned dependencies.
Add "make check" to run the python linters [in the host execution environment].
Add "make venv-check" which combines the above two: create/update the venv, then run the linters in that explicitly managed environment.
Add "make develop" which canonizes the runes needed to get both the linting pre-requisites (the "[devel]" part), and the editable live-install (the "-e" part) of these python libraries.
make clean: delete miscellaneous python packaging output possibly created by pipenv, pip, or other python packaging utilities
make distclean: delete the above, the .venv, and the editable "qemu" package forwarder (qemu.egg-info) if there is one.
Signed-off-by John Snow <[email protected]>--- python/README.rst | 3 +++ python/Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)create mode 100644 python/Makefile
python/README.rst +3
-0@@ -35,6 +35,9 @@ Files in this directory - ``qemu/`` Python package source directory. - ``tests/`` Python package tests directory. - ``avocado.cfg`` Configuration for the Avocado test-runner. + Used by ``make check`` et al. +- ``Makefile`` provides some common testing/installation invocations. + Try ``make help`` to see available targets. - ``MANIFEST.in`` is read by python setuptools, it specifies additional files that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org.python/Makefile new file +8
-0@@ -0,0 +1,42 @@ +.PHONY: help venv venv-check check clean distclean develop + +help: + @echo "python packaging help:" + @echo "" + @echo "make venv: Create pipenv's virtual environment." + @echo " NOTE: Requires Python 3.6 and pipenv." + @echo " Will download packages from PyPI."python/Makefile line 18
Quoted 10 lines
python/Makefile new file +10
-0+ @echo " Hint: (On Fedora): 'sudo dnf install python36 pipenv'" + @echo "" + @echo "make venv-check: run linters using pipenv's virtual environment." + @echo " Hint: If you don't know which test to run, run this one!" + @echo "" + @echo "make develop: Install deps for 'make check', and" + @echo " the qemu libs in editable/development mode." + @echo "" + @echo "make check: run linters using the current environment." + @echo ""Let's observe how this will be used (or misused). I fear most people will jump into
make check, even though you have describedmake venv-checkas the primary choice.Quoted 4 lines
We have a precedent with
make check-acceptancethat will create a venv and use it by default, so we can consider that as a fallback strategy based on user feedback.Right, I see. Though, I did intentionally want to make it clear which of these invocations created an environment and which did not.
Unlike the acceptance tests, it might make sense to run these tests both inside and outside of that venv, so I opted to make the default "make" target "make help".
The Gitlab CI will run the right one, after all -- and I do still expect the regular 'make check' to pass, so I am not as sure that it's a crucial failure if someone runs the "wrong one".
Quoted 17 lines
Quoted 17 lines
python/Makefile new file +17
-0+ @echo "make clean: remove build output." + @echo "" + @echo "make distclean: remove venv files, qemu package forwarder, and" + @echo " everything from 'make clean'." + +venv: .venv +.venv: Pipfile.lock + @PIPENV_VENV_IN_PROJECT=1 pipenv sync --dev --keep-outdated + @touch .venv + +venv-check: venv + @pipenv run make check + +develop: + pip3 install -e .[devel] + +check:Quoted 9 lines
python/Makefile line 40
Quoted 5 lines
python/Makefile new file +5
-0+ @avocado --config avocado.cfg run tests/ + +clean: + rm -rf build/ dist/ +Usually
python3 setup.py clean --allwould be the better choice here, but, it doesn't cleandist/, so I'm OK with this.
Quoted 3 lines
Hm, I should probably move the 'dist' down into 'distclean' anyway, and I will replace the clean invocation with the one you suggest.
OK then, makes sense to me.
- Cleber.
PATCH v6 23/25 python: add .gitignore
In reply to John SnowIgnore *Python* build and package output (build, dist, qemu.egg-info); these files are not created as part of a QEMU build.
Ignore miscellaneous cached python confetti (__pycache__, *.pyc, .mypy_cache).
Ignore .idea (pycharm) .vscode, and .venv (pipenv et al).
--- python/.gitignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 python/.gitignore
python/.gitignore new file +19 -0
@@ -0,0 +1,19 @@ +# python bytecode cache +*.pyc +__pycache__/ + +# linter/tooling cache +.mypy_cache/ +.cache/ + +# python packaging +build/ +dist/ +qemu.egg-info/ + +# editor config +.idea/ +.vscode/ + +# virtual environments (pipenv et al) +.venv/
Signature · 1 line
2.30.2
Re: [PATCH v6 23/25] python: add .gitignore
Quoted 20 lines · John Snow
Ignore *Python* build and package output (build, dist, qemu.egg-info); these files are not created as part of a QEMU build.
Ignore miscellaneous cached python confetti (
__pycache__, *.pyc, .mypy_cache).Ignore .idea (pycharm) .vscode, and .venv (pipenv et al).
Signed-off-by John Snow <[email protected]>--- python/.gitignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 python/.gitignorepython/.gitignore new file +0
-0
python/.gitignore line 2
Quoted 2 lines
python/.gitignore new file +2
-0@@ -0,0 +1,19 @@ +# python bytecode cache +*.pyc
This is a duplicate from the parent .gitignore, so I would avoid it.
python/.gitignore line 3
Quoted 1 line
python/.gitignore new file +1
-0+__pycache__/
And this one is interesting because, the only thing that *should* be in __pycache__ dirs is .pyc files (covered by the parent .gitignore file).
So, I get the same behavior without these two entries here, so I would skip them. Let me know if you have any reason for explicitly including them.
- Cleber.
Re: [PATCH v6 23/25] python: add .gitignore
Quoted 32 lines · Cleber Rosa
Quoted 20 lines · John Snow
Ignore *Python* build and package output (build, dist, qemu.egg-info); these files are not created as part of a QEMU build.
Ignore miscellaneous cached python confetti (
__pycache__, *.pyc, .mypy_cache).Ignore .idea (pycharm) .vscode, and .venv (pipenv et al).
Signed-off-by John Snow <[email protected]>--- python/.gitignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)create mode 100644 python/.gitignore
python/.gitignore new file +0
-0python/.gitignore line 2
Quoted 2 lines
python/.gitignore new file +2
-0@@ -0,0 +1,19 @@ +# python bytecode cache +*.pycThis is a duplicate from the parent .gitignore, so I would avoid it.
python/.gitignore line 3
Quoted 1 line
python/.gitignore new file +1
-0+__pycache__/And this one is interesting because, the only thing that *should* be in
__pycache__dirs is .pyc files (covered by the parent .gitignore file).
Quoted 6 lines
So, I get the same behavior without these two entries here, so I would skip them. Let me know if you have any reason for explicitly including them.
- Cleber.
Hm, not really ... Just completeness, I suppose, since this directory is becoming increasingly separate from the rest of the tree.
It isn't crucial, it just seemed like a weird omission if they weren't listed here. *shrug*
--js
Re: [PATCH v6 23/25] python: add .gitignore
Quoted 40 lines · John Snow
Quoted 32 lines · Cleber Rosa
Quoted 20 lines · John Snow
Ignore *Python* build and package output (build, dist, qemu.egg-info); these files are not created as part of a QEMU build.
Ignore miscellaneous cached python confetti (
__pycache__, *.pyc, .mypy_cache).Ignore .idea (pycharm) .vscode, and .venv (pipenv et al).
Signed-off-by John Snow <[email protected]>--- python/.gitignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)create mode 100644 python/.gitignore
python/.gitignore new file +0
-0python/.gitignore line 2
Quoted 2 lines
python/.gitignore new file +2
-0@@ -0,0 +1,19 @@ +# python bytecode cache +*.pycThis is a duplicate from the parent .gitignore, so I would avoid it.
python/.gitignore line 3
Quoted 1 line
python/.gitignore new file +1
-0+__pycache__/And this one is interesting because, the only thing that *should* be in
__pycache__dirs is .pyc files (covered by the parent .gitignore file).Quoted 6 lines
So, I get the same behavior without these two entries here, so I would skip them. Let me know if you have any reason for explicitly including them.
- Cleber.
Quoted 7 lines
Hm, not really ... Just completeness, I suppose, since this directory is becoming increasingly separate from the rest of the tree.
It isn't crucial, it just seemed like a weird omission if they weren't listed here. *shrug*
--js
And still, this dir is part of the overall tree. Honestly, without any change in behavior, I'd *not* add those two ignore rules.
Cheers,
- Cleber.
Re: [PATCH v6 23/25] python: add .gitignore
Quoted 44 lines · Cleber Rosa
Quoted 43 lines · John Snow
Quoted 32 lines · Cleber Rosa
Quoted 20 lines · John Snow
Ignore *Python* build and package output (build, dist, qemu.egg-info); these files are not created as part of a QEMU build.
Ignore miscellaneous cached python confetti (
__pycache__, *.pyc, .mypy_cache).Ignore .idea (pycharm) .vscode, and .venv (pipenv et al).
Signed-off-by John Snow <[email protected]>--- python/.gitignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)create mode 100644 python/.gitignore
python/.gitignore new file +0
-0python/.gitignore line 2
Quoted 2 lines
python/.gitignore new file +2
-0@@ -0,0 +1,19 @@ +# python bytecode cache +*.pycThis is a duplicate from the parent .gitignore, so I would avoid it.
python/.gitignore line 3
Quoted 1 line
python/.gitignore new file +1
-0+__pycache__/And this one is interesting because, the only thing that *should* be in
__pycache__dirs is .pyc files (covered by the parent .gitignore file).Quoted 6 lines
So, I get the same behavior without these two entries here, so I would skip them. Let me know if you have any reason for explicitly including them.
- Cleber.
Hm, not really ... Just completeness, I suppose, since this directory is becoming increasingly separate from the rest of the tree.
Quoted 6 lines
Quoted 4 lines
It isn't crucial, it just seemed like a weird omission if they weren't listed here. *shrug*
--js
And still, this dir is part of the overall tree.
For now 😇
Honestly, without
Quoted 2 lines
any change in behavior, I'd *not* add those two ignore rules.
If you insist.
--js
PATCH v6 24/25 gitlab: add python linters to CI
In reply to John SnowAdd python3.6 to the fedora container image: we need it to run the linters against that explicit version to make sure we don't break our minimum version promise.
Add pipenv so that we can fetch precise versions of pip packages we need to guarantee test reproducability.
--- .gitlab-ci.yml | 12 ++++++++++++ tests/docker/dockerfiles/fedora.docker | 2 ++ 2 files changed, 14 insertions(+)
.gitlab-ci.yml +12 -0
@@ -779,6 +779,18 @@ check-patch: GIT_DEPTH: 1000 allow_failure: true + +check-python: + stage: test + image: $CI_REGISTRY_IMAGE/qemu/fedora:latest + script: + - cd python + - make venv-check + variables: + GIT_DEPTH: 1000 + needs: + job: amd64-fedora-container + check-dco: stage: build image: $CI_REGISTRY_IMAGE/qemu/centos8:latest
tests/docker/dockerfiles/fedora.docker +2 -0
@@ -84,6 +84,7 @@ ENV PACKAGES \ numactl-devel \ perl \ perl-Test-Harness \ + pipenv \ pixman-devel \ python3 \ python3-PyYAML \
@@ -93,6 +94,7 @@ ENV PACKAGES \ python3-pip \ python3-sphinx \ python3-virtualenv \ + python3.6 \ rdma-core-devel \ SDL2-devel \ snappy-devel \
Signature · 1 line
2.30.2
Re: [PATCH v6 24/25] gitlab: add python linters to CI
Quoted 49 lines · John Snow
Add python3.6 to the fedora container image: we need it to run the linters against that explicit version to make sure we don't break our minimum version promise.
Add pipenv so that we can fetch precise versions of pip packages we need to guarantee test reproducability.
Signed-off-by John Snow <[email protected]>--- .gitlab-ci.yml | 12 ++++++++++++ tests/docker/dockerfiles/fedora.docker | 2 ++ 2 files changed, 14 insertions(+).gitlab-ci.yml +12
-0@@ -779,6 +779,18 @@ check-patch: GIT_DEPTH: 1000 allow_failure: true + +check-python: + stage: test + image: $CI_REGISTRY_IMAGE/qemu/fedora:latest + script: + - cd python + - make venv-check + variables: + GIT_DEPTH: 1000 + needs: + job: amd64-fedora-container + check-dco: stage: build image: $CI_REGISTRY_IMAGE/qemu/centos8:latesttests/docker/dockerfiles/fedora.docker +1
-0@@ -84,6 +84,7 @@ ENV PACKAGES \ numactl-devel \ perl \ perl-Test-Harness \ + pipenv \ pixman-devel \ python3 \ python3-PyYAML \
tests/docker/dockerfiles/fedora.docker ENV PACKAGES \ · line 97
Quoted 4 lines
tests/docker/dockerfiles/fedora.docker +1
-0@@ -93,6 +94,7 @@ ENV PACKAGES \ python3-pip \ python3-sphinx \ python3-virtualenv \ + python3.6 \
I personally would prefer having a different container image for this job. Because it would:
1. Be super simple (FROM fedora:33 / dnf -y install python3.6 pipenv)
2. Not carry all this unnecessary baggage
3. Not risk building QEMU with Python 3.6 (suppose the ./configure probe changes unintentionally)
But, AFAICT there is no precedent in requiring new images for different types of checks. So, unless someone else complains loudly, I'm OK with this.
Re: [PATCH v6 24/25] gitlab: add python linters to CI
Quoted 63 lines · Cleber Rosa
Quoted 49 lines · John Snow
Add python3.6 to the fedora container image: we need it to run the linters against that explicit version to make sure we don't break our minimum version promise.
Add pipenv so that we can fetch precise versions of pip packages we need to guarantee test reproducability.
Signed-off-by John Snow <[email protected]>--- .gitlab-ci.yml | 12 ++++++++++++ tests/docker/dockerfiles/fedora.docker | 2 ++ 2 files changed, 14 insertions(+).gitlab-ci.yml +12
-0@@ -779,6 +779,18 @@ check-patch: GIT_DEPTH: 1000 allow_failure: true + +check-python: + stage: test + image: $CI_REGISTRY_IMAGE/qemu/fedora:latest + script: + - cd python + - make venv-check + variables: + GIT_DEPTH: 1000 + needs: + job: amd64-fedora-container + check-dco: stage: build image: $CI_REGISTRY_IMAGE/qemu/centos8:latesttests/docker/dockerfiles/fedora.docker +1
-0@@ -84,6 +84,7 @@ ENV PACKAGES \ numactl-devel \ perl \ perl-Test-Harness \ + pipenv \ pixman-devel \ python3 \ python3-PyYAML \tests/docker/dockerfiles/fedora.docker ENV PACKAGES \ · line 97
Quoted 4 lines
tests/docker/dockerfiles/fedora.docker +1
-0@@ -93,6 +94,7 @@ ENV PACKAGES \ python3-pip \ python3-sphinx \ python3-virtualenv \ + python3.6 \I personally would prefer having a different container image for this job. Because it would:
1. Be super simple (FROM fedora:33 / dnf -y install python3.6 pipenv)
2. Not carry all this unnecessary baggage
3. Not risk building QEMU with Python 3.6 (suppose the ./configure probe changes unintentionally)
Quoted 6 lines
But, AFAICT there is no precedent in requiring new images for different types of checks. So, unless someone else complains loudly, I'm OK with this.
Reviewed-by Cleber Rosa <[email protected]>
Hm....
I'll try. You're right that it would make the pipeline a lot simpler because it'd have less cruft.
but thank you for the R-B in the meantime ;)
--js
PATCH v6 25/25 python: add tox support
In reply to John SnowThis is intended to be a manually run, non-CI script.
Use tox to test the linters against all python versions from 3.6 to 3.9. This will only work if you actually have those versions installed locally, but Fedora makes this easy:
Quoted 1 line
sudo dnf install python36 python37 python38 python39
Unlike the pipenv tests (make venv-check), this pulls "whichever" versions of the python packages, so they are unpinned and may break as time goes on. In the case that breakages are found, setup.cfg should be amended accordingly to avoid the bad dependant versions, or the code should be amended to work around the issue.
--- python/README.rst | 2 ++ python/.gitignore | 1 + python/Makefile | 7 ++++++- python/setup.cfg | 1 + python/tox.ini | 13 +++++++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 python/tox.ini
python/README.rst +2 -0
@@ -49,3 +49,5 @@ Files in this directory this package; it is referenced by ``setup.cfg``. - ``setup.cfg`` houses setuptools package configuration. - ``setup.py`` is the setuptools installer used by pip; See above. +- ``tox.ini`` houses configuration for tox, which runs tests against + several Python versions to test compatibility.
python/.gitignore +1 -0
@@ -17,3 +17,4 @@ qemu.egg-info/ # virtual environments (pipenv et al) .venv/ +.tox/
python/Makefile +6 -1
@@ -16,6 +16,8 @@ help: @echo "" @echo "make check: run linters using the current environment." @echo "" + @echo "make check-tox: run linters using multiple python versions." + @echo "" @echo "make clean: remove build output." @echo "" @echo "make distclean: remove venv files, qemu package forwarder, and"
@@ -35,8 +37,11 @@ develop: check: @avocado --config avocado.cfg run tests/ +check-tox: + @tox + clean: rm -rf build/ dist/ distclean: clean - rm -rf qemu.egg-info/ .venv/ + rm -rf qemu.egg-info/ .venv/ .tox/
python/setup.cfg +1 -0
@@ -33,6 +33,7 @@ devel = extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's exclude = __pycache__, .venv, + .tox, [mypy] strict = True
python/tox.ini new file +13 -0
@@ -0,0 +1,13 @@ +# tox (https://tox.readthedocs.io/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +envlist = py36, py37, py38, py39 + +[testenv] +allowlist_externals = make +deps = .[devel] +commands = + make check
Signature · 1 line
2.30.2
Re: [PATCH v6 25/25] python: add tox support
Quoted 15 lines · John Snow
This is intended to be a manually run, non-CI script.
Use tox to test the linters against all python versions from 3.6 to 3.9. This will only work if you actually have those versions installed locally, but Fedora makes this easy:
Quoted 1 line
sudo dnf install python36 python37 python38 python39
Unlike the pipenv tests (make venv-check), this pulls "whichever" versions of the python packages, so they are unpinned and may break as time goes on. In the case that breakages are found, setup.cfg should be amended accordingly to avoid the bad dependant versions, or the code should be amended to work around the issue.
Signed-off-by John Snow <[email protected]>
Quoted 9 lines
--- python/README.rst | 2 ++ python/.gitignore | 1 + python/Makefile | 7 ++++++- python/setup.cfg | 1 + python/tox.ini | 13 +++++++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 python/tox.ini
This works as intended for me. A couple of notes / suggestions for future improvements:
* dnf install tox pulled all the Python versions available (I assume as suggestions) automatically
* tox.ini can be folded into setup.cfg
* a custom container image with all those Python versions may be handy for running both the pipenv based job (along with the suggestions on the previous patch) and an on-demand, "allow_failure" tox based CI job.
Other than those suggestions, this LGTM!
Re: [PATCH v6 25/25] python: add tox support
Quoted 26 lines · Cleber Rosa
Quoted 15 lines · John Snow
This is intended to be a manually run, non-CI script.
Use tox to test the linters against all python versions from 3.6 to 3.9. This will only work if you actually have those versions installed locally, but Fedora makes this easy:
Quoted 1 line
sudo dnf install python36 python37 python38 python39
Unlike the pipenv tests (make venv-check), this pulls "whichever" versions of the python packages, so they are unpinned and may break as time goes on. In the case that breakages are found, setup.cfg should be amended accordingly to avoid the bad dependant versions, or the code should be amended to work around the issue.
Signed-off-by John Snow <[email protected]>Quoted 9 lines
--- python/README.rst | 2 ++ python/.gitignore | 1 + python/Makefile | 7 ++++++- python/setup.cfg | 1 + python/tox.ini | 13 +++++++++++++ 5 files changed, 23 insertions(+), 1 deletion(-)create mode 100644 python/tox.ini
Quoted 8 lines
This works as intended for me. A couple of notes / suggestions for future improvements:
*
dnf install toxpulled all the Python versions available (I assume as suggestions) automatically* tox.ini can be folded into setup.cfg
Done!
Quoted 5 lines
* a custom container image with all those Python versions may be handy for running both the pipenv based job (along with the suggestions on the previous patch) and an on-demand, "
allow_failure" tox based CI job.
Yeah, I was thinking this would be good, too!
I think at this point, it's going to be a follow-up, though. Because ideally, yes, this SHOULD pass -- it's just that it needs a fairly particular environment to run in, which is annoying, so it's here as an optional-ish thing for now.
Maybe I'll make a new fedora:latest container that's meant solely for testing python stuff, because it's just such a convenient distro for it.
Later, though.
Quoted 5 lines
Other than those suggestions, this LGTM!
Reviewed-by Cleber Rosa <[email protected]>Tested-by Cleber Rosa <[email protected]>
🎉
Re: [PATCH v6 25/25] python: add tox support
Quoted 30 lines · John Snow
Quoted 29 lines · Cleber Rosa
Quoted 15 lines · John Snow
This is intended to be a manually run, non-CI script.
Use tox to test the linters against all python versions from 3.6 to 3.9. This will only work if you actually have those versions installed locally, but Fedora makes this easy:
Quoted 1 line
sudo dnf install python36 python37 python38 python39
Unlike the pipenv tests (make venv-check), this pulls "whichever" versions of the python packages, so they are unpinned and may break as time goes on. In the case that breakages are found, setup.cfg should be amended accordingly to avoid the bad dependant versions, or the code should be amended to work around the issue.
Signed-off-by John Snow <[email protected]>Quoted 9 lines
--- python/README.rst | 2 ++ python/.gitignore | 1 + python/Makefile | 7 ++++++- python/setup.cfg | 1 + python/tox.ini | 13 +++++++++++++ 5 files changed, 23 insertions(+), 1 deletion(-)create mode 100644 python/tox.ini
This works as intended for me. A couple of notes / suggestions for future improvements:
Quoted 8 lines
Quoted 5 lines
*
dnf install toxpulled all the Python versions available (I assume as suggestions) automatically* tox.ini can be folded into setup.cfg
Done!
Nice!
Quoted 13 lines
Quoted 5 lines
* a custom container image with all those Python versions may be handy for running both the pipenv based job (along with the suggestions on the previous patch) and an on-demand, "
allow_failure" tox based CI job.Yeah, I was thinking this would be good, too!
I think at this point, it's going to be a follow-up, though. Because ideally, yes, this SHOULD pass -- it's just that it needs a fairly particular environment to run in, which is annoying, so it's here as an optional-ish thing for now.
Quoted 5 lines
Maybe I'll make a new fedora:latest container that's meant solely for testing python stuff, because it's just such a convenient distro for it.
Later, though.
Sure.
Quoted 7 lines
Quoted 5 lines
Other than those suggestions, this LGTM!
Reviewed-by Cleber Rosa <[email protected]>Tested-by Cleber Rosa <[email protected]>🎉
\o/ (with 3 characters, because I'm unable to find the right codepoint)
Re: [PATCH v6 25/25] python: add tox support
Quoted 65 lines · Cleber Rosa
Quoted 30 lines · John Snow
Quoted 29 lines · Cleber Rosa
Quoted 15 lines · John Snow
This is intended to be a manually run, non-CI script.
Use tox to test the linters against all python versions from 3.6 to 3.9. This will only work if you actually have those versions installed locally, but Fedora makes this easy:
Quoted 1 line
sudo dnf install python36 python37 python38 python39
Unlike the pipenv tests (make venv-check), this pulls "whichever" versions of the python packages, so they are unpinned and may break as time goes on. In the case that breakages are found, setup.cfg should be amended accordingly to avoid the bad dependant versions, or the code should be amended to work around the issue.
Signed-off-by John Snow <[email protected]>Quoted 9 lines
--- python/README.rst | 2 ++ python/.gitignore | 1 + python/Makefile | 7 ++++++- python/setup.cfg | 1 + python/tox.ini | 13 +++++++++++++ 5 files changed, 23 insertions(+), 1 deletion(-)create mode 100644 python/tox.ini
This works as intended for me. A couple of notes / suggestions for future improvements:
Quoted 8 lines
Quoted 5 lines
*
dnf install toxpulled all the Python versions available (I assume as suggestions) automatically* tox.ini can be folded into setup.cfg
Done!
Nice!
Quoted 13 lines
Quoted 5 lines
* a custom container image with all those Python versions may be handy for running both the pipenv based job (along with the suggestions on the previous patch) and an on-demand, "
allow_failure" tox based CI job.Yeah, I was thinking this would be good, too!
I think at this point, it's going to be a follow-up, though. Because ideally, yes, this SHOULD pass -- it's just that it needs a fairly particular environment to run in, which is annoying, so it's here as an optional-ish thing for now.
Quoted 5 lines
Maybe I'll make a new fedora:latest container that's meant solely for testing python stuff, because it's just such a convenient distro for it.
Later, though.
Sure.
Quoted 2 lines
Quoted 2 lines
Other than those suggestions, this LGTM!
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Reviewed-by Cleber Rosa <[email protected]>Tested-by Cleber Rosa <[email protected]>🎉
\o/ (with 3 characters, because I'm unable to find the right codepoint)
if you're on fedora using the ime-bus stuff, try ctrl+shift+e to enter EMOJI MODE and then type 'tada' and then hit 'space' to search.
🥳
Quoted 5 lines · John Snow
Based-on: <[email protected]>
CI: https://gitlab.com/jsnow/qemu/-/pipelines/302010131
GitLab: https://gitlab.com/jsnow/qemu/-/tree/python-package-mk3
MR: https://gitlab.com/jsnow/qemu/-/merge_requests/4
Patchset updated and rebased on top of new linting pre-req series. (Gitlab branch and MR rebased and updated.)
Based-on: <[email protected]>
Quoted 320 lines
I invite you to leave review comments on my mock merge request on gitlab, submitted against my own mirror. I will, as always, also respond to feedback on-list.
ABOUT
=====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 -- some import statements change in a few places.
RATIONALE
=========The primary motivation of this series is primarily to formalize our dependencies on mypy, flake8, isort, and pylint alongside versions that are known to work. It does this using the setup.cfg and
setup.pyfiles. It also adds explicitly pinned versions (using Pipfile.lock) of these dependencies that should behave in a repeatable and known way for developers and CI environments both. Lastly, it enables those CI checks such that we can enforce Python coding quality checks via the CI tests.An auxiliary motivation is that 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* and this series *will not* cause any such releases. We have time to debate finer points like API guarantees and versioning even after this series is merged.Other bits of interest
----------------------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 (and confounding other python analysis tools).
For example: when developing, you may go to qemu/python/ and run
make venvfollowed bypipenv shellto activate a virtual environment that contains the qemu python packages. These packages will always reflect the current version of the source files in the tree. When you are finished, you can simply exit the shell (^d) 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] ."
TESTING THIS SERIES
===================First of all, nothing should change. Without any intervention, everything should behave exactly as it did before. The only new information here comes from how to interact with and run the linters that will be enforcing code quality standards in this subdirectory.
There are various invocations available that will test subtly different combinations using subtly different environments. I am assuming some light knowledge of Python environments and installing Python packages here. If you have questions, I would be delighted to answer them.
To test the new tests, CD to ./python/ first, and then:
0. Try "make" or "make help" to get a sense of this series.
1. Try "make venv && 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 where the script is, or what your CWD is.
This will pull some packages from PyPI and install them into the virtual environment, leaving your normal environment untouched.
You will need Python 3.6 and pipenv installed on your system to do this step. For Fedora: "dnf install python36 pipenv" will do the trick. If you don't have this, skip down to #4 and onwards.
2. Try "make check" while still in the shell to run the Python linters using the venv built in the previous step. This will run avocado, which will in turn execute mypy, flake8, isort and pylint with the correct arguments.
3. Having exited the shell from above, try "make venv-check". This will create and update the venv if needed, then run 'make check' within the context of that shell. It should pass as long as the above did. You should be able to run "make distclean" prior to running "make venv-check" and have the entire process work start to finish.
4. Still outside of the venv, you may try running "make check". This will not install anything, but unless you have the right Python dependencies installed, these tests may fail for you. You might try using "pip install --user .[devel]" to install the development packages needed to run the tests successfully to your local user's python environment. Once done, you will probably want to "pip uninstall qemu" to remove the qemu packages to avoid them interfering with other things.
5. "make distclean" will delete the venv and any temporary files that may have been created by packaging, installing, testing, etc.
6. You may also (if you wish) create your own environment using a Python other than 3.6, bypassing pipenv. This may be useful for environments in which you simply do not have Python 3.6 readily available, or explicitly wish to test against a different version.
Using the Python of your choice:
-
> make distclean(Remove the .venv, if you created one.)
-> /usr/bin/python3.9 -m venv .venv
-> source .venv/bin/activate(or activate.[fish|csh])
-> make develop(Installs linter deps to this venv)
-> make check(Runs tests using current env)
-> deactivate(Leaves the venv)This *should* pass, and if it doesn't, it's a bug. Due to dependencies changing like shifting sands, it's impossible to promise support for every last combination of dependency and python version. This is why the "make venv-check" target uses Python 3 and a very explicit set of packages instead. Still, this form *should* pass.
7. If you are running Fedora or a distro that packages multiple Python versions, you can try running "make check-tox" to run the linters under all Python versions from Python 3.6 to 3.9. This will create a series of virtual environments under the .tox folder, leaving your existing environment unscathed. This should pass, provided you have the requisite Python versions on hand. When you are done, "make distclean" should remove any testing files.
CHANGELOG
=========V6
--``` 001/25:[----] [--] 'iotests/297: add --namespace-packages to mypy arguments' 002/25:[----] [-C] 'python: create qemu packages' 003/25:[----] [--] 'python: create utils sub-package' 004/25:[0005] [FC] 'python: add qemu package installer' 005/25:[0002] [FC] 'python: add VERSION file' 006/25:[----] [--] 'python: add directory structure README.rst files' 007/25:[down] 'python: add MANIFEST.in' 008/25:[0001] [FC] 'python: Add pipenv support' 009/25:[----] [--] 'python: add pylint import exceptions' 010/25:[----] [--] 'python: move pylintrc into setup.cfg' 011/25:[0083] [FC] 'python: add pylint to pipenv' 012/25:[----] [--] 'python: move flake8 config to setup.cfg' 013/25:[----] [--] 'python: add excluded dirs to flake8 config' 014/25:[0038] [FC] 'python: Add flake8 to pipenv' 015/25:[----] [--] 'python: move mypy.ini into setup.cfg' 016/25:[0050] [FC] 'python: add mypy to pipenv' 017/25:[----] [--] 'python: move .isort.cfg into setup.cfg' 018/25:[0006] [FC] 'python/qemu: add isort to pipenv' 019/25:[0004] [FC] 'python/qemu: add qemu package itself to pipenv' 020/25:[0014] [FC] 'python: add devel package requirements to setuptools' 021/25:[down] 'python: add avocado-framework and tests' 022/25:[0015] [FC] 'python: add Makefile for some common tasks' 023/25:[0018] [FC] 'python: add .gitignore' 024/25:[0004] [FC] 'gitlab: add python linters to CI' 025/25:[down] 'python: add tox support' ```- 04: Changed maintainer blurb in
PACKAGE.rst
- 05: VERSION is now 0.6.1a0
- 07: New, needed for both tox and using Pipenv to install the qemu package(s) in editable mode.
- 08: Add README entries explaining the purpose of the pipenv files.
- 11: pylint dependency was bumped to 2.7.0.
- 14: pipenv changes.
- 16: pipenv changes.
- 18: isort pinned at >= 5.1.2 now; see commit message.
- 19: pipenv changes.
- 20: Context differences from isort, pylint, and pipenv changes.
- 22:
- Add 'make develop'
- Add moreREADME.rstentries.
- Change pytest invocation to avocado.
- 23:
- Add comments to gitignore, split ignores out by function/category
- Ignore vscode files. (I like vscode now!)
- 24: Use the 'needs' feature of Gitlab CI and move the test to 'test' stageSTATUS
=======``` + [01] iotests-297-add-namespace # [RB] CR [SOB] JS + [02] python-create-qemu-packages # [SOB] JS + [03] python-create-utils-sub # [SOB] JS + [04] python-add-qemu-package # [SOB] JS + [05] python-add-version-file # [RB] CR [SOB] JS + [06] python-add-directory-structure # [SOB] JS + [07] python-add-manifest-in # [SOB] JS + [08] python-add-pipenv-support # [RB] CR [SOB] JS + [09] python-add-pylint-import # [RB] CR [SOB] JS + [10] python-move-pylintrc-into # [RB] CR [TB] CR [SOB] JS + [11] python-add-pylint-to-pipenv # [SOB] JS + [12] python-move-flake8-config-to # [RB] CR [SOB] JS + [13] python-add-excluded-dirs-to # [SOB] JS + [14] python-add-flake8-to-pipenv # [RB] CR [TB] CR [SOB] JS + [15] python-move-mypy-ini-into # [SOB] JS + [16] python-add-mypy-to-pipenv # [RB] CR [TB] CR [SOB] JS + [17] python-move-isort-cfg-into # [RB] CR [SOB] JS + [18] python-qemu-add-isort-to # [SOB] JS + [19] python-qemu-add-qemu-package # [RB] CR [TB] CR [SOB] JS + [20] python-add-devel-package # [SOB] JS + [21] python-add-avocado-framework # [SOB] JS + [22] python-add-makefile-for-some # [SOB] JS + [23] python-add-gitignore # [SOB] JS + [24] gitlab-add-python-linters-to # [SOB] JS > [25] python-add-tox-support # [SOB] JS ```John Snow (25):
iotests/297: add --namespace-packages to mypy arguments
python: create qemu packages
python: create utils sub-package
python: add qemu package installer
python: add VERSION file
python: add directory structureREADME.rstfiles
python: add MANIFEST.in
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 excluded dirs to flake8 config
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: add devel package requirements to setuptools
python: add avocado-framework and tests
python: addMakefilefor some common tasks
python: add .gitignore
gitlab: add python linters to CI
python: add tox supportpython/PACKAGE.rst | 33 +++ python/README.rst | 53 +++++ python/qemu/README.rst | 8 + python/qemu/machine/README.rst | 9 + python/qemu/qmp/README.rst | 9 + python/qemu/utils/README.rst | 7 + .gitlab-ci.yml | 12 + python/.gitignore | 20 ++ python/MANIFEST.in | 2 + python/Makefile | 47 ++++ python/Pipfile | 13 ++ python/Pipfile.lock | 231 ++++++++++++++++++++ python/VERSION | 1 + python/avocado.cfg | 10 + python/mypy.ini | 4 - python/qemu/.flake8 | 2 - python/qemu/.isort.cfg | 7 - python/qemu/__init__.py | 11 - python/qemu/machine/__init__.py | 36 +++ python/qemu/{ => machine}/console_socket.py | 0 python/qemu/{ => machine}/machine.py | 16 +- python/qemu/{ => machine}/qtest.py | 3 +- python/qemu/pylintrc | 58 ----- python/qemu/{qmp.py => qmp/__init__.py} | 12 +- python/qemu/utils/__init__.py | 23 ++ python/qemu/{ => utils}/accel.py | 0 python/setup.cfg | 79 +++++++ python/setup.py | 23 ++ python/tests/flake8.sh | 2 + python/tests/isort.sh | 2 + python/tests/mypy.sh | 2 + python/tests/pylint.sh | 2 + python/tox.ini | 13 ++ tests/acceptance/avocado_qemu/__init__.py | 4 +- tests/acceptance/virtio-gpu.py | 2 +- tests/docker/dockerfiles/fedora.docker | 2 + tests/qemu-iotests/297 | 1 + tests/qemu-iotests/300 | 4 +- tests/qemu-iotests/iotests.py | 2 +- tests/vm/aarch64vm.py | 2 +- tests/vm/basevm.py | 2 +- 41 files changed, 672 insertions(+), 97 deletions(-)create mode 100644
python/PACKAGE.rst
create mode 100644python/README.rst
create mode 100644python/qemu/README.rst
create mode 100644python/qemu/machine/README.rstcreate mode 100644python/qemu/qmp/README.rstcreate mode 100644python/qemu/utils/README.rstcreate mode 100644 python/.gitignore
create mode 100644 python/MANIFEST.in
create mode 100644 python/Makefile
create mode 100644 python/Pipfile
create mode 100644 python/Pipfile.lock
create mode 100644 python/VERSION
create mode 100644 python/avocado.cfg
delete mode 100644 python/mypy.ini
delete mode 100644 python/qemu/.flake8
delete mode 100644 python/qemu/.isort.cfg
delete mode 100644python/qemu/__init__.pycreate mode 100644python/qemu/machine/__init__.pyrename python/qemu/{ =>machine}/console_socket.py(100%) rename python/qemu/{ =>machine}/machine.py(98%) rename python/qemu/{ =>machine}/qtest.py(98%) delete mode 100644 python/qemu/pylintrc
renamepython/qemu/{qmp.py=>qmp/__init__.py} (96%) create mode 100644python/qemu/utils/__init__.pyrename python/qemu/{ =>utils}/accel.py(100%) create mode 100644 python/setup.cfg
create mode 100755python/setup.py
create mode 100755python/tests/flake8.sh
create mode 100755python/tests/isort.sh
create mode 100755python/tests/mypy.sh
create mode 100755python/tests/pylint.sh
create mode 100644 python/tox.ini