From 6fb95f72b091248abf798d1aea237bc591114030 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 | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/dependencies/pinned-requirements.txt b/lib/galaxy/dependencies/pinned-requirements.txt index 91752afea326..325ecb44595f 100644 --- a/lib/galaxy/dependencies/pinned-requirements.txt +++ b/lib/galaxy/dependencies/pinned-requirements.txt @@ -133,6 +133,7 @@ propcache==0.2.0 ; python_version >= "3.8" and python_version < "3.13" prov==1.5.1 ; python_version >= "3.8" and python_version < "3.13" psutil==6.1.0 ; python_version >= "3.8" and python_version < "3.13" pulsar-galaxy-lib==0.15.6 ; python_version >= "3.8" and python_version < "3.13" +puremagic==1.28 ; python_version >= "3.8" and python_version < "3.13" pycparser==2.22 ; python_version >= "3.8" and python_version < "3.13" pycryptodome==3.21.0 ; python_version >= "3.8" and python_version < "3.13" pydantic-core==2.23.4 ; 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..7d867525dfb8 100644 --- a/lib/galaxy/util/image_util.py +++ b/lib/galaxy/util/image_util.py @@ -1,12 +1,13 @@ """Provides utilities for working with image files.""" -import imghdr import logging from typing import ( List, Optional, ) +import puremagic + try: from PIL import Image except ImportError: @@ -26,7 +27,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: