Skip to content
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

Add support for Hints in python-libzim #115

Merged
merged 4 commits into from
Aug 27, 2021
Merged

Add support for Hints in python-libzim #115

merged 4 commits into from
Aug 27, 2021

Conversation

mgautierfr
Copy link
Collaborator

@mgautierfr mgautierfr commented Aug 3, 2021

Fixes #93

This PR is not fully tested, no check that created zim are correct.
The error handling is not perfect. No handling of :

  • get_hints returning something else than a dict.
  • get_hints returning a dict where the key is something else that a Hints.
  • ....

@codecov
Copy link

codecov bot commented Aug 3, 2021

Codecov Report

Merging #115 (38e2114) into update-libzim (787c9ed) will decrease coverage by 0.82%.
The diff coverage is 100.00%.

❗ Current head 38e2114 differs from pull request most recent head 5a0b305. Consider uploading reports for the commit 5a0b305 to get more accurate results
Impacted file tree graph

@@                Coverage Diff                @@
##           update-libzim     #115      +/-   ##
=================================================
- Coverage          97.94%   97.11%   -0.83%     
=================================================
  Files                  3        3              
  Lines                292      312      +20     
=================================================
+ Hits                 286      303      +17     
- Misses                 6        9       +3     
Impacted Files Coverage Δ
libzim/wrapper.pyx 96.17% <100.00%> (-1.08%) ⬇️
libzim/writer.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 787c9ed...5a0b305. Read the comment docs.

@kelson42
Copy link
Contributor

kelson42 commented Aug 3, 2021

@mgautierfr Does that fix openzim/libzim#590 as well?

@mgautierfr
Copy link
Collaborator Author

@mgautierfr Does that fix openzim/libzim#590 as well?

Not entirely. It allow sotoki to be updated to pass the correct hints to libzim (which will fix the issue)

@kelson42
Copy link
Contributor

kelson42 commented Aug 4, 2021

@mgautierfr hmmm... then it is not clear what is left to do to close the libzim bug.

@mgautierfr
Copy link
Collaborator Author

There is no libzim bug. Only a wrong usage of it. we must update its user (python-libzim and sotoki) to correctly use it.

I've made half of the work here and @rgaudin seems to have made the other half as he has generated zim file with correct article listing (kiwix/kiwix-js#708 (comment))

What we need to do is stabilize this API, be more resilient to errors and maybe add some tests (This PR already update tests to pass hints, but do not test more)

@rgaudin
Copy link
Member

rgaudin commented Aug 4, 2021

There is no libzim bug. Only a wrong usage of it. we must update its user (python-libzim and sotoki) to correctly use it.

I've made half of the work here and @rgaudin seems to have made the other half as he has generated zim file with correct article listing (kiwix/kiwix-js#708 (comment))

What we need to do is stabilize this API, be more resilient to errors and maybe add some tests (This PR already update tests to pass hints, but do not test more)

I'm on it

Copy link
Member

@rgaudin rgaudin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me. Used it with sotoki.

Added tests in 6528b53. @mgautierfr please check whether you are fine with this approach or not

@rgaudin rgaudin marked this pull request as ready for review August 4, 2021 15:31
Copy link
Collaborator Author

@mgautierfr mgautierfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments on the tests.
(I cannot approve or request changes on the PR as I'm the one who open it)

tests/test_libzim_creator.py Outdated Show resolved Hide resolved
tests/test_libzim_creator.py Show resolved Hide resolved
mgautierfr and others added 2 commits August 20, 2021 15:03
This is a pretty simple implementation.
Following commits will correctly test the feature and adapt a bit the
API.
Failsafe approach to Hints usage: only fail on missing or non-dict-like values.
Assume, `hints=` can be whatever and
 - only cherry-pick our expected Hint from there
 - cast any value to bool

While this drifts a bit appart the zero-logic approach of the wrapper, it's a common
pythonic approach for this kind of things.
Main reason for this is that filtering and casting in Python allows exception to
go up the stack while in-cpp casting does not and ends up ignored.

Now testing:
 - Item without `get_hints()`
 - writer.Item without `get_hints()` impl.
 - `get_hints()` returning a non-dict value
 - `get_hints()` returning unexpected hints (filtered)
 - hints on redirection
@mgautierfr
Copy link
Collaborator Author

(The push-force only rewrite my commit message to remove the WIP)

@rgaudin
Copy link
Member

rgaudin commented Aug 22, 2021

@mgautierfr it seems the tests now fail as we are expecting a Runtime Error exception when adding content to a non-started Creator but we segfault instead. It was not the case earlier so that may have to do with your edits…

Those tests are in test_libzim_creator.py at test_creator_additem(), test_creator_metadata() and test_creator_redirection(). Additionaly, test_creator_badfilename() segfaults as well. Looks like the same issue.

It seems to not fail on github actions (failing ones are reader-related) but it does locally here.

@rgaudin
Copy link
Member

rgaudin commented Aug 27, 2021

Apparently due to openzim/libzim#613

@rgaudin
Copy link
Member

rgaudin commented Aug 27, 2021

Apparently due to openzim/libzim#613

I think it wasn't failing on github because it used a nightly from the 22nd and the fix was merged-in on the 20th. makes sense

Also Added native int as Hint test (filtered)
    One may think that it would be valid to pass a dict with
    an int as key that matches the Hints in libzim's item.h.
    Those are filtered in pylibzim as not recognized as Hint objects.
 Also Removing duplicate test
@rgaudin
Copy link
Member

rgaudin commented Aug 27, 2021

Rebased the commits ; I'm happy with the state of this. Failing tests are reader-based and regards updates to the test ZIM on libkiwix and would be adressed when fixing the reader I believe.

–> merging.

@rgaudin rgaudin merged commit b7fafda into update-libzim Aug 27, 2021
@rgaudin rgaudin deleted the hint branch August 27, 2021 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support getHints
3 participants