Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/Tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ jobs:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

test-reader-only:
runs-on: ubuntu-26.04
env:
LIBZIM_WITHOUT_WRITER: "1"

steps:
- uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.14"

- name: Display Python version
run: python -VV

- name: Install dependencies (and project)
run: |
pip install -U pip
pip install -e .[test,scripts]

- name: Run the tests
run: inv coverage --args "-vvv"

build-docs: # validate that doc can be built
runs-on: ubuntu-26.04

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Free-threaded CPython is supported: the extension declares itself free-threading

Users on other platforms can install the source distribution (see [Building](#Building) below).

Writer support is decided when the extension is built, not when it is installed: there is no install-time extra for it. Set `LIBZIM_WITHOUT_WRITER=1` when building against a libzim compiled without writer support; such a build exposes the reader, search, suggestion, illustration and version modules only. Import `libzim.writer` in a `try`/`except ImportError` block to detect writer support at runtime.


## Contributions

Expand Down
10 changes: 8 additions & 2 deletions libzim/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ from libzim import (
search, # pyright: ignore[reportUnusedImport]
suggestion, # pyright: ignore[reportUnusedImport]
version, # pyright: ignore[reportUnusedImport]
writer, # pyright: ignore[reportUnusedImport]
)

__all__ = ["illustration", "reader", "search", "suggestion", "version", "writer"]
__all__ = ["illustration", "reader", "search", "suggestion", "version"]

try:
from libzim import writer as writer

__all__.append("writer")
except ImportError:
pass
7 changes: 7 additions & 0 deletions libzim/libwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
#include <cstdlib>
#include <iostream>
#include <zim/blob.h>
#include <zim/zim_config.h>
#ifndef LIBZIM_WITHOUT_WRITER
#include <zim/writer/creator.h>
#endif


ObjWrapper::ObjWrapper(PyObject* obj)
Expand Down Expand Up @@ -96,6 +99,7 @@ zim::Blob _callMethodOnObj(PyObject *obj, const std::string& methodName, std::st
return blob_cy_call_fct(obj, methodName, &error);
}

#ifndef LIBZIM_WITHOUT_WRITER
template<>
std::unique_ptr<zim::writer::ContentProvider>
_callMethodOnObj(PyObject *obj, const std::string& methodName, std::string& error) {
Expand All @@ -119,6 +123,7 @@ zim::writer::IndexData::GeoPosition
_callMethodOnObj(PyObject *obj, const std::string& methodName, std::string& error) {
return geoposition_cy_call_fct(obj, methodName, &error);
}
#endif // LIBZIM_WITHOUT_WRITER

// This cpp function call a python method on a python object.
// It checks that we are in a valid state and handle any potential error coming from python.
Expand All @@ -136,6 +141,7 @@ Output callMethodOnObj(PyObject* obj, const std::string& methodName) {
}


#ifndef LIBZIM_WITHOUT_WRITER
/*
################################
# Content Provider Wrapper #
Expand Down Expand Up @@ -238,6 +244,7 @@ zim::writer::Hints WriterItemWrapper::getHints() const
{
return callMethodOnObj<zim::writer::Hints>(m_obj, "get_hints");
}
#endif // LIBZIM_WITHOUT_WRITER

zim::Compression comp_from_int(int compValue)
{
Expand Down
10 changes: 8 additions & 2 deletions libzim/libwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
#include <zim/entry.h>
#include <zim/item.h>
#include <zim/illustration.h>
#include <zim/writer/item.h>
#include <zim/writer/contentProvider.h>
#include <zim/search.h>
#include <zim/suggestion.h>
#include <zim/zim_config.h>

#ifndef LIBZIM_WITHOUT_WRITER
#include <zim/writer/item.h>
#include <zim/writer/contentProvider.h>
#endif

struct _object;
typedef _object PyObject;
Expand Down Expand Up @@ -313,6 +317,7 @@ class ObjWrapper
PyObject* m_obj;
};

#ifndef LIBZIM_WITHOUT_WRITER
class WriterItemWrapper : public zim::writer::Item, private ObjWrapper
{
public:
Expand Down Expand Up @@ -347,6 +352,7 @@ class IndexDataWrapper: public zim::writer::IndexData, private ObjWrapper
uint32_t getWordCount() const override;
IndexData::GeoPosition getGeoPosition() const override;
};
#endif // LIBZIM_WITHOUT_WRITER


// Small helpers
Expand Down
Loading
Loading