Skip to content

Commit

Permalink
Bring back removed features, add deprecations and Release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed Jul 8, 2024
1 parent 8303152 commit 709f103
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def test(name: str, function: Callable[[str], str | None]) -> None:
test(feature, features.version_feature)


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


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


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


@skip_unless_feature("libjpeg_turbo")
def test_libjpeg_turbo_version() -> None:
version = features.version("libjpeg_turbo")
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Support for the following features can be checked:
* ``raqm``: Raqm library, required for ``ImageFont.Layout.RAQM`` in :py:func:`PIL.ImageFont.truetype`. Run-time version number is available for Raqm 0.7.0 or newer.
* ``libimagequant``: (compile time) ImageQuant quantization support in :py:func:`PIL.Image.Image.quantize`. Run-time version number is available.
* ``xcb``: (compile time) Support for X11 in :py:func:`PIL.ImageGrab.grab` via the XCB library.
* ``transp_webp``: Deprecated. Always ``True`` if WebP module is installed.
* ``webp_mux``: Deprecated. Always ``True`` if WebP module is installed.
* ``webp_anim``: Deprecated. Always ``True`` if WebP module is installed.

.. autofunction:: PIL.features.check_feature
.. autofunction:: PIL.features.version_feature
Expand Down
9 changes: 6 additions & 3 deletions docs/releasenotes/11.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ similarly removed.
Deprecations
============

TODO
^^^^
WebP Features Test
^^^^^^^^^^^^^^^^^^

TODO
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 sohuld not be used.
These checks wil be removed in Pillow 12.0.0 (2025-10-15).

API Changes
===========
Expand Down
10 changes: 9 additions & 1 deletion src/PIL/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import IO

import PIL
from PIL import _deprecate

from . import Image

Expand Down Expand Up @@ -119,6 +120,9 @@ def get_supported_codecs() -> list[str]:


features = {
"webp_anim": ("PIL._webp", True, None),
"webp_mux": ("PIL._webp", True, None),
"transp_webp": ("PIL._webp", True, None),
"raqm": ("PIL._imagingft", "HAVE_RAQM", "raqm_version"),
"fribidi": ("PIL._imagingft", "HAVE_FRIBIDI", "fribidi_version"),
"harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"),
Expand All @@ -144,7 +148,11 @@ def check_feature(feature: str) -> bool | None:

try:
imported_module = __import__(module, fromlist=["PIL"])
return getattr(imported_module, flag)
if isinstance(flag, str):
return getattr(imported_module, flag)
else:
_deprecate.deprecate(f'check_feature("{feature}")', 12)
return flag
except ModuleNotFoundError:
return None
except ImportError as ex:
Expand Down

0 comments on commit 709f103

Please sign in to comment.