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

Introduced Formatter in libzim #862

Merged
merged 2 commits into from
Mar 20, 2024
Merged

Introduced Formatter in libzim #862

merged 2 commits into from
Mar 20, 2024

Conversation

ShaopengLin
Copy link
Contributor

@ShaopengLin ShaopengLin commented Mar 3, 2024

Hi! I am a GSOC student this year and its my first PR here.

Changes:

Discussion needed:

  • I am not sure if we want the class to be public facing? If no, then the createZimExample.cpp should not be changed. The user would be confused what Formatter is.
  • Classes with their own operator<< defined with std::ostream (e.g. blob.h) and functions that uses more complex features of stringstreams (e.g. class CapturedStderr) in my opinion should not need changes.
    • Making ourselves std::ostream goes against our goal to keep things in a stringstream.
    • Having the same featrues of stringstreams will likely mean inheritance.

Fixes #432

Copy link
Collaborator

@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.

Thanks for the PR.

Few things to change.
I'm in favor of using it in archive.cpp and debug.h too.

src/file_compound.cpp Outdated Show resolved Hide resolved
src/file_reader.cpp Outdated Show resolved Hide resolved
src/writer/creator.cpp Outdated Show resolved Hide resolved
Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 12.17391% with 101 lines in your changes are missing coverage. Please review.

Project coverage is 58.04%. Comparing base (f624344) to head (c234ff2).

Files Patch % Lines
src/file_reader.cpp 0.00% 36 Missing and 1 partial ⚠️
src/writer/creator.cpp 9.09% 4 Missing and 6 partials ⚠️
src/narrowdown.h 0.00% 4 Missing and 5 partials ⚠️
src/writer/cluster.cpp 0.00% 3 Missing and 5 partials ⚠️
src/debug.h 0.00% 6 Missing ⚠️
src/entry.cpp 28.57% 2 Missing and 3 partials ⚠️
src/file_compound.cpp 0.00% 5 Missing ⚠️
src/writer/counterHandler.cpp 0.00% 0 Missing and 4 partials ⚠️
include/zim/error.h 0.00% 0 Missing and 3 partials ⚠️
src/version.cpp 0.00% 3 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #862      +/-   ##
==========================================
+ Coverage   57.73%   58.04%   +0.30%     
==========================================
  Files         100      101       +1     
  Lines        4619     4617       -2     
  Branches     1936     1921      -15     
==========================================
+ Hits         2667     2680      +13     
+ Misses        672      667       -5     
+ Partials     1280     1270      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ShaopengLin
Copy link
Contributor Author

I am a little against using it in test/archive. The CapturedStderr Class is using rdbuf to read the stream buffer which our class is intended to hide. It makes the class too coupled. If we want to replace all uses of (o)stringstream with Formatter, we should be using inheritance instead. When they need specific features of stringstreams I think it is best they just use the original classes.

src/file_reader.cpp Outdated Show resolved Hide resolved
@ShaopengLin ShaopengLin requested a review from mgautierfr March 4, 2024 19:55
@ShaopengLin
Copy link
Contributor Author

Also, I think we should place the class in include/zim/tools.h. After installation, error.h would not be able to use this class.

@ShaopengLin
Copy link
Contributor Author

Resolved most of the comments and moved to zim/tools.h to ensure installation is correct. Likely need another patch depending on the discussion of std::endl vs '\n' and archive.cpp

Copy link
Collaborator

@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.

Still a small change to do about closing ".

I agree with the global code but please rework the commits. Once this PR will be merged, we will not care about the small mistake made during development and fixed during review. We are more interested with a clean git history.

I would suggest 3 commits (but feel free to assume your own pov on this) :

  • Fix closing ".
  • Introduce Formatter.
  • Use formater

src/file_compound.cpp Outdated Show resolved Hide resolved
@ShaopengLin
Copy link
Contributor Author

Fixed the compilation issue with __ostream_type from different platforms. @mgautierfr Can you run the CI again?

@ShaopengLin
Copy link
Contributor Author

ShaopengLin commented Mar 7, 2024

I am new to codecov. I believe I should just add test cases in the test folder that hit those code changes right? This might take a while...

@ShaopengLin
Copy link
Contributor Author

ShaopengLin commented Mar 10, 2024

Should we ignore the codecov atm? So these changes were not part of the covered sections. If we see the sentry report from other PRs, the exact sections are shown as missed. I do not think I have enough knowledge on how to reproduce all these error edge cases. @mgautierfr @kelson42

@mgautierfr
Copy link
Collaborator

Should we ignore the codecov atm?

Yes, the formater is used a lot to generate error message. Difficult to fully test.

Replaced uses of (o)stringstreams in src that does not need stringstream methods. Carry along change adding a missing quotation in file_compound.cpp. Fix openzim#432
@mgautierfr mgautierfr merged commit 8d978e1 into openzim:main Mar 20, 2024
28 of 30 checks passed
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.

Introduce Formatter in libzim.
2 participants