configure: create a python venv and ensure meson, sphinx
Subsystems (2)
v2 cover configure: create a python venv and ensure meson, sphinx
This patch series creates a mandatory python virtual environment ("venv") during configure time and uses it to ensure the availability of meson and sphinx.
See https://www.qemu.org/2023/03/24/python/ for motivations. The summary is that the goal of this series is to ensure that the python used to run meson is the same python used to run Sphinx, tests, and any build-time python scripting we have. As it stands, meson and sphinx (and their extensions) *may* run in a different python environment than the one configured and chosen by the user at configure/build time.
The effective change of this series is that QEMU will now unconditionally create a venv at configure-time and will ensure that meson (and sphinx, if docs are enabled) are available through that venv.
Some important points as a pre-emptive "FAQ":
- Works for Python 3.6 and up, on Fedora, OpenSuSE, Red Hat, CentOS, Alpine, Debian, Ubuntu, NetBSD, OpenBSD, and hopefully everywhere No new dependencies (...for most platforms. Debian and NetBSD get an asterisk, see patch 4).
- The venv is unconditionally created and lives at {build_dir}/pyvenv. The python interpreter used by this venv is always the one identified by configure. (Which in turn is always the one specified by --python or $PYTHON). --meson and --sphinx-build disappear.
- *almost* all python scripts in qemu.git executed as part of the build system, meson, sphinx, avocado tests, vm tests or CI are always executed within this venv. iotests are not yet integrated.
- Missing dependencies, when possible, are fetched and installed on-demand automatically to make developer environments "just work". However, it remains possible to build and test fully offline. Right now, online behavior is only triggered by --enable-docs, and even in that case...
- ... distribution packaged 'meson' and 'sphinx' are still utilized whenever possible as the highest preference.
- The bundled 'meson' takes the shape of a .whl file, replacing the git submodule. qemu-qmp will follow suit, while Sphinx will not be bundled just like it already isn't.
- about 13% of the mkvenv.py script is devoted to supporting Python 3.7 and Debian 10. ¯\_(ツ)_/¯
Tested with "make check-minreqs" after every patch and with GitLab at
https://gitlab.com/bonzini/qemu/-/pipelines/868627762.
Enjoy!
John and Paolo
v1->v2:
- integrate distlib for script generation and also to look up installed packages
- print a more precise error for --diagnose when running in an isolated venv
- reorganized code to avoid ensurepip, so that it is not spread across multiple patches
- made non-fatal errors a bit less scary
John Snow (23):
python: update pylint configuration
python: add mkvenv.py
mkvenv: add better error message for broken or missing ensurepip
mkvenv: add nested venv workaround
mkvenv: add ensure subcommand
mkvenv: add --diagnose option to explain "ensure" failures
mkvenv: add console script entry point generation
mkvenv: use pip's vendored distlib as a fallback
mkvenv: avoid ensurepip if pip is installed
mkvenv: work around broken pip installations on Debian 10 tests/docker: add python3-venv dependency
tests/vm: Configure netbsd to use Python 3.10
tests/vm: add py310-expat to NetBSD
python: add vendor.py utility
configure: create a python venv unconditionally python/wheels: add vendored meson package
configure: use 'mkvenv ensure meson' to bootstrap meson qemu.git: drop meson git submodule
tests: Use configure-provided pyvenv for tests
configure: move --enable-docs and --disable-docs back to configure
configure: bootstrap sphinx with mkvenv
configure: add --enable-pypi and --disable-pypi
configure: Add courtesy hint to Python version failure message
Paolo Bonzini (4):
python: shut up "pip install" during "make check-minreqs"
Python: Drop support for Python 3.6
mkvenv: mark command as required
python: bump some of the dependencies
.gitlab-ci.d/buildtest-template.yml | 4 +- .gitlab-ci.d/buildtest.yml | 6 +- .gitmodules | 3 - configure | 152 +-- docs/about/build-platforms.rst | 2 +- docs/conf.py | 9 - docs/devel/acpi-bits.rst | 6 +- docs/devel/testing.rst | 14 +- docs/meson.build | 2 +- meson | 1 - meson_options.txt | 2 - python/Makefile | 19 +- python/scripts/mkvenv.py | 897 ++++++++++++++++++ python/scripts/vendor.py | 74 ++ python/setup.cfg | 46 +- python/tests/flake8.sh | 1 + python/tests/isort.sh | 1 + python/tests/minreqs.txt | 19 +- python/tests/mypy.sh | 1 + python/tests/pylint.sh | 1 + python/wheels/meson-0.61.5-py3-none-any.whl | Bin 0 -> 862509 bytes .../org.centos/stream/8/x86_64/test-avocado | 4 +- scripts/device-crash-test | 2 +- scripts/meson-buildoptions.sh | 3 - scripts/qapi/mypy.ini | 2 +- tests/Makefile.include | 10 +- .../dockerfiles/debian-all-test-cross.docker | 3 +- .../dockerfiles/debian-hexagon-cross.docker | 3 +- .../dockerfiles/debian-riscv64-cross.docker | 3 +- .../dockerfiles/debian-tricore-cross.docker | 3 +- tests/requirements.txt | 7 +- tests/vm/netbsd | 2 + 32 files changed, 1167 insertions(+), 135 deletions(-) delete mode 160000 meson create mode 100644 python/scripts/mkvenv.py create mode 100755 python/scripts/vendor.py create mode 100644 python/wheels/meson-0.61.5-py3-none-any.whl
Signature · 26 lines
2.40.1 From 1b1489d2b8745f10b7b62beed1477019dfc0c4a6 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini <[email protected]> Date: Wed, 10 May 2023 23:54:09 -0400 Subject: [PATCH v2 01/27] python: shut up "pip install" during "make check-minreqs" Content-Type: text/plain; charset=UTF-8 "make check-minreqs" runs pip without the --disable-pip-version-check option, which causes the obnoxious "A new release of pip available" message. Recent versions of pip also complain that some of the dependencies in our virtual environment rely on "setup.py install" instead of providing a pyproject.toml file; apparently it is deprecated to install them directly from pip instead of letting the "wheel" package take care of them. So, install "wheel" in the virtual environment. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
python/Makefile +6 -3
@@ -54,6 +54,7 @@ pipenv check-pipenv: @echo "pipenv was dropped; try 'make check-minreqs' or 'make min-venv'" @exit 1 +PIP_INSTALL = pip install --disable-pip-version-check .PHONY: min-venv min-venv: $(QEMU_MINVENV_DIR) $(QEMU_MINVENV_DIR)/bin/activate $(QEMU_MINVENV_DIR) $(QEMU_MINVENV_DIR)/bin/activate: setup.cfg tests/minreqs.txt
@@ -62,10 +63,12 @@ $(QEMU_MINVENV_DIR) $(QEMU_MINVENV_DIR)/bin/activate: setup.cfg tests/minreqs.tx @( \ echo "ACTIVATE $(QEMU_MINVENV_DIR)"; \ . $(QEMU_MINVENV_DIR)/bin/activate; \ + echo "INSTALL wheel $(QEMU_MINVENV_DIR)"; \ + $(PIP_INSTALL) wheel 1>/dev/null; \ echo "INSTALL -r tests/minreqs.txt $(QEMU_MINVENV_DIR)";\ - pip install -r tests/minreqs.txt 1>/dev/null; \ + $(PIP_INSTALL) -r tests/minreqs.txt 1>/dev/null; \ echo "INSTALL -e qemu $(QEMU_MINVENV_DIR)"; \ - pip install -e . 1>/dev/null; \ + $(PIP_INSTALL) -e . 1>/dev/null; \ ) @touch $(QEMU_MINVENV_DIR)
@@ -100,7 +103,7 @@ check-dev: dev-venv .PHONY: develop develop: - pip3 install --disable-pip-version-check -e .[devel] + $(PIP_INSTALL) -e .[devel] .PHONY: check check:
Signature · 22 lines
2.40.1 From 478bcefa964170a2c694c71889a39709168ca36e Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:10 -0400 Subject: [PATCH v2 02/27] python: update pylint configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Pylint 2.17.x decided that SocketAddrT was a bad name for a Type Alias for some reason. Sure, fine, whatever. Signed-off-by: John Snow <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/setup.cfg | 1 + 1 file changed, 1 insertion(+)
python/setup.cfg +1 -0
@@ -132,6 +132,7 @@ good-names=i, fd, # fd = os.open(...) c, # for c in string: ... T, # for TypeVars. See pylint#3401 + SocketAddrT, # Not sure why this is invalid. [pylint.similarities] # Ignore imports when computing similarities.
Signature · 50 lines
2.40.1 From 6dbd67f6c346e1ead3413d5b781f1b48de5633a1 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:11 -0400 Subject: [PATCH v2 03/27] python: add mkvenv.py Content-Type: text/plain; charset=UTF-8 This script will be responsible for building a lightweight Python virtual environment at configure time. It works with Python 3.6 or newer. It has been designed to: - work *offline*, no PyPI required. - work *quickly*, The fast path is only ~65ms on my machine. - work *robustly*, with multiple fallbacks to keep things working. - work *cooperatively*, using system packages where possible. (You can use your distro's meson, no problem.) Due to its unique position in the build chain, it exists outside of the installable python packages in-tree and *must* be runnable without any third party dependencies. Under normal circumstances, the only dependency required to execute this script is Python 3.6+ itself. The script is *faster* by several seconds when setuptools and pip are installed in the host environment, which is probably the case for a typical multi-purpose developer workstation. In the event that pip/setuptools are missing or not usable, additional dependencies may be required on some distributions which remove certain Python stdlib modules to package them separately: - Debian may require python3-venv to provide "ensurepip" - NetBSD may require py310-expat to provide "pyexpat" * (* Or whichever version is current for NetBSD.) Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 247 +++++++++++++++++++++++++++++++++++++++ python/setup.cfg | 9 ++ python/tests/flake8.sh | 1 + python/tests/isort.sh | 1 + python/tests/mypy.sh | 1 + python/tests/pylint.sh | 1 + 6 files changed, 260 insertions(+) create mode 100644 python/scripts/mkvenv.py
python/scripts/mkvenv.py new file +247 -0
247 lines not on this page · raw message
python/setup.cfg +9 -0
@@ -103,6 +103,15 @@ ignore_missing_imports = True [mypy-pygments] ignore_missing_imports = True +[mypy-importlib.metadata] +ignore_missing_imports = True + +[mypy-importlib_metadata] +ignore_missing_imports = True + +[mypy-pkg_resources] +ignore_missing_imports = 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
python/tests/flake8.sh +1 -0
@@ -1,2 +1,3 @@ #!/bin/sh -e python3 -m flake8 qemu/ +python3 -m flake8 scripts/
python/tests/isort.sh +1 -0
@@ -1,2 +1,3 @@ #!/bin/sh -e python3 -m isort -c qemu/ +python3 -m isort -c scripts/
python/tests/mypy.sh +1 -0
@@ -1,2 +1,3 @@ #!/bin/sh -e python3 -m mypy -p qemu +python3 -m mypy scripts/
python/tests/pylint.sh +1 -0
@@ -1,3 +1,4 @@ #!/bin/sh -e # See commit message for environment variable explainer. SETUPTOOLS_USE_DISTUTILS=stdlib python3 -m pylint qemu/ +SETUPTOOLS_USE_DISTUTILS=stdlib python3 -m pylint scripts/
Signature · 20 lines
2.40.1 From 87397421790dc745fc4933831704e9ee4a6c5231 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Tue, 16 May 2023 09:25:38 +0200 Subject: [PATCH v2 04/27] mkvenv: add better error message for broken or missing ensurepip Content-Type: text/plain; charset=UTF-8 Debian debundles ensurepip for python; NetBSD debundles pyexpat but ensurepip needs pyexpat. Try our best to offer a helpful error message instead of just failing catastrophically. Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
python/scripts/mkvenv.py +37 -0
@@ -34,6 +34,7 @@ # later. See the COPYING file in the top-level directory. import argparse +from importlib.util import find_spec import logging import os from pathlib import Path
@@ -76,6 +77,10 @@ class QemuEnvBuilder(venv.EnvBuilder): def __init__(self, *args: Any, **kwargs: Any) -> None: logger.debug("QemuEnvBuilder.__init__(...)") + + if kwargs["with_pip"]: + check_ensurepip() + super().__init__(*args, **kwargs) # Make the context available post-creation:
@@ -98,6 +103,38 @@ def get_value(self, field: str) -> str: return ret +def check_ensurepip() -> None: + """ + Check that we have ensurepip. + + Raise a fatal exception with a helpful hint if it isn't available. + """ + if not find_spec("ensurepip"): + msg = ( + "Python's ensurepip module is not found.\n" + "It's normally part of the Python standard library, " + "maybe your distribution packages it separately?\n" + "Either install ensurepip, or alleviate the need for it in the " + "first place by installing pip and setuptools for " + f"'{sys.executable}'.\n" + "(Hint: Debian puts ensurepip in its python3-venv package.)" + ) + raise Ouch(msg) + + # ensurepip uses pyexpat, which can also go missing on us: + if not find_spec("pyexpat"): + msg = ( + "Python's pyexpat module is not found.\n" + "It's normally part of the Python standard library, " + "maybe your distribution packages it separately?\n" + "Either install pyexpat, or alleviate the need for it in the " + "first place by installing pip and setuptools for " + f"'{sys.executable}'.\n\n" + "(Hint: NetBSD's pkgsrc debundles this to e.g. 'py310-expat'.)" + ) + raise Ouch(msg) + + def make_venv( # pylint: disable=too-many-arguments env_dir: Union[str, Path], system_site_packages: bool = False,
Signature · 32 lines
2.40.1 From a5abb83016bf4cc1557fc49e1b62b44fdf7ce9c7 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:13 -0400 Subject: [PATCH v2 05/27] mkvenv: add nested venv workaround Content-Type: text/plain; charset=UTF-8 Python virtual environments do not typically nest; they may inherit from the top-level system packages or not at all. For our purposes, it would be convenient to emulate "nested" virtual environments to allow callers of the configure script to install specific versions of python utilities in order to test build system features, utility version compatibility, etc. While it is possible to install packages into the system environment (say, by using the --user flag), it's nicer to install test packages into a totally isolated environment instead. As detailed in https://www.qemu.org/2023/03/24/python/, Emulate a nested venv environment by using .pth files installed into the site-packages folder that points to the parent environment when appropriate. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 91 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 5 deletions(-)
python/scripts/mkvenv.py +86 -5
136 lines not on this page · raw message
Signature · 46 lines
2.40.1 From f5c6d680b124f5168c72f60ff1b155a9d1c6e9e6 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:14 -0400 Subject: [PATCH v2 06/27] mkvenv: add ensure subcommand Content-Type: text/plain; charset=UTF-8 This command is to be used to add various packages (or ensure they're already present) into the configure-provided venv in a modular fashion. Examples: mkvenv ensure --online --dir "${source_dir}/python/wheels/" "meson>=0.61.5" mkvenv ensure --online "sphinx>=1.6.0" mkvenv ensure "qemu.qmp==0.0.2" It's designed to look for packages in three places, in order: (1) In system packages, if the version installed is already good enough. This way your distribution-provided meson, sphinx, etc are always used as first preference. (2) In a vendored packages directory. Here I am suggesting qemu.git/python/wheels/ as that directory. This is intended to serve as a replacement for vendoring the meson source for QEMU tarballs. It is also highly likely to be extremely useful for packaging the "qemu.qmp" package in source distributions for platforms that do not yet package qemu.qmp separately. (3) Online, via PyPI, ***only when "--online" is passed***. This is only ever used as a fallback if the first two sources do not have an appropriate package that meets the requirement. The ability to build QEMU and run tests *completely offline* is not impinged. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> [Use distlib to lookup distributions. - Paolo] Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 135 ++++++++++++++++++++++++++++++++++++++- python/setup.cfg | 10 +++ python/tests/minreqs.txt | 3 + 3 files changed, 145 insertions(+), 3 deletions(-)
python/scripts/mkvenv.py +132 -3
183 lines not on this page · raw message
python/setup.cfg +10 -0
@@ -36,6 +36,7 @@ packages = # Remember to update tests/minreqs.txt if changing anything below: devel = avocado-framework >= 90.0 + distlib >= 0.3.6 flake8 >= 3.6.0 fusepy >= 2.0.4 isort >= 5.1.2
@@ -112,6 +113,15 @@ ignore_missing_imports = True [mypy-pkg_resources] ignore_missing_imports = True +[mypy-distlib] +ignore_missing_imports = True + +[mypy-distlib.database] +ignore_missing_imports = True + +[mypy-distlib.version] +ignore_missing_imports = 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
python/tests/minreqs.txt +3 -0
@@ -16,6 +16,9 @@ urwid==2.1.2 urwid-readline==0.13 Pygments==2.9.0 +# Dependencies for mkvenv +distlib==0.3.6 + # Dependencies for FUSE support for qom-fuse fusepy==2.0.4
Signature · 26 lines
2.40.1 From 18131ff76b12b57e5d90034e46f248f179dd3946 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:15 -0400 Subject: [PATCH v2 07/27] mkvenv: add --diagnose option to explain "ensure" failures Content-Type: text/plain; charset=UTF-8 This is a routine that is designed to print some usable info for human beings back out to the terminal if/when "mkvenv ensure" fails to locate or install a package during configure time, such as meson or sphinx. Since we are requiring that "meson" and "sphinx" are installed to the same Python environment as QEMU is configured to build with, this can produce some surprising failures when things are mismatched. This method is here to try and ease that sting by offering some actionable diagnosis. Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 170 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 1 deletion(-)
python/scripts/mkvenv.py +169 -1
212 lines not on this page · raw message
Signature · 27 lines
2.40.1 From a45365fe78f61c7a7619600fdf69c8023d45df05 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Tue, 16 May 2023 12:08:11 +0200 Subject: [PATCH v2 08/27] mkvenv: add console script entry point generation Content-Type: text/plain; charset=UTF-8 When creating a virtual environment that inherits system packages, script entry points (like "meson", "sphinx-build", etc) are not re-generated with the correct shebang. When you are *inside* of the venv, this is not a problem, but if you are *outside* of it, you will not have a script that engages the virtual environment appropriately. Add a mechanism that generates new entry points for pre-existing packages so that we can use these scripts to run "meson", "sphinx-build", "pip", unambiguously inside the venv. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 114 +++++++++++++++++++++++++++++++++++++++ python/setup.cfg | 3 ++ 2 files changed, 117 insertions(+)
python/scripts/mkvenv.py +114 -0
144 lines not on this page · raw message
python/setup.cfg +3 -0
@@ -119,6 +119,9 @@ ignore_missing_imports = True [mypy-distlib.database] ignore_missing_imports = True +[mypy-distlib.scripts] +ignore_missing_imports = True + [mypy-distlib.version] ignore_missing_imports = True
Signature · 23 lines
2.40.1 From 8ca0f325d8f4e10f047ba6822830aa8217989e25 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Tue, 16 May 2023 09:05:51 +0200 Subject: [PATCH v2 09/27] mkvenv: use pip's vendored distlib as a fallback Content-Type: text/plain; charset=UTF-8 distlib is usually not installed on Linux distribution, but it is vendored into pip. Because the virtual environment has pip via ensurepip, we can piggy-back on pip's vendored version. This could break if they move our cheese in the future, but the fix would be simply to require distlib. If it is debundled, as it is on msys, it is simply available directly. Signed-off-by: John Snow <[email protected]> [Move to toplevel. - Paolo] Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 25 ++++++++++++++++++++++--- python/setup.cfg | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-)
python/scripts/mkvenv.py +22 -3
@@ -69,10 +69,25 @@ import venv import warnings -import distlib.database -import distlib.scripts -import distlib.version +# Try to load distlib, with a fallback to pip's vendored version. +# HAVE_DISTLIB is checked below, just-in-time, so that mkvenv does not fail +# outside the venv or before a potential call to ensurepip in checkpip(). +HAVE_DISTLIB = True +try: + import distlib.database + import distlib.scripts + import distlib.version +except ImportError: + try: + # Reach into pip's cookie jar. pylint and flake8 don't understand + # that these imports will be used via distlib.xxx. + from pip._vendor import distlib + import pip._vendor.distlib.database # noqa, pylint: disable=unused-import + import pip._vendor.distlib.scripts # noqa, pylint: disable=unused-import + import pip._vendor.distlib.version # noqa, pylint: disable=unused-import + except ImportError: + HAVE_DISTLIB = False # Do not add any mandatory dependencies from outside the stdlib: # This script *must* be usable standalone!
@@ -664,6 +679,10 @@ def ensure( bellwether for the presence of 'sphinx'. """ print(f"mkvenv: checking for {', '.join(dep_specs)}", file=sys.stderr) + + if not HAVE_DISTLIB: + raise Ouch("a usable distlib could not be found, please install it") + try: _do_ensure(dep_specs, online, wheels_dir) except subprocess.CalledProcessError as exc:
python/setup.cfg +18 -0
@@ -125,6 +125,24 @@ ignore_missing_imports = True [mypy-distlib.version] ignore_missing_imports = True +[mypy-pip] +ignore_missing_imports = True + +[mypy-pip._vendor] +ignore_missing_imports = True + +[mypy-pip._vendor.distlib] +ignore_missing_imports = True + +[mypy-pip._vendor.distlib.database] +ignore_missing_imports = True + +[mypy-pip._vendor.distlib.scripts] +ignore_missing_imports = True + +[mypy-pip._vendor.distlib.version] +ignore_missing_imports = 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 · 13 lines
2.40.1 From 23eaa6d871e2501e3fd5131a33c5a3edcfb27e7c Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Tue, 16 May 2023 09:18:23 +0200 Subject: [PATCH v2 10/27] mkvenv: avoid ensurepip if pip is installed Content-Type: text/plain; charset=UTF-8 Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 67 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-)
python/scripts/mkvenv.py +64 -3
127 lines not on this page · raw message
Signature · 26 lines
2.40.1 From 9625872704c4087ad0b5a92885106b598a163607 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Tue, 16 May 2023 09:13:32 +0200 Subject: [PATCH v2 11/27] mkvenv: work around broken pip installations on Debian 10 Content-Type: text/plain; charset=UTF-8 This is a workaround intended for Debian 10, where the debian-patched pip does not function correctly if accessed from within a virtual environment. We don't support Debian 10 as a build platform any longer, though we do still utilize it for our build-tricore-softmmu CI test. It's also possible that this bug might appear on other derivative platforms and this workaround may prove useful. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 72 +++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 16 deletions(-)
python/scripts/mkvenv.py +56 -16
110 lines not on this page · raw message
Signature · 40 lines
2.40.1 From a2e2e7057b55de9b0425186f341e3ae97fcdd5c7 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:19 -0400 Subject: [PATCH v2 12/27] tests/docker: add python3-venv dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Several debian-based tests need the python3-venv dependency as a consequence of Debian debundling the "ensurepip" module normally included with Python. As mkvenv.py stands as of this commit, Debian requires EITHER: (A) setuptools and pip, or (B) ensurepip mkvenv is a few seconds faster if you have setuptools and pip, so developers should prefer the first requirement. For the purposes of CI, the time-save is a wash; it's only a matter of who is responsible for installing pip and when; the timing is about the same. Arbitrarily, I chose adding ensurepip to the test configuration because it is normally part of the Python stdlib, and always having it allows us a more consistent cross-platform environment. Signed-off-by: John Snow <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- tests/docker/dockerfiles/debian-all-test-cross.docker | 3 ++- tests/docker/dockerfiles/debian-hexagon-cross.docker | 3 ++- tests/docker/dockerfiles/debian-riscv64-cross.docker | 3 ++- tests/docker/dockerfiles/debian-tricore-cross.docker | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-)
tests/docker/dockerfiles/debian-all-test-cross.docker +2 -1
@@ -57,7 +57,8 @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata \ gcc-sh4-linux-gnu \ libc6-dev-sh4-cross \ gcc-sparc64-linux-gnu \ - libc6-dev-sparc64-cross + libc6-dev-sparc64-cross \ + python3-venv ENV QEMU_CONFIGURE_OPTS --disable-system --disable-docs --disable-tools ENV DEF_TARGET_LIST aarch64-linux-user,alpha-linux-user,arm-linux-user,hppa-linux-user,i386-linux-user,m68k-linux-user,mips-linux-user,mips64-linux-user,mips64el-linux-user,mipsel-linux-user,ppc-linux-user,ppc64-linux-user,ppc64le-linux-user,riscv64-linux-user,s390x-linux-user,sh4-linux-user,sparc64-linux-user
tests/docker/dockerfiles/debian-hexagon-cross.docker +2 -1
@@ -20,7 +20,8 @@ RUN apt-get update && \ bison \ flex \ git \ - ninja-build && \ + ninja-build \ + python3-venv && \ # Install QEMU build deps for use in CI DEBIAN_FRONTEND=noninteractive eatmydata \ apt build-dep -yy --arch-only qemu
tests/docker/dockerfiles/debian-riscv64-cross.docker +2 -1
@@ -28,7 +28,8 @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata apt install -yy \ libglib2.0-dev \ ninja-build \ pkg-config \ - python3 + python3 \ + python3-venv # Add ports and riscv64 architecture RUN echo "deb http://ftp.ports.debian.org/debian-ports/ sid main" >> /etc/apt/sources.list
tests/docker/dockerfiles/debian-tricore-cross.docker +2 -1
@@ -33,7 +33,8 @@ RUN apt update && \ pkgconf \ python3-pip \ python3-setuptools \ - python3-wheel + python3-wheel \ + python3-venv RUN curl -#SL https://github.com/bkoppelmann/package_940/releases/download/tricore-toolchain-9.40/tricore-toolchain-9.4.0.tar.gz \ | tar -xzC /usr/local/
Signature · 22 lines
2.40.1 From 235cc733f99a178cc3cfd11ee9516588a87bc54a Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:20 -0400 Subject: [PATCH v2 13/27] tests/vm: Configure netbsd to use Python 3.10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 NetBSD removes some packages from the Python stdlib, but only re-packages them for Python 3.10. Switch to using Python 3.10. Signed-off-by: John Snow <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- tests/vm/netbsd | 1 + 1 file changed, 1 insertion(+)
tests/vm/netbsd +1 -0
@@ -30,6 +30,7 @@ class NetBSDVM(basevm.BaseVM): "git-base", "pkgconf", "xz", + "python310", "ninja-build", # gnu tools
Signature · 28 lines
2.40.1 From ad24b9aa43270baf9b9a0c90bf5364cac7fe700b Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:21 -0400 Subject: [PATCH v2 14/27] tests/vm: add py310-expat to NetBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 NetBSD cannot successfully run "ensurepip" without access to the pyexpat module, which NetBSD debundles. Like the Debian patch, it would be strictly faster long term to install pip/setuptools, and I recommend developers at their workstations take that approach instead. For the purposes of a throwaway VM, there's not really a speed difference for who is responsible for installing pip; us (needs py310-pip) or Python (needs py310-expat). Signed-off-by: John Snow <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- tests/vm/netbsd | 1 + 1 file changed, 1 insertion(+)
tests/vm/netbsd +1 -0
@@ -31,6 +31,7 @@ class NetBSDVM(basevm.BaseVM): "pkgconf", "xz", "python310", + "py310-expat", "ninja-build", # gnu tools
Signature · 26 lines
2.40.1 From 085f10d46d162f68712e83bd1d1b587d791d6d22 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:22 -0400 Subject: [PATCH v2 15/27] python: add vendor.py utility Content-Type: text/plain; charset=UTF-8 This is a teeny-tiny script that just downloads any packages we want to vendor from PyPI and stores them in qemu.git/python/wheels/. If I'm hit by a meteor, it'll be easy to replicate what I have done in order to udpate the vendored source. We don't really care which python runs it; it exists as a meta-utility with no external dependencies and we won't package or install it. It will be monitored by the linters/type checkers, though; so it's guaranteed safe on python 3.6+. Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/vendor.py | 74 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 python/scripts/vendor.py
python/scripts/vendor.py new file +74 -0
74 lines not on this page · raw message
Signature · 22 lines
2.40.1 From a8cbd616a6fce429f06240c4cca51f005a89cf08 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:23 -0400 Subject: [PATCH v2 16/27] configure: create a python venv unconditionally Content-Type: text/plain; charset=UTF-8 This patch changes the configure script so that it always creates and uses a python virtual environment unconditionally. Meson bootstrapping is temporarily altered to force the use of meson from git or vendored source (as packaged in our source tarballs). A subsequent commit restores the use of distribution-vendored Meson. Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- configure | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)
configure +29 -5
@@ -625,7 +625,6 @@ check_py_version() { python= first_python= if test -z "${PYTHON}"; then - explicit_python=no # A bare 'python' is traditionally python 2.x, but some distros # have it as python 3.x, so check in both places. for binary in python3 python python3.11 python3.10 python3.9 python3.8 python3.7 python3.6; do
@@ -644,7 +643,6 @@ else # Same as above, but only check the environment variable. has "${PYTHON}" || error_exit "The PYTHON environment variable does not point to an executable" python=$(command -v "$PYTHON") - explicit_python=yes if check_py_version "$python"; then # This one is good. first_python=
@@ -729,7 +727,7 @@ for opt do ;; --install=*) ;; - --python=*) python="$optarg" ; explicit_python=yes + --python=*) python="$optarg" ;; --skip-meson) skip_meson=yes ;;
@@ -1090,8 +1088,34 @@ if ! check_py_version "$python"; then "Use --python=/path/to/python to specify a supported Python." fi -# Resolve PATH + suppress writing compiled files -python="$(command -v "$python") -B" +# Resolve PATH +python="$(command -v "$python")" +explicit_python=yes + +# Create a Python virtual environment using our configured python. +# The stdout of this script will be the location of a symlink that +# points to the configured Python. +# Entry point scripts for pip, meson, and sphinx are generated if those +# packages are present. + +# Defaults assumed for now: +# - venv is cleared if it exists already; +# - venv is allowed to use system packages; +# - all setup is performed **offline**; +# - No packages are installed by default; +# - pip is not installed into the venv when possible, +# but ensurepip is called as a fallback when necessary. + +echo "python determined to be '$python'" +echo "python version: $($python --version)" + +python="$($python -B "${source_path}/python/scripts/mkvenv.py" create pyvenv)" +if test "$?" -ne 0 ; then + error_exit "python venv creation failed" +fi + +# Suppress writing compiled files +python="$python -B" has_meson() { local python_dir=$(dirname "$python")
Signature · 41 lines
2.40.1 From 00dd89a7369d1256c642f77279d9a0c8b832c03e Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:24 -0400 Subject: [PATCH v2 17/27] python/wheels: add vendored meson package Content-Type: text/plain; charset=UTF-8 In preference to vendoring meson source, vendor a built distributable ("bdist" in python parlance). This has some benefits: (1) We can get rid of a git submodule, (2) Installing built meson into a venv doesn't require any extra dependencies (the python "wheel" package, chiefly.) (3) We don't treat meson any differently than we would any other python package (we install it, end of story, done.) (4) All future tarball *and* developer checkouts will function offline; No git or PyPI connection needed to fetch meson. Note that because mkvenv prefers vendored packages to PyPI, as mkvenv is currently written we will never consult PyPI for meson. (Do keep in mind that your distribution's meson will be preferred above the vendored version, though.) ``` jsnow@scv ~/s/q/python (python-configure-venv)> python3 scripts/vendor.py pip download --dest /home/jsnow/src/qemu/python/wheels --require-hashes -r /tmp/tmpvo5qav7i Collecting meson==0.61.5 Using cached meson-0.61.5-py3-none-any.whl (862 kB) Saved ./wheels/meson-0.61.5-py3-none-any.whl Successfully downloaded meson ``` Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/wheels/meson-0.61.5-py3-none-any.whl | Bin 0 -> 862509 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 python/wheels/meson-0.61.5-py3-none-any.whl
python/wheels/meson-0.61.5-py3-none-any.whl new file binary +0 -0
Signature · 44 lines
2.40.1 From d6545e8c506d3f36bbbabe7dc387c51280bd4a1a Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:25 -0400 Subject: [PATCH v2 18/27] configure: use 'mkvenv ensure meson' to bootstrap meson Content-Type: text/plain; charset=UTF-8 This commit changes how we detect and install meson. It notably removes '--meson='. Currently, configure creates a lightweight Python virtual environment unconditionally using the user's configured $python that inherits system packages. Temporarily, we forced the use of meson source present via git submodule or in the release tarball. With this patch, we restore the ability to use a system-provided meson: If Meson is installed in the build venv and meets our minimum version requirements, we will use that Meson. This includes a system provided meson, which would be visible via system-site packages inside the venv. In the event that Meson is installed but *not for the chosen Python interpreter*, not found, or of insufficient version, we will attempt to install Meson from vendored source into the newly created Python virtual environment. This vendored installation replaces both the git submodule and tarball source mechanisms for sourcing meson. As a result of this patch, the Python interpreter we use for both our own build scripts *and* Meson extensions are always known to be the exact same Python. As a further benefit, there will also be a symlink available in the build directory that points to the correct, configured python and can be used by e.g. manual tests to invoke the correct, configured Python unambiguously. Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- .gitlab-ci.d/buildtest-template.yml | 4 +- configure | 65 +++++------------------------ 2 files changed, 13 insertions(+), 56 deletions(-)
.gitlab-ci.d/buildtest-template.yml +2 -2
@@ -12,12 +12,12 @@ - mkdir build - cd build - ../configure --enable-werror --disable-docs --enable-fdt=system - ${LD_JOBS:+--meson=git} ${TARGETS:+--target-list="$TARGETS"} + ${TARGETS:+--target-list="$TARGETS"} $CONFIGURE_ARGS || { cat config.log meson-logs/meson-log.txt && exit 1; } - if test -n "$LD_JOBS"; then - ../meson/meson.py configure . -Dbackend_max_links="$LD_JOBS" ; + pyvenv/bin/meson configure . -Dbackend_max_links="$LD_JOBS" ; fi || exit 1; - make -j"$JOBS" - if test -n "$MAKE_CHECK_ARGS";
configure +11 -54
105 lines not on this page · raw message
Signature · 20 lines
2.40.1 From 2e57d7becbe783811535baf67464cf28d9e60db7 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:26 -0400 Subject: [PATCH v2 19/27] qemu.git: drop meson git submodule Content-Type: text/plain; charset=UTF-8 Now that meson is installed from a vendored wheel, we don't need the git submodule anymore. Drop it. Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- .gitmodules | 3 --- meson | 1 - 2 files changed, 4 deletions(-) delete mode 160000 meson
.gitmodules +0 -3
@@ -49,9 +49,6 @@ [submodule "roms/qboot"] path = roms/qboot url = https://gitlab.com/qemu-project/qboot.git -[submodule "meson"] - path = meson - url = https://gitlab.com/qemu-project/meson.git [submodule "roms/vbootrom"] path = roms/vbootrom url = https://gitlab.com/qemu-project/vbootrom.git
meson deleted +0 -1
@@ -1 +0,0 @@ -Subproject commit 3a9b285a55b91b53b2acda987192274352ecb5be
Signature · 26 lines
2.40.1 From 69cfd19aa4f549fb7f5e40a7685dac8eba7b4c8d Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:27 -0400 Subject: [PATCH v2 20/27] tests: Use configure-provided pyvenv for tests Content-Type: text/plain; charset=UTF-8 This patch changes how the avocado tests are provided, ever so slightly. Instead of creating a new testing venv, use the configure-provided 'pyvenv' instead, and install optional packages into that. Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- .gitlab-ci.d/buildtest.yml | 6 +++--- docs/devel/acpi-bits.rst | 6 +++--- docs/devel/testing.rst | 14 +++++++------- scripts/ci/org.centos/stream/8/x86_64/test-avocado | 4 ++-- scripts/device-crash-test | 2 +- tests/Makefile.include | 10 +++++----- tests/requirements.txt | 7 +++++-- 7 files changed, 26 insertions(+), 23 deletions(-)
.gitlab-ci.d/buildtest.yml +3 -3
@@ -103,7 +103,7 @@ crash-test-debian: script: - cd build - make NINJA=":" check-venv - - tests/venv/bin/python3 scripts/device-crash-test -q --tcg-only ./qemu-system-i386 + - pyvenv/bin/python3 scripts/device-crash-test -q --tcg-only ./qemu-system-i386 build-system-fedora: extends:
@@ -146,8 +146,8 @@ crash-test-fedora: script: - cd build - make NINJA=":" check-venv - - tests/venv/bin/python3 scripts/device-crash-test -q ./qemu-system-ppc - - tests/venv/bin/python3 scripts/device-crash-test -q ./qemu-system-riscv32 + - pyvenv/bin/python3 scripts/device-crash-test -q ./qemu-system-ppc + - pyvenv/bin/python3 scripts/device-crash-test -q ./qemu-system-riscv32 build-system-centos: extends:
docs/devel/acpi-bits.rst +3 -3
@@ -61,19 +61,19 @@ Under ``tests/avocado/`` as the root we have: :: $ make check-venv (needed only the first time to create the venv) - $ ./tests/venv/bin/avocado run -t acpi tests/avocado + $ ./pyvenv/bin/avocado run -t acpi tests/avocado The above will run all acpi avocado tests including this one. In order to run the individual tests, perform the following: :: - $ ./tests/venv/bin/avocado run tests/avocado/acpi-bits.py --tap - + $ ./pyvenv/bin/avocado run tests/avocado/acpi-bits.py --tap - The above will produce output in tap format. You can omit "--tap -" in the end and it will produce output like the following: :: - $ ./tests/venv/bin/avocado run tests/avocado/acpi-bits.py + $ ./pyvenv/bin/avocado run tests/avocado/acpi-bits.py Fetching asset from tests/avocado/acpi-bits.py:AcpiBitsTest.test_acpi_smbios_bits JOB ID : eab225724da7b64c012c65705dc2fa14ab1defef JOB LOG : /home/anisinha/avocado/job-results/job-2022-10-10T17.58-eab2257/job.log
docs/devel/testing.rst +7 -7
@@ -882,9 +882,9 @@ You can run the avocado tests simply by executing: make check-avocado -This involves the automatic creation of Python virtual environment -within the build tree (at ``tests/venv``) which will have all the -right dependencies, and will save tests results also within the +This involves the automatic installation, from PyPI, of all the +necessary avocado-framework dependencies into the QEMU venv within the +build tree (at ``./pyvenv``). Test results are also saved within the build tree (at ``tests/results``). Note: the build environment must be using a Python 3 stack, and have
@@ -941,7 +941,7 @@ may be invoked by running: .. code:: - tests/venv/bin/avocado run $OPTION1 $OPTION2 tests/avocado/ + pyvenv/bin/avocado run $OPTION1 $OPTION2 tests/avocado/ Note that if ``make check-avocado`` was not executed before, it is possible to create the Python virtual environment with the dependencies
@@ -956,20 +956,20 @@ a test file. To run tests from a single file within the build tree, use: .. code:: - tests/venv/bin/avocado run tests/avocado/$TESTFILE + pyvenv/bin/avocado run tests/avocado/$TESTFILE To run a single test within a test file, use: .. code:: - tests/venv/bin/avocado run tests/avocado/$TESTFILE:$TESTCLASS.$TESTNAME + pyvenv/bin/avocado run tests/avocado/$TESTFILE:$TESTCLASS.$TESTNAME Valid test names are visible in the output from any previous execution of Avocado or ``make check-avocado``, and can also be queried using: .. code:: - tests/venv/bin/avocado list tests/avocado + pyvenv/bin/avocado list tests/avocado Manual Installation ~~~~~~~~~~~~~~~~~~~
scripts/ci/org.centos/stream/8/x86_64/test-avocado +2 -2
@@ -4,7 +4,7 @@ # KVM and x86_64, or tests that are generic enough to be valid for all # targets. Such a test list can be generated with: # -# ./tests/venv/bin/avocado list --filter-by-tags-include-empty \ +# ./pyvenv/bin/avocado list --filter-by-tags-include-empty \ # --filter-by-tags-include-empty-key -t accel:kvm,arch:x86_64 \ # tests/avocado/ #
@@ -22,7 +22,7 @@ # - tests/avocado/virtio_check_params.py:VirtioMaxSegSettingsCheck.test_machine_types # make get-vm-images -./tests/venv/bin/avocado run \ +./pyvenv/bin/avocado run \ --job-results-dir=tests/results/ \ tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_i440fx_kvm \ tests/avocado/boot_linux.py:BootLinuxX8664.test_pc_q35_kvm \
scripts/device-crash-test +1 -1
@@ -43,7 +43,7 @@ except ModuleNotFoundError as exc: print(f"Module '{exc.name}' not found.") print(" Try 'make check-venv' from your build directory,") print(" and then one way to run this script is like so:") - print(f' > $builddir/tests/venv/bin/python3 "{path}"') + print(f' > $builddir/pyvenv/bin/python3 "{path}"') sys.exit(1) logger = logging.getLogger('device-crash-test')
tests/Makefile.include +5 -5
@@ -89,7 +89,8 @@ distclean-tcg: $(DISTCLEAN_TCG_TARGET_RULES) # Build up our target list from the filtered list of ninja targets TARGETS=$(patsubst libqemu-%.fa, %, $(filter libqemu-%.fa, $(ninja-targets))) -TESTS_VENV_DIR=$(BUILD_DIR)/tests/venv +TESTS_VENV_DIR=$(BUILD_DIR)/pyvenv +TESTS_VENV_TOKEN=$(BUILD_DIR)/pyvenv/tests.group TESTS_VENV_REQ=$(SRC_PATH)/tests/requirements.txt TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/results TESTS_PYTHON=$(TESTS_VENV_DIR)/bin/python3
@@ -111,8 +112,7 @@ quiet-venv-pip = $(quiet-@)$(call quiet-command-run, \ $(TESTS_PYTHON) -m pip -q --disable-pip-version-check $1, \ "VENVPIP","$1") -$(TESTS_VENV_DIR): $(TESTS_VENV_REQ) - $(call quiet-command, $(PYTHON) -m venv $@, VENV, $@) +$(TESTS_VENV_TOKEN): $(TESTS_VENV_REQ) $(call quiet-venv-pip,install -e "$(SRC_PATH)/python/") $(call quiet-venv-pip,install -r $(TESTS_VENV_REQ)) $(call quiet-command, touch $@)
@@ -121,7 +121,7 @@ $(TESTS_RESULTS_DIR): $(call quiet-command, mkdir -p $@, \ MKDIR, $@) -check-venv: $(TESTS_VENV_DIR) +check-venv: $(TESTS_VENV_TOKEN) FEDORA_31_ARCHES_TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGETS))) FEDORA_31_ARCHES_CANDIDATES=$(patsubst ppc64,ppc64le,$(FEDORA_31_ARCHES_TARGETS))
@@ -167,7 +167,7 @@ check: check-build: run-ninja check-clean: - rm -rf $(TESTS_VENV_DIR) $(TESTS_RESULTS_DIR) + rm -rf $(TESTS_RESULTS_DIR) clean: check-clean clean-tcg distclean: distclean-tcg
tests/requirements.txt +5 -2
@@ -1,6 +1,9 @@ # Add Python module requirements, one per line, to be installed -# in the tests/venv Python virtual environment. For more info, +# in the qemu build_dir/pyvenv Python virtual environment. For more info, # refer to: https://pip.pypa.io/en/stable/user_guide/#id1 -# Note that qemu.git/python/ is always implicitly installed. +# +# Note that qemu.git/python/ is implicitly installed to this venv when +# 'make check-venv' is run, and will persist until configure is run +# again. avocado-framework==101.0 pycdlib==1.11.0
Signature · 20 lines
2.40.1 From b9dc31023c11cdf211276652dd6dba663097d90e Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:28 -0400 Subject: [PATCH v2 21/27] configure: move --enable-docs and --disable-docs back to configure Content-Type: text/plain; charset=UTF-8 Move this option back from meson into configure for the purposes of using the configuration value to bootstrap Sphinx in different ways based on this value. Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- configure | 6 ++++++ 1 file changed, 6 insertions(+)
configure +6 -0
@@ -279,6 +279,7 @@ debug_tcg="no" sanitizers="no" tsan="no" fortify_source="yes" +docs="auto" EXESUF="" modules="no" prefix="/usr/local"
@@ -750,6 +751,10 @@ for opt do ;; --disable-debug-info) meson_option_add -Ddebug=false ;; + --enable-docs) docs=enabled + ;; + --disable-docs) docs=disabled + ;; --enable-modules) modules="yes" ;;
@@ -2615,6 +2620,7 @@ if test "$skip_meson" = no; then # QEMU options test "$cfi" != false && meson_option_add "-Dcfi=$cfi" + test "$docs" != auto && meson_option_add "-Ddocs=$docs" test "$fdt" != auto && meson_option_add "-Dfdt=$fdt" test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE" test "$qemu_suffix" != qemu && meson_option_add "-Dqemu_suffix=$qemu_suffix"
Signature · 25 lines
2.40.1 From 4bff86fe38c1ecf89bcdc0f4ad2e3f921bca8497 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:29 -0400 Subject: [PATCH v2 22/27] configure: bootstrap sphinx with mkvenv Content-Type: text/plain; charset=UTF-8 When docs are explicitly requested, require Sphinx>=1.6.0. When docs are explicitly disabled, don't bother to check for Sphinx at all. If docs are set to "auto", attempt to locate Sphinx, but continue onward if it wasn't located. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- configure | 21 +++++++++++++++++++-- docs/conf.py | 9 --------- docs/meson.build | 2 +- meson_options.txt | 2 -- scripts/meson-buildoptions.sh | 3 --- 5 files changed, 20 insertions(+), 17 deletions(-)
configure +19 -2
@@ -1115,9 +1115,9 @@ fi # Suppress writing compiled files python="$python -B" +mkvenv="$python ${source_path}/python/scripts/mkvenv.py" - -if ! $python "${source_path}/python/scripts/mkvenv.py" ensure \ +if ! $mkvenv ensure \ --dir "${source_path}/python/wheels" \ --diagnose "meson" \ "meson>=0.61.5" ;
@@ -1132,6 +1132,23 @@ fi meson="$(cd pyvenv/bin; pwd)/meson" +# Conditionally ensure Sphinx is installed. + +if test "$docs" != "disabled" ; then + if ! $mkvenv ensure \ + --diagnose "sphinx-build" \ + "sphinx>=1.6.0" sphinx_rtd_theme; + then + if test "$docs" = "enabled" ; then + exit 1 + fi + echo "Sphinx not found/usable, disabling docs." + docs=disabled + else + docs=enabled + fi +fi + # Probe for ninja if test -z "$ninja"; then
docs/conf.py +0 -9
@@ -32,15 +32,6 @@ from distutils.version import LooseVersion from sphinx.errors import ConfigError -# Make Sphinx fail cleanly if using an old Python, rather than obscurely -# failing because some code in one of our extensions doesn't work there. -# In newer versions of Sphinx this will display nicely; in older versions -# Sphinx will also produce a Python backtrace but at least the information -# gets printed... -if sys.version_info < (3,6): - raise ConfigError( - "QEMU requires a Sphinx that uses Python 3.6 or better\n") - # The per-manual conf.py will set qemu_docdir for a single-manual build; # otherwise set it here if this is an entire-manual-set build. # This is always the absolute path of the docs/ directory in the source tree.
docs/meson.build +1 -1
@@ -1,4 +1,4 @@ -sphinx_build = find_program(get_option('sphinx_build'), +sphinx_build = find_program(fs.parent(python.full_path()) / 'sphinx-build', required: get_option('docs')) # Check if tools are available to build documentation.
meson_options.txt +0 -2
@@ -12,8 +12,6 @@ option('pkgversion', type : 'string', value : '', description: 'use specified string as sub-version of the package') option('smbd', type : 'string', value : '', description: 'Path to smbd for slirp networking') -option('sphinx_build', type : 'string', value : 'sphinx-build', - description: 'Use specified sphinx-build for building document') option('iasl', type : 'string', value : '', description: 'Path to ACPI disassembler') option('tls_priority', type : 'string', value : 'NORMAL',
scripts/meson-buildoptions.sh +0 -3
@@ -57,8 +57,6 @@ meson_options_help() { printf "%s\n" ' --localedir=VALUE Locale data directory [share/locale]' printf "%s\n" ' --localstatedir=VALUE Localstate data directory [/var/local]' printf "%s\n" ' --mandir=VALUE Manual page directory [share/man]' - printf "%s\n" ' --sphinx-build=VALUE Use specified sphinx-build for building document' - printf "%s\n" ' [sphinx-build]' printf "%s\n" ' --sysconfdir=VALUE Sysconf data directory [etc]' printf "%s\n" ' --tls-priority=VALUE Default TLS protocol/cipher priority string' printf "%s\n" ' [NORMAL]'
@@ -425,7 +423,6 @@ _meson_option_parse() { --disable-sndio) printf "%s" -Dsndio=disabled ;; --enable-sparse) printf "%s" -Dsparse=enabled ;; --disable-sparse) printf "%s" -Dsparse=disabled ;; - --sphinx-build=*) quote_sh "-Dsphinx_build=$2" ;; --enable-spice) printf "%s" -Dspice=enabled ;; --disable-spice) printf "%s" -Dspice=disabled ;; --enable-spice-protocol) printf "%s" -Dspice_protocol=enabled ;;
Signature · 38 lines
2.40.1 From bf8179d43b42d001d7f5d9237128a2b3ea8da1b4 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:30 -0400 Subject: [PATCH v2 23/27] configure: add --enable-pypi and --disable-pypi Content-Type: text/plain; charset=UTF-8 In the event that there's no vendored source present and no sufficient version of $package can be found, we will attempt to connect to PyPI to install the package if '--disable-pypi' was not passed. This means that PyPI access is "enabled by default", but there are some subtleties that make this action occur much less frequently than you might imagine: (1) While --enable-pypi is the default, vendored source will always be preferred when found, making PyPI a fallback. This should ensure that configure-time venv building "just works" for almost everyone in almost every circumstance. (2) Because meson source is, at time of writing, vendored directly into qemu.git, PyPI will never be used for sourcing meson. (3) Because Sphinx is an optional dependency, if docs are set to "auto", PyPI will not be used to obtain Sphinx source as a fallback and instead docs will be disabled. If PyPI sourcing of sphinx is desired, --enable-docs should be passed to force the lookup. I chose this as the default behavior to avoid adding new internet lookups to a "default" invocation of configure. Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- configure | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
configure +20 -1
@@ -623,6 +623,7 @@ check_py_version() { } python= +pypi="enabled" first_python= if test -z "${PYTHON}"; then # A bare 'python' is traditionally python 2.x, but some distros
@@ -888,6 +889,10 @@ for opt do --with-git-submodules=*) git_submodules_action="$optarg" ;; + --disable-pypi) pypi="disabled" + ;; + --enable-pypi) pypi="enabled" + ;; --enable-plugins) if test "$mingw32" = "yes"; then error_exit "TCG plugins not currently supported on Windows platforms" else
@@ -1101,7 +1106,9 @@ python="$(command -v "$python")" # Defaults assumed for now: # - venv is cleared if it exists already; # - venv is allowed to use system packages; -# - all setup is performed **offline**; +# - all setup can be performed offline; +# - missing packages may be fetched from PyPI, +# unless --disable-pypi is passed. # - pip is not installed into the venv when possible, # but ensurepip is called as a fallback when necessary.
@@ -1117,7 +1124,13 @@ fi python="$python -B" mkvenv="$python ${source_path}/python/scripts/mkvenv.py" +mkvenv_flags="" +if test "$pypi" = "enabled" ; then + mkvenv_flags="--online" +fi + if ! $mkvenv ensure \ + $mkvenv_flags \ --dir "${source_path}/python/wheels" \ --diagnose "meson" \ "meson>=0.61.5" ;
@@ -1134,8 +1147,14 @@ meson="$(cd pyvenv/bin; pwd)/meson" # Conditionally ensure Sphinx is installed. +mkvenv_flags="" +if test "$pypi" = "enabled" -a "$docs" = "enabled" ; then + mkvenv_flags="--online" +fi + if test "$docs" != "disabled" ; then if ! $mkvenv ensure \ + $mkvenv_flags \ --diagnose "sphinx-build" \ "sphinx>=1.6.0" sphinx_rtd_theme; then
Signature · 64 lines
2.40.1 From 2e29fc95fbbbf7a548081e1b1039ab8184620522 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini <[email protected]> Date: Wed, 10 May 2023 23:54:31 -0400 Subject: [PATCH v2 24/27] Python: Drop support for Python 3.6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Python 3.6 was EOL 2021-12-31. Newer versions of upstream libraries have begun dropping support for this version and it is becoming more cumbersome to support. Avocado-framework and qemu.qmp each have their own reasons for wanting to drop Python 3.6, but won't until QEMU does. Versions of Python available in our supported build platforms as of today, with optional versions available in parentheses: openSUSE Leap 15.4: 3.6.15 (3.9.10, 3.10.2) CentOS Stream 8: 3.6.8 (3.8.13, 3.9.16) CentOS Stream 9: 3.9.13 Fedora 36: 3.10 Fedora 37: 3.11 Debian 11: 3.9.2 Alpine 3.14, 3.15: 3.9.16 Alpine 3.16, 3.17: 3.10.10 Ubuntu 20.04 LTS: 3.8.10 Ubuntu 22.04 LTS: 3.10.4 NetBSD 9.3: 3.9.13* FreeBSD 12.4: 3.9.16 FreeBSD 13.1: 3.9.16 OpenBSD 7.2: 3.9.16 Note: Our VM tests install 3.9 explicitly for FreeBSD and 3.10 for NetBSD; the default for "python" or "python3" in FreeBSD is 3.9.16. NetBSD does not appear to have a default meta-package, but offers several options, the lowest of which is 3.7.15. "python39" appears to be a pre-requisite to one of the other packages we request in tests/vm/netbsd. pip, ensurepip and other Python essentials are currently only available for Python 3.10 for NetBSD. CentOS and OpenSUSE support parallel installation of multiple Python interpreters, and binaries in /usr/bin will always use Python 3.6. However, the newly introduced support for virtual environments ensures that all build steps that execute QEMU Python code use a single interpreter. Since it is safe to under our supported platform policy, bump our minimum supported version of Python to 3.7. Signed-off-by: John Snow <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- configure | 10 +++++----- docs/about/build-platforms.rst | 2 +- python/Makefile | 10 +++++----- python/setup.cfg | 7 +++---- python/tests/minreqs.txt | 2 +- scripts/qapi/mypy.ini | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-)
configure +5 -5
@@ -617,9 +617,9 @@ esac check_py_version() { - # We require python >= 3.6. + # We require python >= 3.7. # NB: a True python conditional creates a non-zero return code (Failure) - "$1" -c 'import sys; sys.exit(sys.version_info < (3,6))' + "$1" -c 'import sys; sys.exit(sys.version_info < (3,7))' } python=
@@ -628,7 +628,7 @@ first_python= if test -z "${PYTHON}"; then # A bare 'python' is traditionally python 2.x, but some distros # have it as python 3.x, so check in both places. - for binary in python3 python python3.11 python3.10 python3.9 python3.8 python3.7 python3.6; do + for binary in python3 python python3.11 python3.10 python3.9 python3.8 python3.7; do if has "$binary"; then python=$(command -v "$binary") if check_py_version "$python"; then
@@ -1077,7 +1077,7 @@ then # If first_python is set, there was a binary somewhere even though # it was not suitable. Use it for the error message. if test -n "$first_python"; then - error_exit "Cannot use '$first_python', Python >= 3.6 is required." \ + error_exit "Cannot use '$first_python', Python >= 3.7 is required." \ "Use --python=/path/to/python to specify a supported Python." else error_exit "Python not found. Use --python=/path/to/python"
@@ -1090,7 +1090,7 @@ then fi if ! check_py_version "$python"; then - error_exit "Cannot use '$python', Python >= 3.6 is required." \ + error_exit "Cannot use '$python', Python >= 3.7 is required." \ "Use --python=/path/to/python to specify a supported Python." fi
docs/about/build-platforms.rst +1 -1
@@ -98,7 +98,7 @@ Python runtime option of the ``configure`` script to point QEMU to a supported version of the Python runtime. - As of QEMU |version|, the minimum supported version of Python is 3.6. + As of QEMU |version|, the minimum supported version of Python is 3.7. Python build dependencies Some of QEMU's build dependencies are written in Python. Usually these
python/Makefile +5 -5
@@ -9,14 +9,14 @@ help: @echo "make check-minreqs:" @echo " Run tests in the minreqs virtual environment." @echo " These tests use the oldest dependencies." - @echo " Requires: Python 3.6" - @echo " Hint (Fedora): 'sudo dnf install python3.6'" + @echo " Requires: Python 3.7" + @echo " Hint (Fedora): 'sudo dnf install python3.7'" @echo "" @echo "make check-tox:" @echo " Run tests against multiple python versions." @echo " These tests use the newest dependencies." - @echo " Requires: Python 3.6 - 3.10, and tox." - @echo " Hint (Fedora): 'sudo dnf install python3-tox python3.10'" + @echo " Requires: Python 3.7 - 3.11, and tox." + @echo " Hint (Fedora): 'sudo dnf install python3-tox python3.11'" @echo " The variable QEMU_TOX_EXTRA_ARGS can be use to pass extra" @echo " arguments to tox". @echo ""
@@ -59,7 +59,7 @@ PIP_INSTALL = pip install --disable-pip-version-check min-venv: $(QEMU_MINVENV_DIR) $(QEMU_MINVENV_DIR)/bin/activate $(QEMU_MINVENV_DIR) $(QEMU_MINVENV_DIR)/bin/activate: setup.cfg tests/minreqs.txt @echo "VENV $(QEMU_MINVENV_DIR)" - @python3.6 -m venv $(QEMU_MINVENV_DIR) + @python3.7 -m venv $(QEMU_MINVENV_DIR) @( \ echo "ACTIVATE $(QEMU_MINVENV_DIR)"; \ . $(QEMU_MINVENV_DIR)/bin/activate; \
python/setup.cfg +3 -4
@@ -14,7 +14,6 @@ classifiers = Natural Language :: English Operating System :: OS Independent Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9
@@ -23,7 +22,7 @@ classifiers = Typing :: Typed [options] -python_requires = >= 3.6 +python_requires = >= 3.7 packages = qemu.qmp qemu.machine
@@ -77,7 +76,7 @@ exclude = __pycache__, [mypy] strict = True -python_version = 3.6 +python_version = 3.7 warn_unused_configs = True namespace_packages = True warn_unused_ignores = False
@@ -199,7 +198,7 @@ multi_line_output=3 # of python available on your system to run this test. [tox:tox] -envlist = py36, py37, py38, py39, py310, py311 +envlist = py37, py38, py39, py310, py311 skip_missing_interpreters = true [testenv]
python/tests/minreqs.txt +1 -1
@@ -1,5 +1,5 @@ # This file lists the ***oldest possible dependencies*** needed to run -# "make check" successfully under ***Python 3.6***. It is used primarily +# "make check" successfully under ***Python 3.7***. It is used primarily # by GitLab CI to ensure that our stated minimum versions in setup.cfg # are truthful and regularly validated. #
scripts/qapi/mypy.ini +1 -1
@@ -1,7 +1,7 @@ [mypy] strict = True disallow_untyped_calls = False -python_version = 3.6 +python_version = 3.7 [mypy-qapi.schema] disallow_untyped_defs = False
Signature · 29 lines
2.40.1 From 1354e64566d20e8541c9a40eecfff722560098f2 Mon Sep 17 00:00:00 2001 From: John Snow <[email protected]> Date: Wed, 10 May 2023 23:54:32 -0400 Subject: [PATCH v2 25/27] configure: Add courtesy hint to Python version failure message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 If we begin requiring Python 3.7+, a few platforms are going to need to install an additional Python interpreter package. As a courtesy to the user, suggest the optional package they might need to install. This will hopefully minimize any downtime caused by the change in Python dependency. Signed-off-by: John Snow <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- configure | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
configure +4 -1
@@ -1091,7 +1091,10 @@ fi if ! check_py_version "$python"; then error_exit "Cannot use '$python', Python >= 3.7 is required." \ - "Use --python=/path/to/python to specify a supported Python." + "Use --python=/path/to/python to specify a supported Python." \ + "Maybe try:" \ + " openSUSE Leap 15.3+: zypper install python39" \ + " CentOS 8: dnf install python38" fi # Resolve PATH
Signature · 18 lines
2.40.1 From cdc2a8e0b3e51c12d12dd7650bee09cb735a2f66 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini <[email protected]> Date: Wed, 10 May 2023 23:54:33 -0400 Subject: [PATCH v2 26/27] mkvenv: mark command as required Content-Type: text/plain; charset=UTF-8 This is only available in Python 3.7+. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/scripts/mkvenv.py | 1 + 1 file changed, 1 insertion(+)
python/scripts/mkvenv.py +1 -0
@@ -854,6 +854,7 @@ def main() -> int: subparsers = parser.add_subparsers( title="Commands", dest="command", + required=True, metavar="command", help="Description", )
Signature · 29 lines
2.40.1 From 3c003c79b14120806dc7d733108a3cc83953ac5b Mon Sep 17 00:00:00 2001 From: Paolo Bonzini <[email protected]> Date: Tue, 16 May 2023 11:59:36 +0200 Subject: [PATCH v2 27/27] python: bump some of the dependencies Content-Type: text/plain; charset=UTF-8 The version of pyflakes that is listed in python/tests/minreqs.txt breaks on Python 3.8 with the following message: AttributeError: 'FlakesChecker' object has no attribute 'CONSTANT' Now that we do not support EOL'd Python versions anymore, we can update to newer, fixed versions. It is a good time to do so, before Python packages start dropping support for Python 3.7 as well! The new mypy is also a bit smarter about which packages are actually being used, so remove the now-unnecessary sections from setup.cfg. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: John Snow <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> --- python/setup.cfg | 10 ++-------- python/tests/minreqs.txt | 14 +++++++------- 2 files changed, 9 insertions(+), 15 deletions(-)
python/setup.cfg +2 -8
@@ -36,11 +36,11 @@ packages = devel = avocado-framework >= 90.0 distlib >= 0.3.6 - flake8 >= 3.6.0 + flake8 >= 5.0.4 fusepy >= 2.0.4 isort >= 5.1.2 mypy >= 0.780 - pylint >= 2.8.0 + pylint >= 2.17.3 tox >= 3.18.0 urwid >= 2.1.2 urwid-readline >= 0.13
@@ -124,12 +124,6 @@ ignore_missing_imports = True [mypy-distlib.version] ignore_missing_imports = True -[mypy-pip] -ignore_missing_imports = True - -[mypy-pip._vendor] -ignore_missing_imports = True - [mypy-pip._vendor.distlib] ignore_missing_imports = True
python/tests/minreqs.txt +7 -7
@@ -26,23 +26,23 @@ fusepy==2.0.4 avocado-framework==90.0 # Linters -flake8==3.6.0 +flake8==5.0.4 isort==5.1.2 mypy==0.780 -pylint==2.8.0 +pylint==2.17.3 # Transitive flake8 dependencies -mccabe==0.6.0 -pycodestyle==2.4.0 -pyflakes==2.0.0 +mccabe==0.7.0 +pycodestyle==2.9.1 +pyflakes==2.5.0 # Transitive mypy dependencies mypy-extensions==0.4.3 typed-ast==1.4.0 -typing-extensions==3.7.4 +typing-extensions==4.5.0 # Transitive pylint dependencies -astroid==2.5.4 +astroid==2.15.4 lazy-object-proxy==1.4.0 toml==0.10.0 wrapt==1.12.1
Signature · 1 line
2.40.1
v2 cover configure: create a python venv and ensure meson, sphinx
This patch series creates a mandatory python virtual environment ("venv") during configure time and uses it to ensure the availability of meson and sphinx.
See https://www.qemu.org/2023/03/24/python/ for motivations. The summary is that the goal of this series is to ensure that the python used to run meson is the same python used to run Sphinx, tests, and any build-time python scripting we have. As it stands, meson and sphinx (and their extensions) *may* run in a different python environment than the one configured and chosen by the user at configure/build time.
The effective change of this series is that QEMU will now unconditionally create a venv at configure-time and will ensure that meson (and sphinx, if docs are enabled) are available through that venv.
Some important points as a pre-emptive "FAQ":
- Works for Python 3.6 and up, on Fedora, OpenSuSE, Red Hat, CentOS, Alpine, Debian, Ubuntu, NetBSD, OpenBSD, and hopefully everywhere No new dependencies (...for most platforms. Debian and NetBSD get an asterisk, see patch 4).
- The venv is unconditionally created and lives at {build_dir}/pyvenv. The python interpreter used by this venv is always the one identified by configure. (Which in turn is always the one specified by --python or $PYTHON). --meson and --sphinx-build disappear.
- *almost* all python scripts in qemu.git executed as part of the build system, meson, sphinx, avocado tests, vm tests or CI are always executed within this venv. iotests are not yet integrated.
- Missing dependencies, when possible, are fetched and installed on-demand automatically to make developer environments "just work". However, it remains possible to build and test fully offline. Right now, online behavior is only triggered by --enable-docs, and even in that case...
- ... distribution packaged 'meson' and 'sphinx' are still utilized whenever possible as the highest preference.
- The bundled 'meson' takes the shape of a .whl file, replacing the git submodule. qemu-qmp will follow suit, while Sphinx will not be bundled just like it already isn't.
- about 13% of the mkvenv.py script is devoted to supporting Python 3.7 and Debian 10. ¯\_(ツ)_/¯
Tested with "make check-minreqs" after every patch and with GitLab at
https://gitlab.com/bonzini/qemu/-/pipelines/868627762.
Enjoy!
John and Paolo
v1->v2:
- integrate distlib for script generation and also to look up installed packages
- print a more precise error for --diagnose when running in an isolated venv
- reorganized code to avoid ensurepip, so that it is not spread across multiple patches
- made non-fatal errors a bit less scary
John Snow (23):
python: update pylint configuration
python: add mkvenv.py
mkvenv: add better error message for broken or missing ensurepip
mkvenv: add nested venv workaround
mkvenv: add ensure subcommand
mkvenv: add --diagnose option to explain "ensure" failures
mkvenv: add console script entry point generation
mkvenv: use pip's vendored distlib as a fallback
mkvenv: avoid ensurepip if pip is installed
mkvenv: work around broken pip installations on Debian 10 tests/docker: add python3-venv dependency
tests/vm: Configure netbsd to use Python 3.10
tests/vm: add py310-expat to NetBSD
python: add vendor.py utility
configure: create a python venv unconditionally python/wheels: add vendored meson package
configure: use 'mkvenv ensure meson' to bootstrap meson qemu.git: drop meson git submodule
tests: Use configure-provided pyvenv for tests
configure: move --enable-docs and --disable-docs back to configure
configure: bootstrap sphinx with mkvenv
configure: add --enable-pypi and --disable-pypi
configure: Add courtesy hint to Python version failure message
Paolo Bonzini (4):
python: shut up "pip install" during "make check-minreqs"
Python: Drop support for Python 3.6
mkvenv: mark command as required
python: bump some of the dependencies
.gitlab-ci.d/buildtest-template.yml | 4 +- .gitlab-ci.d/buildtest.yml | 6 +- .gitmodules | 3 - configure | 152 +-- docs/about/build-platforms.rst | 2 +- docs/conf.py | 9 - docs/devel/acpi-bits.rst | 6 +- docs/devel/testing.rst | 14 +- docs/meson.build | 2 +- meson | 1 - meson_options.txt | 2 - python/Makefile | 19 +- python/scripts/mkvenv.py | 897 ++++++++++++++++++ python/scripts/vendor.py | 74 ++ python/setup.cfg | 46 +- python/tests/flake8.sh | 1 + python/tests/isort.sh | 1 + python/tests/minreqs.txt | 19 +- python/tests/mypy.sh | 1 + python/tests/pylint.sh | 1 + python/wheels/meson-0.61.5-py3-none-any.whl | Bin 0 -> 862509 bytes .../org.centos/stream/8/x86_64/test-avocado | 4 +- scripts/device-crash-test | 2 +- scripts/meson-buildoptions.sh | 3 - scripts/qapi/mypy.ini | 2 +- tests/Makefile.include | 10 +- .../dockerfiles/debian-all-test-cross.docker | 3 +- .../dockerfiles/debian-hexagon-cross.docker | 3 +- .../dockerfiles/debian-riscv64-cross.docker | 3 +- .../dockerfiles/debian-tricore-cross.docker | 3 +- tests/requirements.txt | 7 +- tests/vm/netbsd | 2 + 32 files changed, 1167 insertions(+), 135 deletions(-) delete mode 160000 meson create mode 100644 python/scripts/mkvenv.py create mode 100755 python/scripts/vendor.py create mode 100644 python/wheels/meson-0.61.5-py3-none-any.whl
Signature · 1 line
2.40.1
Quoted 41 lines · Paolo Bonzini
This patch series creates a mandatory python virtual environment ("venv") during configure time and uses it to ensure the availability of meson and sphinx.
See https://www.qemu.org/2023/03/24/python/ for motivations. The summary is that the goal of this series is to ensure that the
pythonused to run meson is the samepythonused to run Sphinx, tests, and any build-time python scripting we have. As it stands, meson and sphinx (and their extensions) *may* run in a different python environment than the one configured and chosen by the user at configure/build time.The effective change of this series is that QEMU will now unconditionally create a venv at configure-time and will ensure that meson (and sphinx, if docs are enabled) are available through that venv.
Some important points as a pre-emptive "FAQ":
- Works for Python 3.6 and up, on Fedora, OpenSuSE, Red Hat, CentOS, Alpine, Debian, Ubuntu, NetBSD, OpenBSD, and hopefully everywhere No new dependencies (...for most platforms. Debian and NetBSD get an asterisk, see patch 4).
- The venv is unconditionally created and lives at {build_dir}/pyvenv. The python interpreter used by this venv is always the one identified by configure. (Which in turn is always the one specified by --python or $PYTHON). --meson and --sphinx-build disappear.
- *almost* all python scripts in qemu.git executed as part of the build system, meson, sphinx, avocado tests, vm tests or CI are always executed within this venv. iotests are not yet integrated.
- Missing dependencies, when possible, are fetched and installed on-demand automatically to make developer environments "just work". However, it remains possible to build and test fully offline. Right now, online behavior is only triggered by --enable-docs, and even in that case...
- ... distribution packaged 'meson' and 'sphinx' are still utilized whenever possible as the highest preference.
Quoted 7 lines
- The bundled 'meson' takes the shape of a .whl file, replacing the git submodule. qemu-qmp will follow suit, while Sphinx will not be bundled just like it already isn't.
- about 13% of the
mkvenv.pyscript is devoted to supporting Python 3.7 and Debian 10. ¯\_(ツ)_/¯
I like that you measured this. It feels like more than 13%, but I'm going to trust this oddly specific number.
Quoted 2 lines
Tested with "make check-minreqs" after every patch and with GitLab at
https://gitlab.com/bonzini/qemu/-/pipelines/868627762.
For v1, I also tested with "make check-minreqs && make check-tox" and also started checking/formatting with black --line-length=79. I haven't added black into the linters yet because there's surely a ton of code that needs observed before I do that, but Dan suggested it and I liked it enough to start using it myself to take the ambiguity out of how to handle long lines.
(Not worth a respin if black isn't happy, I didn't check. Just mentioning it.)
Quoted 8 lines
Enjoy!
John and Paolo
v1->v2:
- integrate distlib for script generation and also to look up installed packages
Thanks :)
Quoted 5 lines
- print a more precise error for --diagnose when running in an isolated venv
- reorganized code to avoid ensurepip, so that it is not spread across multiple patches
- made non-fatal errors a bit less scary
"Oops" => "Oopsies!!"
Quoted 74 lines
John Snow (23):
python: update pylint configuration
python: addmkvenv.py
mkvenv: add better error message for broken or missing ensurepip
mkvenv: add nested venv workaround
mkvenv: add ensure subcommand
mkvenv: add --diagnose option to explain "ensure" failures
mkvenv: add console script entry point generation
mkvenv: use pip's vendored distlib as a fallback
mkvenv: avoid ensurepip if pip is installed
mkvenv: work around broken pip installations on Debian 10 tests/docker: add python3-venv dependency
tests/vm: Configure netbsd to use Python 3.10
tests/vm: add py310-expat to NetBSD
python: addvendor.pyutility
configure: create a python venv unconditionally python/wheels: add vendored meson package
configure: use 'mkvenv ensure meson' to bootstrap meson qemu.git: drop meson git submodule
tests: Use configure-provided pyvenv for tests
configure: move --enable-docs and --disable-docs back to configure
configure: bootstrap sphinx with mkvenv
configure: add --enable-pypi and --disable-pypi
configure: Add courtesy hint to Python version failure messagePaolo Bonzini (4):
python: shut up "pip install" during "make check-minreqs"
Python: Drop support for Python 3.6
mkvenv: mark command as required
python: bump some of the dependencies.gitlab-ci.d/buildtest-template.yml | 4 +- .gitlab-ci.d/buildtest.yml | 6 +- .gitmodules | 3 - configure | 152 +-- docs/about/build-platforms.rst | 2 +- docs/conf.py | 9 - docs/devel/acpi-bits.rst | 6 +- docs/devel/testing.rst | 14 +- docs/meson.build | 2 +- meson | 1 - meson_options.txt | 2 - python/Makefile | 19 +- python/scripts/mkvenv.py | 897 ++++++++++++++++++ python/scripts/vendor.py | 74 ++ python/setup.cfg | 46 +- python/tests/flake8.sh | 1 + python/tests/isort.sh | 1 + python/tests/minreqs.txt | 19 +- python/tests/mypy.sh | 1 + python/tests/pylint.sh | 1 + python/wheels/meson-0.61.5-py3-none-any.whl | Bin 0 -> 862509 bytes .../org.centos/stream/8/x86_64/test-avocado | 4 +- scripts/device-crash-test | 2 +- scripts/meson-buildoptions.sh | 3 - scripts/qapi/mypy.ini | 2 +- tests/Makefile.include | 10 +- .../dockerfiles/debian-all-test-cross.docker | 3 +- .../dockerfiles/debian-hexagon-cross.docker | 3 +- .../dockerfiles/debian-riscv64-cross.docker | 3 +- .../dockerfiles/debian-tricore-cross.docker | 3 +- tests/requirements.txt | 7 +- tests/vm/netbsd | 2 + 32 files changed, 1167 insertions(+), 135 deletions(-) delete mode 160000 meson create mode 100644 python/scripts/mkvenv.py create mode 100755 python/scripts/vendor.py create mode 100644 python/wheels/meson-0.61.5-py3-none-any.whl--
2.40.1