Skip to content

Commit

Permalink
replace imghdr by puremagic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bernt-matthias committed Oct 29, 2024
1 parent d11d893 commit 713f3de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/galaxy/dependencies/pinned-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/util/image_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Optional,
)

import puremagic

try:
from PIL import Image
except ImportError:
Expand All @@ -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:
Expand Down

0 comments on commit 713f3de

Please sign in to comment.