diff --git a/lib/galaxy/util/image_util.py b/lib/galaxy/util/image_util.py index 3b11a50d2fda..b8c26cf0ff54 100644 --- a/lib/galaxy/util/image_util.py +++ b/lib/galaxy/util/image_util.py @@ -1,6 +1,5 @@ """Provides utilities for working with image files.""" -import imghdr import logging from typing import ( List, @@ -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: diff --git a/packages/app/setup.cfg b/packages/app/setup.cfg index fe0dfe430c91..7f3e9775529e 100644 --- a/packages/app/setup.cfg +++ b/packages/app/setup.cfg @@ -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 diff --git a/packages/data/setup.cfg b/packages/data/setup.cfg index 01f623c7d199..2dd4e7e16b07 100644 --- a/packages/data/setup.cfg +++ b/packages/data/setup.cfg @@ -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 diff --git a/packages/test.sh b/packages/test.sh index d2ed377c352b..2120ac2b922a 100755 --- a/packages/test.sh +++ b/packages/test.sh @@ -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 diff --git a/packages/tool_shed/setup.cfg b/packages/tool_shed/setup.cfg index 7cd328385896..0e9de75e1a4e 100644 --- a/packages/tool_shed/setup.cfg +++ b/packages/tool_shed/setup.cfg @@ -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 diff --git a/packages/tool_util/setup.cfg b/packages/tool_util/setup.cfg index eabca1a6e1b9..c0cdb4935917 100644 --- a/packages/tool_util/setup.cfg +++ b/packages/tool_util/setup.cfg @@ -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 diff --git a/packages/util/setup.cfg b/packages/util/setup.cfg index bb6a232cc1e2..09380cd65be1 100644 --- a/packages/util/setup.cfg +++ b/packages/util/setup.cfg @@ -48,6 +48,8 @@ packages = find: python_requires = >=3.7 [options.extras_require] +image_util = + pillow jstree = dictobj template = diff --git a/test/unit/util/test_checkers.py b/test/unit/util/test_checkers.py index 1e30d25656cd..b474defc965a 100644 --- a/test/unit/util/test_checkers.py +++ b/test/unit/util/test_checkers.py @@ -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(): @@ -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