diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 0384f60d..08e23a57 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,5 +1,5 @@ """ version info """ -__version__ = "0.39.5" +__version__ = "0.39.6" diff --git a/osxphotos/imageconverter.py b/osxphotos/imageconverter.py index cffbc6ab..b69a46ee 100644 --- a/osxphotos/imageconverter.py +++ b/osxphotos/imageconverter.py @@ -4,7 +4,6 @@ # reference: https://stackoverflow.com/questions/59330149/coreimage-ciimage-write-jpg-is-shifting-colors-macos/59334308#59334308 -import logging import pathlib import Metal @@ -16,6 +15,11 @@ from Foundation import NSDictionary from wurlitzer import pipes +class ImageConversionError(Exception): + """Base class for exceptions in this module. """ + + pass + class ImageConverter: """ Convert images to jpeg. This class is a singleton which will re-use the Core Image CIContext to avoid @@ -60,6 +64,7 @@ class ImageConverter: Raises: ValueError if compression quality not in range 0.0 to 1.0 FileNotFoundError if input_path doesn't exist + ImageConversionError if error during conversion """ # accept input_path or output_path as pathlib.Path @@ -89,8 +94,7 @@ class ImageConverter: input_image = Quartz.CIImage.imageWithContentsOfURL_(input_url) if input_image is None: - logging.debug(f"Could not create CIImage for {input_path}") - return False + raise ImageConversionError(f"Could not create CIImage for {input_path}") output_colorspace = input_image.colorSpace() or Quartz.CGColorSpaceCreateWithName( Quartz.CoreGraphics.kCGColorSpaceSRGB @@ -105,8 +109,7 @@ class ImageConverter: if not error: return True else: - logging.debug( + raise ImageConversionError( "Error converting file {input_path} to jpeg at {output_path}: {error}" ) - return False diff --git a/setup.py b/setup.py index ec801c87..fc3d60a0 100755 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f: setup( name="osxphotos", version=about["__version__"], - description="Manipulate (read-only) Apple's Photos app library on Mac OS X", + description="Export photos from Apple's macOS Photos app and query the Photos library database to access metadata about images.", long_description=about["long_description"], long_description_content_type="text/markdown", author="Rhet Turnbull", diff --git a/tests/test_image_converter.py b/tests/test_image_converter.py index 566accf3..350ec554 100644 --- a/tests/test_image_converter.py +++ b/tests/test_image_converter.py @@ -89,14 +89,15 @@ def test_image_converter_bad_file(): """ Try to convert a file that's not an image """ import pathlib import tempfile - from osxphotos.imageconverter import ImageConverter + from osxphotos.imageconverter import ImageConverter, ImageConversionError converter = ImageConverter() tempdir = tempfile.TemporaryDirectory(prefix="osxphotos_") with tempdir: imgfile = pathlib.Path(TEST_NOT_AN_IMAGE) outfile = pathlib.Path(tempdir.name) / f"{imgfile.stem}.jpeg" - assert not converter.write_jpeg(imgfile, outfile) + with pytest.raises(ImageConversionError): + converter.write_jpeg(imgfile, outfile) def test_image_converter_missing_file():