Skip to content

Commit 16e7902

Browse files
authored
Merge pull request #28 from openzim/setup
2 parents 754bc7a + 52678a3 commit 16e7902

File tree

9 files changed

+86
-98
lines changed

9 files changed

+86
-98
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ on:
66
- v*
77

88
env:
9-
LIBZIM_RELEASE: libzim_linux-x86_64-6.1.1
10-
LIBZIM_LIBRARY_PATH: lib/x86_64-linux-gnu/libzim.so.6.1.1
9+
LIBZIM_RELEASE: libzim_linux-x86_64-6.1.5
1110
LIBZIM_INCLUDE_PATH: include/zim
1211
CYTHON_VERSION: 0.29.6
1312

@@ -46,28 +45,29 @@ jobs:
4645
4746
- name: Link libzim dylib & headers into workspace lib and include folders
4847
run: |
49-
cp -p $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH lib/libzim.so
50-
cp -p $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH lib/
51-
sudo ldconfig $GITHUB_WORKSPACE/lib
48+
cp -dp $GITHUB_WORKSPACE/libzim_linux/lib/x86_64-linux-gnu/* lib/
49+
ln -s libzim.so.6 lib/libzim.so
5250
ln -s $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_INCLUDE_PATH include/zim
5351
5452
- name: Build cython, sdist, and bdist_wheels
5553
run: |
56-
pip install --upgrade cython==$CYTHON_VERSION setuptools pip
57-
python3 setup.py build_ext
58-
python3 setup.py sdist bdist_wheel
59-
python -m cibuildwheel --output-dir wheelhouse
54+
pip install --upgrade cython==$CYTHON_VERSION setuptools pip wheel
55+
python3 setup.py build_ext --rpath='$ORIGIN'
56+
if [[ "${{ matrix.python-version }}" == "3.6" ]]
57+
then
58+
python3 setup.py sdist
59+
fi
60+
cp -p lib/libzim.so.6 libzim
61+
python3 setup.py bdist_wheel --plat-name=manylinux1_x86_64
6062
6163
- uses: actions/upload-artifact@v1
6264
with:
6365
name: wheels
64-
path: ./wheelhouse
66+
path: ./dist
6567

6668
- name: Push release to PyPI
6769
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
6870
uses: pypa/gh-action-pypi-publish@master
6971
with:
7072
user: __token__
7173
password: ${{ secrets.PYPI_API_TOKEN }}
72-
# TODO: remove this line to upload to the real PyPI when ready
73-
repository_url: https://test.pypi.org/legacy/

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ include/*
1919
libzim_linux-*/
2020

2121
# Autogenerated files
22-
libzim_wrapper.*.so
23-
libzim/libzim_wrapper.cpp
24-
libzim/libzim_wrapper.h
25-
libzim/libzim_wrapper_api.h
22+
wrapper.*.so
23+
libzim/wrapper.cpp
24+
libzim/wrapper.h
25+
libzim/wrapper_api.h

MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ include README.md
33
include tests/*.py
44
include pyproject.toml
55

6-
recursive-include lib *
7-
recursive-include include *
86
recursive-include libzim *
7+
global-exclude __pycache__/*
8+
exclude *.egg-info/*

libzim/lib.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <Python.h>
2424
#include "lib.h"
2525

26-
#include "libzim_wrapper_api.h"
26+
#include "wrapper_api.h"
2727

2828
#include <iostream>
2929
#include <zim/writer/url.h>
@@ -38,7 +38,7 @@
3838

3939
ZimArticleWrapper::ZimArticleWrapper(PyObject *obj) : m_obj(obj)
4040
{
41-
if (import_libzim_wrapper())
41+
if (import_libzim__wrapper())
4242
{
4343
std::cerr << "Error executing import_libzim!\n";
4444
throw std::runtime_error("Error executing import_libzim");

libzim/reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# flake8: noqa
22

3-
from libzim_wrapper import File
4-
from libzim_wrapper import ReadArticle as Article
3+
from .wrapper import FilePy as File
4+
from .wrapper import ReadArticle as Article
File renamed without changes.

libzim/libzim_wrapper.pyx renamed to libzim/wrapper.pyx

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919

2020

21-
cimport libzim.libzim_wrapper as clibzim
21+
cimport libzim.wrapper as wrapper
2222

2323
from cython.operator import dereference, preincrement
2424
from cpython.ref cimport PyObject
@@ -36,15 +36,15 @@ import datetime
3636
#########################
3737

3838
cdef class WritingBlob:
39-
cdef clibzim.Blob* c_blob
39+
cdef wrapper.Blob* c_blob
4040
cdef bytes ref_content
4141

4242
def __cinit__(self, content):
4343
if isinstance(content, str):
4444
self.ref_content = content.encode('UTF-8')
4545
else:
4646
self.ref_content = content
47-
self.c_blob = new clibzim.Blob(<char *> self.ref_content, len(self.ref_content))
47+
self.c_blob = new wrapper.Blob(<char *> self.ref_content, len(self.ref_content))
4848

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

5555
cdef class ReadingBlob:
56-
cdef clibzim.Blob c_blob
56+
cdef wrapper.Blob c_blob
5757
cdef Py_ssize_t size
5858
cdef int view_count
5959

60-
cdef __setup(self, clibzim.Blob blob):
60+
cdef __setup(self, wrapper.Blob blob):
6161
"""Assigns an internal pointer to the wrapped C++ article object.
6262
6363
Parameters
@@ -116,7 +116,7 @@ cdef public api:
116116
ret_str = func()
117117
return ret_str.encode('UTF-8')
118118

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

@@ -146,7 +146,7 @@ cdef class Creator:
146146
flag if the creator was finalized
147147
"""
148148

149-
cdef clibzim.ZimCreatorWrapper *c_creator
149+
cdef wrapper.ZimCreatorWrapper *c_creator
150150
cdef bool _finalized
151151

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

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

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

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

@@ -239,7 +239,7 @@ cdef class ReadArticle:
239239
from_read_article(zim.Article art)
240240
Creates a python ZimArticle from a C++ zim.Article article.
241241
"""
242-
cdef clibzim.Article c_article
242+
cdef wrapper.Article c_article
243243
cdef ReadingBlob _blob
244244
cdef bool _haveBlob
245245

@@ -251,7 +251,7 @@ cdef class ReadArticle:
251251
def __cinit__(self):
252252
self._haveBlob = False
253253

254-
cdef __setup(self, clibzim.Article art):
254+
cdef __setup(self, wrapper.Article art):
255255
"""Assigns an internal pointer to the wrapped C++ article object.
256256
257257
Parameters
@@ -267,7 +267,7 @@ cdef class ReadArticle:
267267

268268
# Factory functions - Currently Cython can't use classmethods
269269
@staticmethod
270-
cdef from_read_article(clibzim.Article art):
270+
cdef from_read_article(wrapper.Article art):
271271
"""Creates a python ZimFileArticle from a C++ Article (zim::).
272272
273273
Parameters
@@ -332,7 +332,7 @@ cdef class ReadArticle:
332332
# File #
333333
#########################
334334

335-
cdef class File:
335+
cdef class FilePy:
336336
"""
337337
A class to represent a Zim File Reader.
338338
@@ -344,7 +344,7 @@ cdef class File:
344344
the file name of the File Reader object
345345
"""
346346

347-
cdef clibzim.File *c_file
347+
cdef wrapper.File *c_file
348348
cdef object _filename
349349

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

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

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

@@ -419,7 +419,7 @@ cdef class File:
419419
"""
420420

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

@@ -435,8 +435,8 @@ cdef class File:
435435
The url of the main page
436436
TODO Check old formats
437437
"""
438-
cdef clibzim.Fileheader header = self.c_file.getFileheader()
439-
cdef clibzim.Article article
438+
cdef wrapper.Fileheader header = self.c_file.getFileheader()
439+
cdef wrapper.Article article
440440
if header.hasMainPage():
441441
article = self.c_file.getArticle(header.getMainPage())
442442
return article.getLongUrl().decode("UTF-8", "strict");
@@ -504,8 +504,8 @@ cdef class File:
504504
iterator
505505
An interator with the urls of suggested articles starting from start position
506506
"""
507-
cdef unique_ptr[clibzim.Search] search = self.c_file.suggestions(query.encode('UTF-8'),start, end)
508-
cdef clibzim.search_iterator it = dereference(search).begin()
507+
cdef unique_ptr[wrapper.Search] search = self.c_file.suggestions(query.encode('UTF-8'),start, end)
508+
cdef wrapper.search_iterator it = dereference(search).begin()
509509

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

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

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

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

565565
def __repr__(self):

libzim/writer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import datetime
2222
from collections import defaultdict
2323

24-
import libzim_wrapper
25-
from libzim_wrapper import WritingBlob as Blob
24+
from .wrapper import Creator as _Creator
25+
from .wrapper import WritingBlob as Blob
2626

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

@@ -137,7 +137,7 @@ class Creator:
137137

138138
def __init__(self, filename, main_page, index_language, min_chunk_size):
139139
print(filename)
140-
self._creatorWrapper = libzim_wrapper.Creator(filename, main_page, index_language, min_chunk_size)
140+
self._creatorWrapper = _Creator(filename, main_page, index_language, min_chunk_size)
141141
self.filename = filename
142142
self.main_page = main_page
143143
self.language = index_language

0 commit comments

Comments
 (0)