Skip to content

Commit c80a726

Browse files
author
Tyler Romero
authored
Merge branch 'main' into py313-tests
2 parents f13272a + c29298a commit c80a726

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

pyproject.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ packages = [
99
{include = "**/*.py", from = "src"},
1010
]
1111
readme = "README.md"
12-
version = "0.19.0"
12+
version = "0.20.0"
1313

1414
[tool.poetry.dependencies]
1515
# For certifi, use ">=" instead of "^" since it upgrades its "major version" every year, not really following semver
1616
certifi = ">=2023.7.22"
1717
frozendict = "^2.3.2"
18-
pillow = ">=9.0.0" # TODO: We may want to mark pillow (and numpy) as extra (https://python-poetry.org/docs/master/pyproject#extras)
19-
pydantic = ">=2.0,<3.0.0"
18+
pillow = ">=11.0.0" # TODO: We may want to mark pillow (and numpy) as extra (https://python-poetry.org/docs/master/pyproject#extras)
19+
pydantic = "^2.0.0"
2020
python = ">=3.9,<4.0"
2121
python-dateutil = "^2.9.0"
2222
requests = "^2.28.2"
@@ -42,14 +42,14 @@ types-requests = "^2.28.11.17"
4242

4343
[tool.poetry.group.sphinx-deps.dependencies]
4444
# These are extra / stricter dependencies required to build the API reference docs
45-
Sphinx = {version = "7.2.6", python = ">=3.9.0,<4.0"}
46-
autodoc-pydantic = {version = "2.0.1", python = ">=3.9.0,<4.0"}
47-
pillow = "^9.0.0"
48-
pydantic = "^2.0"
49-
python = ">=3.9.0,<4.0"
45+
Sphinx = {version = "^7.2.6", python = ">=3.9,<4.0"}
46+
autodoc-pydantic = {version = "^2.0.1", python = ">=3.9,<4.0"}
47+
pillow = "^11.0.0"
48+
pydantic = "^2.0.0"
49+
python = ">=3.9,<4.0"
5050
python-dateutil = "^2.8.2"
51-
sphinx-rtd-theme = {version = "1.3.0", python = ">=3.9.0,<4.0"}
52-
toml = "0.10.2"
51+
sphinx-rtd-theme = {version = "^1.3.0", python = ">=3.9,<4.0"}
52+
toml = "^0.10.2"
5353

5454
[tool.poetry.scripts]
5555
groundlight = "groundlight.cli:groundlight"

src/groundlight/images.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pylint: disable=deprecated-module
2-
import imghdr
32
from io import BufferedReader, BytesIO, IOBase
3+
from pathlib import Path
44
from typing import Union
55

66
from groundlight.optional_imports import Image, np
@@ -37,10 +37,11 @@ def bytestream_from_filename(image_filename: str, jpeg_quality: int = DEFAULT_JP
3737
Only supports JPEG and PNG files for now.
3838
For PNG files, we convert to RGB format used in JPEGs.
3939
"""
40-
if imghdr.what(image_filename) == "jpeg":
40+
image_path = Path(image_filename)
41+
if image_path.suffix.lower() in (".jpeg", ".jpg"):
4142
buffer = buffer_from_jpeg_file(image_filename)
4243
return ByteStreamWrapper(data=buffer)
43-
if imghdr.what(image_filename) == "png":
44+
if image_path.suffix.lower() == ".png":
4445
pil_img = Image.open(image_filename)
4546
# This chops off the alpha channel which can cause unexpected behavior, but handles minimal transparency well
4647
pil_img = pil_img.convert("RGB")
@@ -53,7 +54,7 @@ def buffer_from_jpeg_file(image_filename: str) -> BufferedReader:
5354
5455
For now, we only support JPEG files, and raise an ValueError otherwise.
5556
"""
56-
if imghdr.what(image_filename) == "jpeg":
57+
if Path(image_filename).suffix.lower() in (".jpeg", ".jpg"):
5758
# Note this will get fooled by truncated binaries since it only reads the header.
5859
# That's okay - the server will catch it.
5960
return open(image_filename, "rb")

test/integration/test_groundlight.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,16 @@ def test_submit_image_query_bad_filename(gl: Groundlight, detector: Detector):
470470

471471

472472
def test_submit_image_query_bad_jpeg_file(gl: Groundlight, detector: Detector):
473-
with pytest.raises(ValueError) as exc_info:
473+
with pytest.raises(ApiException) as exc_info:
474474
_image_query = gl.submit_image_query(
475475
detector=detector.id, image="test/assets/blankfile.jpeg", human_review="NEVER"
476476
)
477-
assert "jpeg" in str(exc_info).lower()
477+
assert "uploaded image is empty or corrupted" in exc_info.value.body.lower()
478+
with pytest.raises(ValueError) as exc_info:
479+
_image_query = gl.submit_image_query(
480+
detector=detector.id, image="test/assets/blankfile.jpeeeg", human_review="NEVER"
481+
)
482+
assert "we only support jpeg and png" in str(exc_info).lower()
478483

479484

480485
@pytest.mark.skipif(MISSING_PIL, reason="Needs pillow") # type: ignore

0 commit comments

Comments
 (0)