Repository navigation
Conversation
53b6486 to
4da244a
Compare
4da244a to
070b003
Compare
35ad235 to
bfd945f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #233 +/- ##
==========================================
+ Coverage 94.09% 94.33% +0.23%
==========================================
Files 1 1
Lines 542 600 +58
==========================================
+ Hits 510 566 +56
- Misses 32 34 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bfd945f to
de46d68
Compare
|
Ready for review, wheels build still failing on ubuntu arm64 for "known reasons" but rest is in place so ready to be analyzed |
rgaudin
left a comment
There was a problem hiding this comment.
Thank you @benoit74,
When we designed this on libzim, it was very clear that:
- attributes are an optional, for-the-future feature that we have no real use case for. It's still not in the spec.
- independant width and height are important now
- scale is important now
We thus requested to be able to directly add illustration directly using width, height, scale. That's not the case with this.
If there are libzim primitives to do it, bind them, if it's the same, add the necessary python glue.
On the reader side, it's less important but I feel like a lot is left on the hands of the libzim-user.
How do I know if 48x48 has various scales? I have to loop through all the getIllustrationInfos() results…
|
Thank you! Regarding addIllustrations, there is "only" four variants available in the libzim: https://github.com/openzim/libzim/blob/8ef511ba0de6a8180d79fbc3c7edcfec4202ae5e/include/zim/writer/creator.h#L165-L197 ; I did not exposed the "contentProvider" variants because the one previously present was not exposed either. I could add the two missing, but it will change nothing to your point. I generally second your remarks and frustrations about how "complex" stuff still is with current PR, but I considered we've agreed python-libzim should be a very thin wrapper on top of the libzim, and everything more "complex" should go into the python-scraperlib. I feel like your python-glue is something which should be implemented in the python-scraperlib. For instance even with only this PR, it is already possible to do things like below which are not "that" awful. IllustrationInfo is just a structure to hold all details about the illustration: Details point are all valid. |
I don't think so but this is debatable of course. scraperlib is not intended for many users. It is, as its name implies, scraper-oriented and quite large and have many dependencies. We can do as we please there because we are the main users and requiring explicit extra types for this is OK there. We're already enforcing a lot of stuff, because we're the ones using it. pylibzim on the other end is to be used by hopefully many users. It has zero runtime dependency, is lightweight and lean. It just seems silly to push this uncomfortable change to our users but let's keep this PR like this and open a separate ticket to discuss whether we want to make an exception or not. |
839a33e to
7db4684
Compare
|
Simple changes pushed, but I'm not comfortable with merging this if you are not comfortable with this PR "design" ; changing this afterwards might means breaking the API so needs a major, uncomfortable changes for "users", etc ... I see no urgency in pushing these changes to the python-libzim, since we have no use-case so far, and would prefer to have a decision comfortable for everyone. And I somehow share your concerns, especially on the reader side. I'm less embarrassed by the fact that we need the new Since python-libzim is anyway not used by our readers (so far, unfortunately?), maybe a simple middle ground would be:
WDYT? |
|
I'm fine with this simple glue strategy. It's dumb enough to not be a problem, as you wrote. Regarding the more complex reader usage, there's a ticket for that on libzim, it will definitely be implemented there but first step was to allow addition of multiple scales and width. |
|
Hum, I'm afraid that in fact this simple glue strategy is not that simple, because it will break the API or introduce dirty glue code for Currently second argument to add_illustration is the content. If content can be either second or third or fourth depending on other arguments, this is either brittle (we count arguments to know where content is) or breaking (we force content to be a named argument). Do you have suggestion about how to handle this? Should we introduce different method names? I'm puzzled Same kind of issue with the scale in |
|
Well libzim 9.4.0 did break the API (version doesn't tell because they don't respect semver) so I see no reason we wouldn't allow ourselves to. Also, it's a binding not a pure copy which it can't be, especially since python doesn't support overloading natively. To me it would only make sense to have the content the first param and the rest afterwards. It could even be a single func with What do you think? |
|
I don't know ; I will make a first release with 9.4.0 and Python 3.13 but without this PR, and then we will have time to take informed decision |
|
Pushed two follow-up commits to move this forward after being stuck on the API design question: 1.
2. The previous |
|
@rgaudin feedback is welcomed on these changes |
|
Looks OK ; can you resolve or revive remaining discussions? |
|
Thank you. They are indeed all resolved ; shall I squash and rebase on main? |
rgaudin
left a comment
There was a problem hiding this comment.
See inline comments ; otherwise looks good to me. didn't test it.
Addresses rgaudin's review on PR #233: - add_illustration/get_illustration_item took a Union[int, IllustrationInfo] first argument, which needed an awkward name (squaresize_or_width_or_info) and runtime isinstance dispatch. Split each into a width/height/scale shortcut (no IllustrationInfo involved) and a separate *_info method that mirrors libzim's own IllustrationInfo-based overload directly, with the shortcut building an IllustrationInfo and delegating to it. - Renamed get_illustration_infos to get_illustrations_info ("info" has no plural) and updated the get_illustration_sizes() deprecation message to point at it. - Simplified the get_illustrations_info width/height/min_scale validation and turned the result-building loop into a list comprehension. - Trimmed the IllustrationInfo docstring's usage-guidance paragraph; that's PR-discussion content, not docstring content.
|
Pushed `48ddb3a` addressing the inline comments:
|
Fix #232 Adds a new illustration module with the IllustrationInfo value object, and new width/height/scale-aware illustration APIs: - writer.Creator.add_illustration(content, width, height=None, scale=1.0) and add_illustration_info(content, info) for full control (e.g. extra attributes), mirroring libzim's own IllustrationInfo-based overload - reader.Archive.get_illustration_item(width=None, height=None, scale=None) and get_illustration_item_info(info), with the same shortcut/mirror split - reader.Archive.get_illustrations_info(width=None, height=None, min_scale=None) to discover available illustrations IllustrationInfo is an immutable namedtuple-based value object: width/height/scale/extra_attributes are read-only, extra_attributes is defensively copied into an immutable mapping on construction, and changing a value means building a new instance (e.g. via `._replace()`). as_metadata_item_name/from_metadata_item_name bridge to libzim's own C++ implementation for correctness.
48ddb3a to
de9032f
Compare
Fix #232
Fix #272
To be merged after #234 (which is simpler / narrower scope)
Changes:
illustrationmodule with theIllustrationInfoclass, used byreaderandwritermodulesreader.Archive.get_illustration_item: get "default" and get specific sizes/scalesreader.Archive.get_illustrations_infoswriter.Creator.add_illustration: pass detailed illustration infos instead of one fixed size