Skip to content

Split python-libzim between reader and writer parts - #292

Open
pawank925 wants to merge 1 commit into
openzim:mainfrom
pawank925:split-writer-reader-final
Open

pawank925 wants to merge 1 commit into
openzim:mainfrom
pawank925:split-writer-reader-final

Conversation

@pawank925

Copy link
Copy Markdown
Contributor

Split writer/reader parts to support libzim built without writer (e.g. Android/reader-only builds).

Fixes #287

@pawank925
pawank925 marked this pull request as draft October 28, 2026 02:53
@pawank925
pawank925 marked this pull request as ready for review October 28, 2026 03:01
@pawank925
pawank925 marked this pull request as draft October 28, 2026 03:03
@pawank925
pawank925 force-pushed the split-writer-reader-final branch 3 times, most recently from 7e3bf7b to 3cce80a Compare October 28, 2026 09:47
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.51282% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.28%. Comparing base (f3ed793) to head (1f37944).

Files with missing lines Patch % Lines
libzim/libzim.pyx 95.51% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #292      +/-   ##
==========================================
+ Coverage   93.70%   95.28%   +1.58%     
==========================================
  Files           1        1              
  Lines         635      636       +1     
==========================================
+ Hits          595      606      +11     
+ Misses         40       30      -10     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pawank925

pawank925 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey @benoit74 — a design question on the approach for #287 before this goes further.

#287 floated a pip writer extra: reader-only core by default, writer bits via libzim[writer], plus a way to mark the extra unavailable on some platforms. This PR instead does compile-time detection:

  • setup.py detects at build time whether the linked libzim was built without writer support (LIBZIM_WITHOUT_WRITER in zim_config.h, falling back to the presence of zim/writer/creator.h).
  • When detected, it passes LIBZIM_WITHOUT_WRITER to Cython (compile_time_env) and to the C++ wrappers (-D), so writer-only wrappers/callbacks are not compiled at all.
  • The libzim.writer submodule is only registered when writer support is present, so import libzim.writer raises ImportError on reader-only builds (tests skip via a HAS_WRITER probe).

Rationale: one wheel keeps working against both kinds of libzim, and there is no extra whose availability has to be modeled per platform. Does this satisfy what you need for #283, or would you prefer the writer extra packaging route from #287?

@pawank925
pawank925 force-pushed the split-writer-reader-final branch from 3a13b29 to 3803f8c Compare October 28, 2026 14:21
@pawank925
pawank925 marked this pull request as ready for review October 28, 2026 14:23
Cython cannot conditionally parse `cdef extern` blocks, so declare the
writer API through a local shim header that only includes libzim's writer
headers when the library was built with writer support. Guard the writer
implementations (C++ wrappers, writer callbacks, Hint, Creator and the
libzim.writer registration) with LIBZIM_WITHOUT_WRITER, and detect that
build flag in setup.py once libzim is available.

On a writer-less libzim the extension now builds and `import libzim.writer`
raises ImportError, which is what Android/reader-only wheels need (openzim#283).
Adds tests for lazy submodule loading and creator guards.

Fixes openzim#287
@pawank925
pawank925 force-pushed the split-writer-reader-final branch from 3803f8c to 1f37944 Compare October 28, 2026 14:27

This branch has not been deployed

No deployments
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.

Split python-libzim between reader and writer parts

1 participant