Skip to content

Commit 6830a32

Browse files
committed
Drop use of deprecated imghdr standard library module
which has been removed in the upcoming Python 3.13 .
1 parent 6df122d commit 6830a32

File tree

8 files changed

+19
-11
lines changed

8 files changed

+19
-11
lines changed

lib/galaxy/util/image_util.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Provides utilities for working with image files."""
22

3-
import imghdr
43
import logging
54
from typing import (
65
List,
@@ -22,11 +21,7 @@ def image_type(filename: str) -> Optional[str]:
2221
with Image.open(filename) as im:
2322
fmt = im.format
2423
except Exception:
25-
# We continue to try with imghdr, so this is a rare case of an
26-
# exception we expect to happen frequently, so we're not logging
2724
pass
28-
if not fmt:
29-
fmt = imghdr.what(filename)
3025
if fmt:
3126
return fmt.upper()
3227
else:

packages/app/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ install_requires =
4141
galaxy-objectstore
4242
galaxy-tool-util[cwl,edam]
4343
galaxy-tours
44-
galaxy-util
44+
galaxy-util[image_util]
4545
galaxy-web-framework
4646
galaxy-web-stack
4747
Beaker

packages/data/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ install_requires =
3636
galaxy-objectstore
3737
galaxy-schema
3838
galaxy-tool-util
39-
galaxy-util[template]
39+
galaxy-util[image_util,template]
4040
alembic
4141
alembic-utils
4242
bdbag>=1.6.3

packages/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ while read -r package_dir || [ -n "$package_dir" ]; do # https://stackoverflow.
4949

5050
# Install extras (if needed)
5151
if [ "$package_dir" = "util" ]; then
52-
pip install '.[template,jstree,config_template]'
52+
pip install '.[image_util,template,jstree,config_template]'
5353
elif [ "$package_dir" = "tool_util" ]; then
5454
pip install '.[cwl,mulled,edam,extended-assertions]'
5555
else

packages/tool_shed/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ install_requires =
3636
galaxy-auth
3737
galaxy-config
3838
galaxy-data
39-
galaxy-util
39+
galaxy-util[image_util]
4040
galaxy-web-framework
4141
galaxy-web-stack
4242
galaxy-web-apps

packages/tool_util/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ version = 24.2.dev0
3333
[options]
3434
include_package_data = True
3535
install_requires =
36-
galaxy-util>=22.1
36+
galaxy-util[image_util]>=22.1
3737
conda-package-streaming
3838
lxml!=4.2.2
3939
MarkupSafe

packages/util/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ packages = find:
4848
python_requires = >=3.7
4949

5050
[options.extras_require]
51+
image_util =
52+
pillow
5153
jstree =
5254
dictobj
5355
template =

test/unit/util/test_checkers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import os.path
12
import tempfile
23

3-
from galaxy.util.checkers import check_html
4+
from galaxy.util.checkers import (
5+
check_html,
6+
check_image,
7+
)
48

59

610
def test_check_html():
@@ -17,3 +21,10 @@ def test_check_html():
1721
tmpb.write(b"\x1f\x8b")
1822
tmpb.flush()
1923
assert not check_html(tmpb.name)
24+
25+
26+
def test_check_image():
27+
for filename, expected in (("1.tiff", True), ("454Score.png", True), ("1.bam", False)):
28+
path = f"test-data/{filename}"
29+
assert os.path.exists(path)
30+
assert check_image(path) is expected

0 commit comments

Comments
 (0)