Extend image optimization to support in-memory streams(BytesIO/bytes) and dst_format param#289
Extend image optimization to support in-memory streams(BytesIO/bytes) and dst_format param#289cking100 wants to merge 1 commit intoopenzim:mainfrom
Conversation
|
I've converted PR to draft since it is not ready, please mark it as ready once ... ready 🤣 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #289 +/- ##
==========================================
- Coverage 99.52% 99.33% -0.20%
==========================================
Files 41 41
Lines 2516 2545 +29
Branches 354 365 +11
==========================================
+ Hits 2504 2528 +24
+ Misses 8 6 -2
- Partials 4 11 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e5357ec to
c10b2eb
Compare
|
@benoit74 I will add the test cases soon. But, before that, can I please get a review on the changes? |
benoit74
left a comment
There was a problem hiding this comment.
Few remarks. You are on the right path, thank you
631d2e7 to
b0eea3c
Compare
|
@benoit74 I have made the requested changes. Can you please take a look? Thanks |
benoit74
left a comment
There was a problem hiding this comment.
Nice, I realize we still have "details" to sort out ^^
Another general question: do we really need the @overload definitions now? I don't get anymore what they are adding in this specific case since it looks to me we now support all combinations (src is Path and dst is BytesIo, src is BytesIO and dst is Path, ...)
|
Regarding the Overloads, since these functions are used by multiple scrapers, you might know better than me. We can either remove overloads and have cleaner code, but then we will have to deal with union type every time the functions are being called, or keep them and don't worry about it. @benoit74 |
Let keep it as-is for now and I will double-check this later |
b0eea3c to
bb3e1c6
Compare
bb3e1c6 to
c312f81
Compare
benoit74
left a comment
There was a problem hiding this comment.
Few more remarks + I now realize we probably do not need to add convert option to other optimize_xxx methods. We should just get src_format from src, and if it is different than method format then we do the conversion.
This also means that we probably shouldn't try to guess src_format in optimize_image and delegate that responsibility to optimize_xxx methods.
Adding a convert option to each optimize method made things complicated. This change would help simplify the code.
So we no longer need to call I will update the PR with requested changes soon. Thank you |
Yes, since we will now support implicit conversion. I do not see a use-case where one would be sad that we've implicitly performed the required conversion. Maybe I miss some cases, but let's keep it simple for the time being. |
c312f81 to
1886348
Compare
|
@benoit74 I have updated the PR with the requested changes. Also, removed the overloads as I think it would be cleaner this way, and kept the This change will result in one of the test cases |
|
Code changes LGTM, well done. |
1886348 to
a2145cc
Compare
a2145cc to
f3334d2
Compare
|
@benoit74 Done. Added the test cases as well. Please have a look, and thank you |
f3334d2 to
7700cad
Compare
|
@cking100 I've been out of office most of last week so I'm slowly recovering, I'll come back to you sometime this week. In the mean time, can you please at least fix the PR title and CHANGELOG entry to something more "aligned" with the changes we've made. Thank you. |
|
@benoit74 Sure, I will fix the PR title and CHANGELOG entry. And no worries, take your time. |
7700cad to
4dcf9e7
Compare
benoit74
left a comment
There was a problem hiding this comment.
LGTM, thanks a lot, this has been a tedious work for something quite lean in the end (which I'm happy about, I just wanted to acknowledge the effort you've put in this change which could look quite minimal in the end).
@rgaudin do you want to have a look as well now that this is ready or not?
|
I took a quick look at it ; looks good. |
|
@cking100 please take a look at QA issues + we aim to have 100% code coverage, so please add required ones. I'm a bit surprised If one line is especially stupid to cover I'm OK to introduce a pragma to ignore it in coverage report, but I feel like some important things should be covered with proper test cases (e.g. pass |
Thank you. I know it turned out to be simple, but it needed to be done to be able to fix it. Happy to help.
I will fix the QA issues. The coverage was around 96% for optimization.py, with a few lines inside
AFAIR this is already covered by the test case |
4dcf9e7 to
c8427ef
Compare
conversion to optimize_xxx methods
c8427ef to
08817bd
Compare
|
@benoit74 Fixed the QA issues and also added the test cases. The overall coverage is 99% now. Please have a look, thanks |
Fixes #284
Changes:
optimize_imageandoptimize_gifto acceptio.BytesIOas inputbytesassrcinsideoptimize_imageconvertparameter deprecated foroptimize_image. Users should now usedst_formatinstead.optimize_xxxmethods