mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 10:16:17 +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,6 +18,10 @@ def test_check() -> None:
|
||||||
for codec in features.codecs:
|
for codec in features.codecs:
|
||||||
assert features.check_codec(codec) == features.check(codec)
|
assert features.check_codec(codec) == features.check(codec)
|
||||||
for feature in features.features:
|
for feature in features.features:
|
||||||
|
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)
|
assert features.check_feature(feature) == features.check(feature)
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,18 +47,25 @@ def test_version() -> None:
|
||||||
for codec in features.codecs:
|
for codec in features.codecs:
|
||||||
test(codec, features.version_codec)
|
test(codec, features.version_codec)
|
||||||
for feature in features.features:
|
for feature in features.features:
|
||||||
|
if "webp" in feature:
|
||||||
|
with pytest.warns(DeprecationWarning):
|
||||||
|
test(feature, features.version_feature)
|
||||||
|
else:
|
||||||
test(feature, features.version_feature)
|
test(feature, features.version_feature)
|
||||||
|
|
||||||
|
|
||||||
def test_webp_transparency() -> None:
|
def test_webp_transparency() -> None:
|
||||||
|
with pytest.warns(DeprecationWarning):
|
||||||
assert features.check("transp_webp") == features.check_module("webp")
|
assert features.check("transp_webp") == features.check_module("webp")
|
||||||
|
|
||||||
|
|
||||||
def test_webp_mux() -> None:
|
def test_webp_mux() -> None:
|
||||||
|
with pytest.warns(DeprecationWarning):
|
||||||
assert features.check("webp_mux") == features.check_module("webp")
|
assert features.check("webp_mux") == features.check_module("webp")
|
||||||
|
|
||||||
|
|
||||||
def test_webp_anim() -> None:
|
def test_webp_anim() -> None:
|
||||||
|
with pytest.warns(DeprecationWarning):
|
||||||
assert features.check("webp_anim") == features.check_module("webp")
|
assert features.check("webp_anim") == features.check_module("webp")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ class TestFileWebp:
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
_webp.WebPEncode()
|
_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.
|
Calling decoder functions with no arguments should result in an error.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -13,7 +13,7 @@ from .helper import (
|
||||||
hopper,
|
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:
|
def test_read_rgba() -> None:
|
||||||
|
|
|
@ -8,7 +8,7 @@ from PIL import Image
|
||||||
|
|
||||||
from .helper import assert_image_equal, hopper
|
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"
|
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
|
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).
|
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
|
Removed features
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
|
|
@ -61,10 +61,10 @@ have been deprecated, and will be removed in Pillow 12 (2025-10-15).
|
||||||
Specific WebP Feature Checks
|
Specific WebP Feature Checks
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
The following features ``features.check("transp_webp")``,
|
``features.check("transp_webp")``, ``features.check("webp_mux")`` and
|
||||||
``features.check("webp_mux")``, and ``features.check("webp_anim")`` are now
|
``features.check("webp_anim")`` are now deprecated. They will always return
|
||||||
always ``True`` if the WebP module is installed and should not be used.
|
``True`` if the WebP module is installed, until they are removed in Pillow
|
||||||
These checks will be removed in Pillow 12.0.0 (2025-10-15).
|
12.0.0 (2025-10-15).
|
||||||
|
|
||||||
API Changes
|
API Changes
|
||||||
===========
|
===========
|
||||||
|
|
32
setup.py
32
setup.py
|
@ -794,25 +794,17 @@ class pil_build_ext(build_ext):
|
||||||
if feature.want("webp"):
|
if feature.want("webp"):
|
||||||
_dbg("Looking for webp")
|
_dbg("Looking for webp")
|
||||||
if all(
|
if all(
|
||||||
_find_include_file(self, src)
|
_find_include_file(self, "webp/" + include)
|
||||||
for src in [
|
for include in ("encode.h", "decode.h", "mux.h", "demux.h")
|
||||||
"webp/encode.h",
|
|
||||||
"webp/decode.h",
|
|
||||||
"webp/mux.h",
|
|
||||||
"webp/demux.h",
|
|
||||||
]
|
|
||||||
):
|
):
|
||||||
# In Google's precompiled zip it is call "libwebp":
|
# In Google's precompiled zip it is called "libwebp"
|
||||||
|
for prefix in ("", "lib"):
|
||||||
if all(
|
if all(
|
||||||
_find_library_file(self, lib)
|
_find_library_file(self, prefix + library)
|
||||||
for lib in ["webp", "webpmux", "webpdemux"]
|
for library in ("webp", "webpmux", "webpdemux")
|
||||||
):
|
):
|
||||||
feature.webp = "webp"
|
feature.webp = prefix + "webp"
|
||||||
elif all(
|
break
|
||||||
_find_library_file(self, lib)
|
|
||||||
for lib in ["libwebp", "libwebpmux", "libwebpdemux"]
|
|
||||||
):
|
|
||||||
feature.webp = "libwebp"
|
|
||||||
|
|
||||||
if feature.want("xcb"):
|
if feature.want("xcb"):
|
||||||
_dbg("Looking for xcb")
|
_dbg("Looking for xcb")
|
||||||
|
@ -901,12 +893,8 @@ class pil_build_ext(build_ext):
|
||||||
self._remove_extension("PIL._imagingcms")
|
self._remove_extension("PIL._imagingcms")
|
||||||
|
|
||||||
if feature.webp:
|
if feature.webp:
|
||||||
libs = [
|
libs = [feature.webp, feature.webp + "mux", feature.webp + "demux"]
|
||||||
feature.webp,
|
self._update_extension("PIL._webp", libs)
|
||||||
feature.webp + "mux",
|
|
||||||
feature.webp + "demux",
|
|
||||||
]
|
|
||||||
self._update_extension("PIL._webp", libs, [])
|
|
||||||
else:
|
else:
|
||||||
self._remove_extension("PIL._webp")
|
self._remove_extension("PIL._webp")
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ import warnings
|
||||||
from typing import IO
|
from typing import IO
|
||||||
|
|
||||||
import PIL
|
import PIL
|
||||||
from PIL import _deprecate
|
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
|
from ._deprecate import deprecate
|
||||||
|
|
||||||
modules = {
|
modules = {
|
||||||
"pil": ("PIL._imaging", "PILLOW_VERSION"),
|
"pil": ("PIL._imaging", "PILLOW_VERSION"),
|
||||||
|
@ -149,7 +149,7 @@ def check_feature(feature: str) -> bool | None:
|
||||||
try:
|
try:
|
||||||
imported_module = __import__(module, fromlist=["PIL"])
|
imported_module = __import__(module, fromlist=["PIL"])
|
||||||
if isinstance(flag, bool):
|
if isinstance(flag, bool):
|
||||||
_deprecate.deprecate(f'check_feature("{feature}")', 12)
|
deprecate(f'check_feature("{feature}")', 12)
|
||||||
return flag
|
return flag
|
||||||
return getattr(imported_module, flag)
|
return getattr(imported_module, flag)
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
|
@ -180,7 +180,17 @@ def get_supported_features() -> list[str]:
|
||||||
"""
|
"""
|
||||||
:returns: A list of all supported features.
|
: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:
|
def check(feature: str) -> bool | None:
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
* Check the versions from mux.h and demux.h, to ensure the WebPAnimEncoder and
|
* 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
|
* WebPAnimDecoder APIs are present (initial support was added in 0.5.0). The
|
||||||
* very early versions had some significant differences, so we require later
|
* 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
|
#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
|
#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