From 7125fe4096927a77d5e6ed278f94e387724f7a02 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 7 May 2025 23:29:54 +1000 Subject: [PATCH] Fixed type hints --- Tests/test_file_jxl.py | 4 +++- Tests/test_file_jxl_metadata.py | 20 +++++++++----------- setup.py | 19 +++++++++---------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Tests/test_file_jxl.py b/Tests/test_file_jxl.py index c1b730a79..96b6b0ea5 100644 --- a/Tests/test_file_jxl.py +++ b/Tests/test_file_jxl.py @@ -45,7 +45,9 @@ class TestFileJpegXl: def test_version(self) -> None: _jpegxl.JpegXlDecoderVersion() - assert re.search(r"\d+\.\d+\.\d+$", features.version_module("jpegxl")) + version = features.version_module("jpegxl") + assert version is not None + assert re.search(r"\d+\.\d+\.\d+$", version) def test_read_rgb(self) -> None: """ diff --git a/Tests/test_file_jxl_metadata.py b/Tests/test_file_jxl_metadata.py index d92a82e02..bf21be993 100644 --- a/Tests/test_file_jxl_metadata.py +++ b/Tests/test_file_jxl_metadata.py @@ -29,8 +29,7 @@ except ImportError: def test_read_exif_metadata() -> None: - file_path = "Tests/images/flower.jxl" - with Image.open(file_path) as image: + with Image.open("Tests/images/flower.jxl") as image: assert image.format == "JPEG XL" exif_data = image.info.get("exif", None) assert exif_data @@ -43,8 +42,8 @@ def test_read_exif_metadata() -> None: with Image.open("Tests/images/flower.jpg") as jpeg_image: expected_exif = jpeg_image.info["exif"] - # jpeg xl always returns exif without 'Exif\0\0' prefix - assert exif_data == expected_exif[6:] + # jpeg xl always returns exif without 'Exif\0\0' prefix + assert exif_data == expected_exif[6:] def test_read_exif_metadata_without_prefix() -> None: @@ -53,21 +52,20 @@ def test_read_exif_metadata_without_prefix() -> None: assert im.info["exif"][:6] != b"Exif\x00\x00" exif = im.getexif() - assert exif[305] == "Adobe Photoshop CS6 (Macintosh)" + assert exif[305] == "Adobe Photoshop CS6 (Macintosh)" def test_read_icc_profile() -> None: - file_path = "Tests/images/flower2.jxl" - with Image.open(file_path) as image: + with Image.open("Tests/images/flower2.jxl") as image: assert image.format == "JPEG XL" assert image.info.get("icc_profile", None) icc = image.info["icc_profile"] - with Image.open("Tests/images/flower2.jxl") as jpeg_image: - expected_icc = jpeg_image.info["icc_profile"] + with Image.open("Tests/images/flower2.jxl") as jpeg_image: + expected_icc = jpeg_image.info["icc_profile"] - assert icc == expected_icc + assert icc == expected_icc def test_getxmp() -> None: @@ -110,7 +108,7 @@ def test_4_byte_exif(monkeypatch: pytest.MonkeyPatch) -> None: def get_icc(self) -> None: pass - def get_exif(self) -> None: + def get_exif(self) -> bytes: return b"\0\0\0\0" def get_xmp(self) -> None: diff --git a/setup.py b/setup.py index ac1900d8a..d8526e53e 100644 --- a/setup.py +++ b/setup.py @@ -753,7 +753,7 @@ class pil_build_ext(build_ext): self, "jxl/decode.h" ): if _find_library_file(self, "jxl"): - feature.set("jpegxl", "jxl jxl_threads") + feature.set("jpegxl", "jxl") if feature.want("imagequant"): _dbg("Looking for imagequant") @@ -838,15 +838,6 @@ class pil_build_ext(build_ext): # alternate Windows name. feature.set("lcms", "lcms2_static") - if feature.get("jpegxl"): - # jxl and jxl_threads are required - libs = feature.get("jpegxl").split() - defs = [] - - self._update_extension("PIL._jpegxl", libs, defs) - else: - self._remove_extension("PIL._jpegxl") - if feature.want("webp"): _dbg("Looking for webp") if all( @@ -970,6 +961,14 @@ class pil_build_ext(build_ext): else: self._remove_extension("PIL._avif") + jpegxl = feature.get("jpegxl") + if isinstance(jpegxl, str): + # jxl and jxl_threads are required + libs = [jpegxl, jpegxl + "_threads"] + self._update_extension("PIL._jpegxl", libs) + else: + self._remove_extension("PIL._jpegxl") + tk_libs = ["psapi"] if sys.platform in ("win32", "cygwin") else [] self._update_extension("PIL._imagingtk", tk_libs)