mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Merge pull request #142 from radarhere/webp-require-anim
Suggestions for deprecating older WebP versions
This commit is contained in:
commit
4d544da5c6
|
@ -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:
|
||||
|
@ -43,19 +47,26 @@ def test_version() -> 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")
|
||||
|
|
|
@ -166,7 +166,7 @@ class TestFileWebp:
|
|||
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.
|
||||
"""
|
||||
|
|
|
@ -13,7 +13,7 @@ from .helper import (
|
|||
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:
|
||||
|
|
|
@ -8,7 +8,7 @@ from PIL import Image
|
|||
|
||||
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"
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
----------------
|
||||
|
||||
|
|
|
@ -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
|
||||
===========
|
||||
|
|
36
setup.py
36
setup.py
|
@ -794,25 +794,17 @@ class pil_build_ext(build_ext):
|
|||
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")
|
||||
|
@ -901,12 +893,8 @@ class pil_build_ext(build_ext):
|
|||
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")
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ import warnings
|
|||
from typing import IO
|
||||
|
||||
import PIL
|
||||
from PIL import _deprecate
|
||||
|
||||
from . import Image
|
||||
from ._deprecate import deprecate
|
||||
|
||||
modules = {
|
||||
"pil": ("PIL._imaging", "PILLOW_VERSION"),
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user