-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait before we actually need to process the image for checking if Pillow can handle it. #72
base: main
Are you sure you want to change the base?
Wait before we actually need to process the image for checking if Pillow can handle it. #72
Conversation
…low can handle it. This avoids loading the image needlessly.
2628392
to
41a5152
Compare
41a5152
to
90c3fc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@patrickfournier thank you, as always, for this. I think it would work (functionally) as is, but I've added some note that I think would improve it.
i = Image.open(path) | ||
except UnidentifiedImageError: | ||
logger.warning( | ||
"%s Source image %s is not supported by Pillow.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When putting a filename like this in a log message, I like to wrap the name in quotes (single or double).
This is probably more for Windows, as Rich (the log processing library) doesn't consistently pick out Windows filenames.
return None | ||
except FileNotFoundError: | ||
logger.warning( | ||
"%s Source image %s not found.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put this filename in quotes too (single or double, but match above).
|
||
i = Image.open(image[0]) | ||
i = try_open_image(image[0]) | ||
if i is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like it would be better (more Python-ic) to re-raise the exemptions in try_open_image()
, and then catch them here.
Are there other cases (than raised exemptions) that i
could come back as None
?
LOG_PREFIX, | ||
path, | ||
) | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I note below, it seems to me that it would be more Python-ic to re-raise the exemption, rather than returning a placeholder value like this.
Something like:
try:
# ...
except UnidentifiedImageError as e:
# log message
raise e
…recommendations Add Release.md Closes #72 # Conflicts: # pelican/plugins/image_process/image_process.py
This avoids loading the image needlessly.