From 713f3de8a665f6c918b728b2968ffc3101e71844 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Tue, 29 Oct 2024 12:38:10 +0100 Subject: [PATCH] replace imghdr by puremagic imghdr allowed to detect a few imagetimes and has been deprecated in python 3.13: https://docs.python.org/3.12/library/imghdr.html from the release notes: > The filetype, puremagic, or python-magic libraries should be used as replacements. > For example, the puremagic.what() function can be used to replace the imghdr.what() > function for all file formats that were supported by imghdr. See also https://github.com/cdgriffith/puremagic/blob/763349ec4d02ba930fb1142c6eb684afdf06c6ab/puremagic/main.py#L421 --- lib/galaxy/dependencies/pinned-requirements.txt | 1 + lib/galaxy/util/image_util.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/dependencies/pinned-requirements.txt b/lib/galaxy/dependencies/pinned-requirements.txt index 91752afea326..306980686438 100644 --- a/lib/galaxy/dependencies/pinned-requirements.txt +++ b/lib/galaxy/dependencies/pinned-requirements.txt @@ -86,6 +86,7 @@ h5py==3.11.0 ; python_version >= "3.8" and python_version < "3.9" h5py==3.12.1 ; python_version >= "3.9" and python_version < "3.13" humanfriendly==10.0 ; python_version >= "3.8" and python_version < "3.13" idna==3.10 ; python_version >= "3.8" and python_version < "3.13" +puremagic=1.28 ; python_version >= "3.8" and python_version < "3.13" importlib-metadata==8.5.0 ; python_version >= "3.8" and python_version < "3.13" importlib-resources==6.4.5 ; python_version >= "3.8" and python_version < "3.9" isa-rwval @ git+https://github.com/nsoranzo/isa-rwval.git@3d989181058d2765a93cb0e7ca85d6955e0eb6ef ; python_version >= "3.8" and python_version < "3.13" diff --git a/lib/galaxy/util/image_util.py b/lib/galaxy/util/image_util.py index 3b11a50d2fda..127b18df648f 100644 --- a/lib/galaxy/util/image_util.py +++ b/lib/galaxy/util/image_util.py @@ -7,6 +7,8 @@ Optional, ) +import puremagic + try: from PIL import Image except ImportError: @@ -26,7 +28,7 @@ def image_type(filename: str) -> Optional[str]: # exception we expect to happen frequently, so we're not logging pass if not fmt: - fmt = imghdr.what(filename) + fmt = puremagic.what(filename) if fmt: return fmt.upper() else: