Skip to content
Merged
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: 12 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ on:
- v*

env:
LIBZIM_RELEASE: libzim_linux-x86_64-6.1.1
LIBZIM_LIBRARY_PATH: lib/x86_64-linux-gnu/libzim.so.6.1.1
LIBZIM_RELEASE: libzim_linux-x86_64-6.1.5
LIBZIM_INCLUDE_PATH: include/zim
CYTHON_VERSION: 0.29.6

Expand Down Expand Up @@ -46,28 +45,29 @@ jobs:

- name: Link libzim dylib & headers into workspace lib and include folders
run: |
cp -p $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH lib/libzim.so
cp -p $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH lib/
sudo ldconfig $GITHUB_WORKSPACE/lib
cp -dp $GITHUB_WORKSPACE/libzim_linux/lib/x86_64-linux-gnu/* lib/
ln -s libzim.so.6 lib/libzim.so
ln -s $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_INCLUDE_PATH include/zim

- name: Build cython, sdist, and bdist_wheels
run: |
pip install --upgrade cython==$CYTHON_VERSION setuptools pip
python3 setup.py build_ext
python3 setup.py sdist bdist_wheel
python -m cibuildwheel --output-dir wheelhouse
pip install --upgrade cython==$CYTHON_VERSION setuptools pip wheel
python3 setup.py build_ext --rpath='$ORIGIN'
if [[ "${{ matrix.python-version }}" == "3.6" ]]
then
python3 setup.py sdist
fi
cp -p lib/libzim.so.6 libzim
python3 setup.py bdist_wheel --plat-name=manylinux1_x86_64

- uses: actions/upload-artifact@v1
with:
name: wheels
path: ./wheelhouse
path: ./dist

- name: Push release to PyPI
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
# TODO: remove this line to upload to the real PyPI when ready
repository_url: https://test.pypi.org/legacy/
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include/*
libzim_linux-*/

# Autogenerated files
libzim_wrapper.*.so
libzim/libzim_wrapper.cpp
libzim/libzim_wrapper.h
libzim/libzim_wrapper_api.h
wrapper.*.so
libzim/wrapper.cpp
libzim/wrapper.h
libzim/wrapper_api.h
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ include README.md
include tests/*.py
include pyproject.toml

recursive-include lib *
recursive-include include *
recursive-include libzim *
global-exclude __pycache__/*
exclude *.egg-info/*
4 changes: 2 additions & 2 deletions libzim/lib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <Python.h>
#include "lib.h"

#include "libzim_wrapper_api.h"
#include "wrapper_api.h"

#include <iostream>
#include <zim/writer/url.h>
Expand All @@ -38,7 +38,7 @@

ZimArticleWrapper::ZimArticleWrapper(PyObject *obj) : m_obj(obj)
{
if (import_libzim_wrapper())
if (import_libzim__wrapper())
{
std::cerr << "Error executing import_libzim!\n";
throw std::runtime_error("Error executing import_libzim");
Expand Down
4 changes: 2 additions & 2 deletions libzim/reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flake8: noqa

from libzim_wrapper import File
from libzim_wrapper import ReadArticle as Article
from .wrapper import FilePy as File
from .wrapper import ReadArticle as Article
File renamed without changes.
52 changes: 26 additions & 26 deletions libzim/libzim_wrapper.pyx → libzim/wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.


cimport libzim.libzim_wrapper as clibzim
cimport libzim.wrapper as wrapper

from cython.operator import dereference, preincrement
from cpython.ref cimport PyObject
Expand All @@ -36,15 +36,15 @@ import datetime
#########################

cdef class WritingBlob:
cdef clibzim.Blob* c_blob
cdef wrapper.Blob* c_blob
cdef bytes ref_content

def __cinit__(self, content):
if isinstance(content, str):
self.ref_content = content.encode('UTF-8')
else:
self.ref_content = content
self.c_blob = new clibzim.Blob(<char *> self.ref_content, len(self.ref_content))
self.c_blob = new wrapper.Blob(<char *> self.ref_content, len(self.ref_content))

def __dealloc__(self):
if self.c_blob != NULL:
Expand All @@ -53,11 +53,11 @@ cdef class WritingBlob:
cdef Py_ssize_t itemsize = 1

cdef class ReadingBlob:
cdef clibzim.Blob c_blob
cdef wrapper.Blob c_blob
cdef Py_ssize_t size
cdef int view_count

cdef __setup(self, clibzim.Blob blob):
cdef __setup(self, wrapper.Blob blob):
"""Assigns an internal pointer to the wrapped C++ article object.

Parameters
Expand Down Expand Up @@ -116,7 +116,7 @@ cdef public api:
ret_str = func()
return ret_str.encode('UTF-8')

clibzim.Blob blob_cy_call_fct(object obj, string method, int *error) with gil:
wrapper.Blob blob_cy_call_fct(object obj, string method, int *error) with gil:
"""Lookup and execute a pure virtual method on ZimArticle returning a Blob"""
cdef WritingBlob blob

Expand Down Expand Up @@ -146,7 +146,7 @@ cdef class Creator:
flag if the creator was finalized
"""

cdef clibzim.ZimCreatorWrapper *c_creator
cdef wrapper.ZimCreatorWrapper *c_creator
cdef bool _finalized

def __cinit__(self, str filename, str main_page = "", str index_language = "eng", min_chunk_size = 2048):
Expand All @@ -163,7 +163,7 @@ cdef class Creator:
Minimum chunk size (default 2048)
"""

self.c_creator = clibzim.ZimCreatorWrapper.create(filename.encode("UTF-8"), main_page.encode("UTF-8"), index_language.encode("UTF-8"), min_chunk_size)
self.c_creator = wrapper.ZimCreatorWrapper.create(filename.encode("UTF-8"), main_page.encode("UTF-8"), index_language.encode("UTF-8"), min_chunk_size)
self._finalized = False

def __dealloc__(self):
Expand All @@ -185,8 +185,8 @@ cdef class Creator:
raise RuntimeError("ZimCreator already finalized")

# Make a shared pointer to ZimArticleWrapper from the ZimArticle object
cdef shared_ptr[clibzim.ZimArticleWrapper] art = shared_ptr[clibzim.ZimArticleWrapper](
new clibzim.ZimArticleWrapper(<PyObject*>article));
cdef shared_ptr[wrapper.ZimArticleWrapper] art = shared_ptr[wrapper.ZimArticleWrapper](
new wrapper.ZimArticleWrapper(<PyObject*>article));
with nogil:
self.c_creator.addArticle(art)

Expand Down Expand Up @@ -239,7 +239,7 @@ cdef class ReadArticle:
from_read_article(zim.Article art)
Creates a python ZimArticle from a C++ zim.Article article.
"""
cdef clibzim.Article c_article
cdef wrapper.Article c_article
cdef ReadingBlob _blob
cdef bool _haveBlob

Expand All @@ -251,7 +251,7 @@ cdef class ReadArticle:
def __cinit__(self):
self._haveBlob = False

cdef __setup(self, clibzim.Article art):
cdef __setup(self, wrapper.Article art):
"""Assigns an internal pointer to the wrapped C++ article object.

Parameters
Expand All @@ -267,7 +267,7 @@ cdef class ReadArticle:

# Factory functions - Currently Cython can't use classmethods
@staticmethod
cdef from_read_article(clibzim.Article art):
cdef from_read_article(wrapper.Article art):
"""Creates a python ZimFileArticle from a C++ Article (zim::).

Parameters
Expand Down Expand Up @@ -332,7 +332,7 @@ cdef class ReadArticle:
# File #
#########################

cdef class File:
cdef class FilePy:
"""
A class to represent a Zim File Reader.

Expand All @@ -344,7 +344,7 @@ cdef class File:
the file name of the File Reader object
"""

cdef clibzim.File *c_file
cdef wrapper.File *c_file
cdef object _filename

def __cinit__(self, str filename):
Expand All @@ -355,7 +355,7 @@ cdef class File:
Full path to a zim file
"""

self.c_file = new clibzim.File(filename.encode('UTF-8'))
self.c_file = new wrapper.File(filename.encode('UTF-8'))
self._filename = self.c_file.getFilename().decode("UTF-8", "strict")

def __dealloc__(self):
Expand Down Expand Up @@ -384,7 +384,7 @@ cdef class File:
If an article with the provided long url is not found in the file
"""
# Read to a zim::Article
cdef clibzim.Article art = self.c_file.getArticleByUrl(url.encode('UTF-8'))
cdef wrapper.Article art = self.c_file.getArticleByUrl(url.encode('UTF-8'))
if not art.good():
raise RuntimeError("Article not found for url")

Expand Down Expand Up @@ -419,7 +419,7 @@ cdef class File:
"""

# Read to a zim::Article
cdef clibzim.Article art = self.c_file.getArticle(<int> id)
cdef wrapper.Article art = self.c_file.getArticle(<int> id)
if not art.good():
raise RuntimeError("Article not found for id")

Expand All @@ -435,8 +435,8 @@ cdef class File:
The url of the main page
TODO Check old formats
"""
cdef clibzim.Fileheader header = self.c_file.getFileheader()
cdef clibzim.Article article
cdef wrapper.Fileheader header = self.c_file.getFileheader()
cdef wrapper.Article article
if header.hasMainPage():
article = self.c_file.getArticle(header.getMainPage())
return article.getLongUrl().decode("UTF-8", "strict");
Expand Down Expand Up @@ -504,8 +504,8 @@ cdef class File:
iterator
An interator with the urls of suggested articles starting from start position
"""
cdef unique_ptr[clibzim.Search] search = self.c_file.suggestions(query.encode('UTF-8'),start, end)
cdef clibzim.search_iterator it = dereference(search).begin()
cdef unique_ptr[wrapper.Search] search = self.c_file.suggestions(query.encode('UTF-8'),start, end)
cdef wrapper.search_iterator it = dereference(search).begin()

while it != dereference(search).end():
yield it.get_url().decode('UTF-8')
Expand All @@ -527,8 +527,8 @@ cdef class File:
An iterator with the urls of articles matching the search query starting from start position
"""

cdef unique_ptr[clibzim.Search] search = self.c_file.search(query.encode('UTF-8'),start, end)
cdef clibzim.search_iterator it = dereference(search).begin()
cdef unique_ptr[wrapper.Search] search = self.c_file.search(query.encode('UTF-8'),start, end)
cdef wrapper.search_iterator it = dereference(search).begin()

while it != dereference(search).end():
yield it.get_url().decode('UTF-8')
Expand All @@ -545,7 +545,7 @@ cdef class File:
int
Number of search results
"""
cdef unique_ptr[clibzim.Search] search = self.c_file.search(query.encode('UTF-8'),0, 1)
cdef unique_ptr[wrapper.Search] search = self.c_file.search(query.encode('UTF-8'),0, 1)
return dereference(search).get_matches_estimated()

def get_suggestions_results_count(self, query):
Expand All @@ -559,7 +559,7 @@ cdef class File:
int
Number of article suggestions
"""
cdef unique_ptr[clibzim.Search] search = self.c_file.suggestions(query.encode('UTF-8'),0 , 1)
cdef unique_ptr[wrapper.Search] search = self.c_file.suggestions(query.encode('UTF-8'),0 , 1)
return dereference(search).get_matches_estimated()

def __repr__(self):
Expand Down
6 changes: 3 additions & 3 deletions libzim/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import datetime
from collections import defaultdict

import libzim_wrapper
from libzim_wrapper import WritingBlob as Blob
from .wrapper import Creator as _Creator
from .wrapper import WritingBlob as Blob

__all__ = ["Article", "Blob", "Creator"]

Expand Down Expand Up @@ -137,7 +137,7 @@ class Creator:

def __init__(self, filename, main_page, index_language, min_chunk_size):
print(filename)
self._creatorWrapper = libzim_wrapper.Creator(filename, main_page, index_language, min_chunk_size)
self._creatorWrapper = _Creator(filename, main_page, index_language, min_chunk_size)
self.filename = filename
self.main_page = main_page
self.language = index_language
Expand Down
Loading