Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions for deprecating older WebP versions #142

Merged
merged 7 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions Tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def test_check() -> None:
for codec in features.codecs:
assert features.check_codec(codec) == features.check(codec)
for feature in features.features:
assert features.check_feature(feature) == features.check(feature)
if "webp" in feature:
with pytest.warns(DeprecationWarning):
assert features.check_feature(feature) == features.check(feature)
else:
assert features.check_feature(feature) == features.check(feature)


def test_version() -> None:
Expand All @@ -43,19 +47,26 @@ def test(name: str, function: Callable[[str], str | None]) -> None:
for codec in features.codecs:
test(codec, features.version_codec)
for feature in features.features:
test(feature, features.version_feature)
if "webp" in feature:
with pytest.warns(DeprecationWarning):
test(feature, features.version_feature)
else:
test(feature, features.version_feature)


def test_webp_transparency() -> None:
assert features.check("transp_webp") == features.check_module("webp")
with pytest.warns(DeprecationWarning):
assert features.check("transp_webp") == features.check_module("webp")


def test_webp_mux() -> None:
assert features.check("webp_mux") == features.check_module("webp")
with pytest.warns(DeprecationWarning):
assert features.check("webp_mux") == features.check_module("webp")


def test_webp_anim() -> None:
assert features.check("webp_anim") == features.check_module("webp")
with pytest.warns(DeprecationWarning):
assert features.check("webp_anim") == features.check_module("webp")


@skip_unless_feature("libjpeg_turbo")
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_WebPEncode_with_invalid_args(self) -> None:
with pytest.raises(TypeError):
_webp.WebPEncode()

def test_WebPDecode_with_invalid_args(self) -> None:
def test_WebPAnimDecoder_with_invalid_args(self) -> None:
"""
Calling decoder functions with no arguments should result in an error.
"""
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_webp_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
hopper,
)

_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
pytest.importorskip("PIL._webp", reason="WebP support not installed")


def test_read_rgba() -> None:
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_webp_lossless.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .helper import assert_image_equal, hopper

_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
pytest.importorskip("PIL._webp", reason="WebP support not installed")
RGB_MODE = "RGB"


Expand Down
10 changes: 10 additions & 0 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ JpegImageFile.huffman_ac and JpegImageFile.huffman_dc
The ``huffman_ac`` and ``huffman_dc`` dictionaries on JPEG images were unused. They
have been deprecated, and will be removed in Pillow 12 (2025-10-15).

Specific WebP Feature Checks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. deprecated:: 11.0.0

``features.check("transp_webp")``, ``features.check("webp_mux")`` and
``features.check("webp_anim")`` are now deprecated. They will always return
``True`` if the WebP module is installed, until they are removed in Pillow
12.0.0 (2025-10-15).

Removed features
----------------

Expand Down
8 changes: 4 additions & 4 deletions docs/releasenotes/11.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ have been deprecated, and will be removed in Pillow 12 (2025-10-15).
Specific WebP Feature Checks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The following features ``features.check("transp_webp")``,
``features.check("webp_mux")``, and ``features.check("webp_anim")`` are now
always ``True`` if the WebP module is installed and should not be used.
These checks will be removed in Pillow 12.0.0 (2025-10-15).
``features.check("transp_webp")``, ``features.check("webp_mux")`` and
``features.check("webp_anim")`` are now deprecated. They will always return
``True`` if the WebP module is installed, until they are removed in Pillow
12.0.0 (2025-10-15).

API Changes
===========
Expand Down
36 changes: 12 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,25 +794,17 @@ def build_extensions(self):
if feature.want("webp"):
_dbg("Looking for webp")
if all(
_find_include_file(self, src)
for src in [
"webp/encode.h",
"webp/decode.h",
"webp/mux.h",
"webp/demux.h",
]
_find_include_file(self, "webp/" + include)
for include in ("encode.h", "decode.h", "mux.h", "demux.h")
):
# In Google's precompiled zip it is call "libwebp":
if all(
_find_library_file(self, lib)
for lib in ["webp", "webpmux", "webpdemux"]
):
feature.webp = "webp"
elif all(
_find_library_file(self, lib)
for lib in ["libwebp", "libwebpmux", "libwebpdemux"]
):
feature.webp = "libwebp"
# In Google's precompiled zip it is called "libwebp"
for prefix in ("", "lib"):
if all(
_find_library_file(self, prefix + library)
for library in ("webp", "webpmux", "webpdemux")
):
feature.webp = prefix + "webp"
break

if feature.want("xcb"):
_dbg("Looking for xcb")
Expand Down Expand Up @@ -901,12 +893,8 @@ def build_extensions(self):
self._remove_extension("PIL._imagingcms")

if feature.webp:
libs = [
feature.webp,
feature.webp + "mux",
feature.webp + "demux",
]
self._update_extension("PIL._webp", libs, [])
libs = [feature.webp, feature.webp + "mux", feature.webp + "demux"]
self._update_extension("PIL._webp", libs)
else:
self._remove_extension("PIL._webp")

Expand Down
16 changes: 13 additions & 3 deletions src/PIL/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from typing import IO

import PIL
from PIL import _deprecate

from . import Image
from ._deprecate import deprecate

modules = {
"pil": ("PIL._imaging", "PILLOW_VERSION"),
Expand Down Expand Up @@ -149,7 +149,7 @@ def check_feature(feature: str) -> bool | None:
try:
imported_module = __import__(module, fromlist=["PIL"])
if isinstance(flag, bool):
_deprecate.deprecate(f'check_feature("{feature}")', 12)
deprecate(f'check_feature("{feature}")', 12)
return flag
return getattr(imported_module, flag)
except ModuleNotFoundError:
Expand Down Expand Up @@ -180,7 +180,17 @@ def get_supported_features() -> list[str]:
"""
:returns: A list of all supported features.
"""
return [f for f in features if check_feature(f)]
supported_features = []
for f, (module, flag, _) in features.items():
if flag is True:
for feature, (feature_module, _) in modules.items():
if feature_module == module:
if check_module(feature):
supported_features.append(f)
break
elif check_feature(f):
supported_features.append(f)
return supported_features


def check(feature: str) -> bool | None:
Expand Down
2 changes: 1 addition & 1 deletion src/_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Check the versions from mux.h and demux.h, to ensure the WebPAnimEncoder and
* WebPAnimDecoder APIs are present (initial support was added in 0.5.0). The
* very early versions had some significant differences, so we require later
* versions, before enabling animation support.
* versions.
*/
#if WEBP_MUX_ABI_VERSION < 0x0106 || WEBP_DEMUX_ABI_VERSION < 0x0107
#error libwebp 0.5.0 and above is required. Upgrade libwebp or build Pillow with --disable-webp flag
Expand Down
Loading