Skip to content

Commit

Permalink
Drop use of deprecated imghdr standard library module
Browse files Browse the repository at this point in the history
which has been removed in the upcoming Python 3.13 .
  • Loading branch information
nsoranzo committed Oct 31, 2024
1 parent 695e86e commit ac480e7
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 11 deletions.
5 changes: 0 additions & 5 deletions lib/galaxy/util/image_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides utilities for working with image files."""

import imghdr
import logging
from typing import (
List,
Expand All @@ -22,11 +21,7 @@ def image_type(filename: str) -> Optional[str]:
with Image.open(filename) as im:
fmt = im.format
except Exception:
# We continue to try with imghdr, so this is a rare case of an
# exception we expect to happen frequently, so we're not logging
pass
if not fmt:
fmt = imghdr.what(filename)
if fmt:
return fmt.upper()
else:
Expand Down
2 changes: 1 addition & 1 deletion packages/app/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ install_requires =
galaxy-objectstore
galaxy-tool-util[cwl,edam]
galaxy-tours
galaxy-util
galaxy-util[image_util]
galaxy-web-framework
galaxy-web-stack
Beaker
Expand Down
2 changes: 1 addition & 1 deletion packages/data/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ install_requires =
galaxy-objectstore
galaxy-schema
galaxy-tool-util
galaxy-util[template]
galaxy-util[image_util,template]
alembic
alembic-utils
bdbag>=1.6.3
Expand Down
2 changes: 1 addition & 1 deletion packages/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ while read -r package_dir || [ -n "$package_dir" ]; do # https://stackoverflow.

# Install extras (if needed)
if [ "$package_dir" = "util" ]; then
pip install '.[template,jstree,config_template]'
pip install '.[image_util,template,jstree,config_template]'
elif [ "$package_dir" = "tool_util" ]; then
pip install '.[cwl,mulled,edam,extended-assertions]'
else
Expand Down
2 changes: 1 addition & 1 deletion packages/tool_shed/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ install_requires =
galaxy-auth
galaxy-config
galaxy-data
galaxy-util
galaxy-util[image_util]
galaxy-web-framework
galaxy-web-stack
galaxy-web-apps
Expand Down
2 changes: 1 addition & 1 deletion packages/tool_util/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ version = 24.2.dev0
[options]
include_package_data = True
install_requires =
galaxy-util>=22.1
galaxy-util[image_util]>=22.1
conda-package-streaming
lxml!=4.2.2
MarkupSafe
Expand Down
2 changes: 2 additions & 0 deletions packages/util/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ packages = find:
python_requires = >=3.7

[options.extras_require]
image_util =
pillow
jstree =
dictobj
template =
Expand Down
13 changes: 12 additions & 1 deletion test/unit/util/test_checkers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import os.path
import tempfile

from galaxy.util.checkers import check_html
from galaxy.util.checkers import (
check_html,
check_image,
)


def test_check_html():
Expand All @@ -17,3 +21,10 @@ def test_check_html():
tmpb.write(b"\x1f\x8b")
tmpb.flush()
assert not check_html(tmpb.name)


def test_check_image():
for filename, expected in (("1.tiff", True), ("454Score.png", True), ("1.bam", False)):
path = f"test-data/{filename}"
assert os.path.exists(path)
assert check_image(path) is expected

0 comments on commit ac480e7

Please sign in to comment.