From e2409af88a26cbf49d6647296f9ac3161802c5ec Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Tue, 30 Apr 2024 07:28:26 +0200 Subject: [PATCH 1/3] testlib: fix Pillow type annotations Pillow upstream added a `py.typed` file in their last release, which is causing us problems because: - we `from PIL import Image`, which kinda looks like the class `Image` in the `PIL` module, but is actually a submodule. In particular, `PIL.Image.open()` is not a static method, but a function call, and it doesn't return `PIL.Image`, but rather `PIL.Image.Image`. Fix a couple of annotations. - our hacks for setting `Image = None` if the import is missing are no longer working (since the import now has a better type than `Any`). Let's make the import unconditional. `dnf install python3-pillow`. - several methods are unannotated in the upstream code, leading to warnings about "untyped call from typed code". We use an #ignore for those; cf. https://github.com/python-pillow/Pillow/issues/8029 --- pyproject.toml | 1 - test/common/testlib.py | 17 +++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1ad21a1d4f68..4a2951f65326 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,6 @@ module = [ "machine.*", "task.*", "testvm", - "PIL", # run with bots checked out but its dependencies missing "libvirt", diff --git a/test/common/testlib.py b/test/common/testlib.py index 6758b2641e53..4e6f9a525406 100644 --- a/test/common/testlib.py +++ b/test/common/testlib.py @@ -42,11 +42,7 @@ from lcov import write_lcov from lib.constants import OSTREE_IMAGES from machine import testvm - -try: - from PIL import Image -except ImportError: - Image = None +from PIL import Image _T = TypeVar('_T') _FT = TypeVar("_FT", bound=Callable[..., Any]) @@ -1203,12 +1199,13 @@ def ignorable_coord(x: int, y: int) -> bool: def ignorable_change(a: tuple[int, int, int], b: tuple[int, int, int]) -> bool: return abs(a[0] - b[0]) <= 2 and abs(a[1] - b[1]) <= 2 and abs(a[2] - b[2]) <= 2 - def img_eq(ref: Image, now: Image, delta: Image) -> bool: + def img_eq(ref: Image.Image, now: Image.Image, delta: Image.Image) -> bool: # This is slow but exactly what we want. # ImageMath might be able to speed this up. - data_ref = ref.load() - data_now = now.load() - data_delta = delta.load() + # no-untyped-call: see https://github.com/python-pillow/Pillow/issues/8029 + data_ref = ref.load() # type: ignore[no-untyped-call] + data_now = now.load() # type: ignore[no-untyped-call] + data_delta = delta.load() # type: ignore[no-untyped-call] result = True count = 0 width, height = delta.size @@ -1233,7 +1230,7 @@ def img_eq(ref: Image, now: Image, delta: Image) -> bool: # Preserve alpha channel so that the 'now' # image can be used as the new reference image # without further changes - img_now.putalpha(img_ref.getchannel("A")) + img_now.putalpha(img_ref.getchannel("A")) # type: ignore[no-untyped-call] img_now.save(filename) attach(filename, move=True) ref_filename_for_attach = base + "-reference.png" From c43485086104046cd37fb2d2ec886ae677a452bf Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Tue, 30 Apr 2024 12:36:56 +0200 Subject: [PATCH 2/3] workflows/unit-tests: disable seccomp for podman For some reason this starts causing trouble with `make distcheck` in Fedora 40. --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 1dedb97f817f..c2e17034aafe 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -21,7 +21,7 @@ jobs: set -eux IMAGE="$(curl --fail https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${GITHUB_SHA}/.cockpit-ci/container)" - podman run --network=host --rm --interactive "${IMAGE}" sh -eux < Date: Tue, 30 Apr 2024 07:33:27 +0200 Subject: [PATCH 3/3] cockpit-ci: Update container to 2024-04-25 This brings in a buggy definition in the version of the typeshed included in the new container image. Add an #ignore. See https://github.com/python/typeshed/pull/11548 Closes #20372 --- .cockpit-ci/container | 2 +- src/cockpit/transports.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.cockpit-ci/container b/.cockpit-ci/container index 218f87f52eb4..cfb1254caf80 100644 --- a/.cockpit-ci/container +++ b/.cockpit-ci/container @@ -1 +1 @@ -ghcr.io/cockpit-project/tasks:2024-04-08 +ghcr.io/cockpit-project/tasks:2024-04-25 diff --git a/src/cockpit/transports.py b/src/cockpit/transports.py index 8aabc7d83d6b..969819f60e09 100644 --- a/src/cockpit/transports.py +++ b/src/cockpit/transports.py @@ -402,7 +402,8 @@ def preexec_fn() -> None: super().__init__(loop, protocol, in_fd, out_fd) - self._get_watcher(loop).add_child_handler(self._process.pid, self._exited) + # https://github.com/python/typeshed/pull/11548 + self._get_watcher(loop).add_child_handler(self._process.pid, self._exited) # type: ignore[arg-type] def set_window_size(self, size: WindowSize) -> None: assert self._pty_fd is not None