Skip to content

Commit 1ba2808

Browse files
authored
Merge pull request #10 from openzim/pirate-patch-1
2 parents 0df2e22 + ee55969 commit 1ba2808

File tree

14 files changed

+408
-75
lines changed

14 files changed

+408
-75
lines changed

.github/workflows/release.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: release
2+
on:
3+
release:
4+
types: [published]
5+
tags:
6+
- v*
7+
8+
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
11+
LIBZIM_INCLUDE_PATH: include/zim
12+
CYTHON_VERSION: 0.29.6
13+
14+
jobs:
15+
release:
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
matrix:
19+
os: [ubuntu-latest]
20+
# TODO: expand this to cross-platform builds (see V2 approach below)
21+
# os: [ubuntu-latest, windows-latest, macos-latest]
22+
python-version: [3.6, 3.7, 3.8]
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
27+
- name: Set up Python ${{ matrix.python-version }}
28+
uses: actions/setup-python@v1
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
architecture: x64
32+
33+
- name: Cache libzim dylib & headers
34+
uses: actions/cache@master
35+
id: cache-libzim
36+
with:
37+
path: libzim_linux
38+
key: ${{ env.LIBZIM_RELEASE }}-libzim-cache
39+
40+
- name: Download libzim dylib & headers from OpenZIM.org releases
41+
if: steps.cache-libzim.outputs.cache-hit != 'true'
42+
run: |
43+
wget -q https://download.openzim.org/release/libzim/$LIBZIM_RELEASE.tar.gz
44+
tar --gunzip --extract --file=$LIBZIM_RELEASE.tar.gz
45+
mv $LIBZIM_RELEASE libzim_linux
46+
47+
- name: Link libzim dylib & headers into workspace lib and include folders
48+
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
52+
ln -s $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_INCLUDE_PATH include/zim
53+
54+
- name: Build cython, sdist, and bdist_wheels
55+
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
60+
61+
- uses: actions/upload-artifact@v1
62+
with:
63+
name: wheels
64+
path: ./wheelhouse
65+
66+
- name: Push release to PyPI
67+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
68+
uses: pypa/gh-action-pypi-publish@master
69+
with:
70+
user: __token__
71+
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/

.github/workflows/test.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: test
2+
on: [push]
3+
4+
env:
5+
LIBZIM_RELEASE: libzim_linux-x86_64-6.1.1
6+
LIBZIM_LIBRARY_PATH: lib/x86_64-linux-gnu/libzim.so.6.1.1
7+
LIBZIM_INCLUDE_PATH: include/zim
8+
CYTHON_VERSION: 0.29.6
9+
MAX_LINE_LENGTH: 110
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Python ${{ matrix.python }}
18+
uses: actions/setup-python@v1
19+
with:
20+
python-version: 3.6
21+
architecture: x64
22+
23+
- name: Autoformat with black
24+
run: |
25+
pip install black
26+
black --check --exclude=setup.py .
27+
28+
- name: Lint with flake8
29+
run: |
30+
pip install flake8
31+
# one pass for show-stopper syntax errors or undefined names
32+
flake8 . --count --select=E9,F63,F7,F82 --exclude=setup.py --show-source --statistics
33+
# one pass for small stylistic things
34+
flake8 . --count --exclude=setup.py --max-line-length=$MAX_LINE_LENGTH --statistics
35+
36+
test:
37+
runs-on: ${{ matrix.os }}
38+
strategy:
39+
matrix:
40+
os: [ubuntu-latest]
41+
# TODO: expand this once macos and windows libzim releases become available
42+
# os: [ubuntu-latest, windows-latest, macos-latest]
43+
# alternatively we can compile libzim in docker and use the container as an action
44+
python: [3.6, 3.7, 3.8]
45+
46+
steps:
47+
- uses: actions/checkout@v2
48+
49+
- name: Set up Python ${{ matrix.python }}
50+
uses: actions/setup-python@v1
51+
with:
52+
python-version: ${{ matrix.python }}
53+
architecture: x64
54+
55+
- name: Cache libzim dylib & headers
56+
uses: actions/cache@master
57+
id: cache-libzim
58+
with:
59+
path: libzim_linux
60+
key: ${{ env.LIBZIM_RELEASE }}-libzim-cache
61+
62+
- name: Download libzim dylib & headers from OpenZIM.org releases
63+
if: steps.cache-libzim.outputs.cache-hit != 'true'
64+
run: |
65+
wget -q https://download.openzim.org/release/libzim/$LIBZIM_RELEASE.tar.gz
66+
tar --gunzip --extract --file=$LIBZIM_RELEASE.tar.gz
67+
mv $LIBZIM_RELEASE libzim_linux
68+
69+
- name: Link libzim dylib & headers into workspace lib and include folders
70+
run: |
71+
cp -p $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH lib/libzim.so
72+
cp -p $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH lib/
73+
sudo ldconfig $GITHUB_WORKSPACE/lib
74+
ln -s $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_INCLUDE_PATH include/zim
75+
76+
- name: Build cython, sdist, and bdist_wheel
77+
run: |
78+
pip install --upgrade cython==$CYTHON_VERSION setuptools pip wheel
79+
python3 setup.py build_ext
80+
python3 setup.py sdist bdist_wheel
81+
82+
- name: Test built package with pytest
83+
run: |
84+
export LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH
85+
sudo ldconfig
86+
pip install pytest
87+
pip install -e .
88+
pytest .

.gitignore

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
# General cruft
2+
.DS_Store
3+
.venv
4+
.venv-docker
5+
.mypy_cache
16
__pycache__
2-
build
7+
*.pyc
8+
.tox
9+
10+
# Compiled binaries and package builds
11+
*.so
12+
build/
13+
dist/
14+
*.egg-info/
15+
16+
# Dylibs and headers
17+
lib/*
18+
include/*
19+
libzim_linux-*/
20+
21+
# Autogenerated files
322
libzim_wrapper.*.so
423
libzim/libzim_wrapper.cpp
524
libzim/libzim_wrapper.h
625
libzim/libzim_wrapper_api.h
7-
*.egg-info

MANIFEST.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include LICENSE
2+
include README.md
3+
include tests/*.py
4+
include pyproject.toml
5+
6+
recursive-include lib *
7+
recursive-include include *
8+
recursive-include libzim *

Pipfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
pytest = "*"
8+
cython = "==0.29.6"
9+
e1839a8 = {editable = true, path = "."}
10+
11+
[packages]
File renamed without changes.

include/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Put your zim/*.h folder in here.

lib/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Put your libzim.so file in here.

libzim/reader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
# flake8: noqa
2+
13
from libzim_wrapper import File
24
from libzim_wrapper import ReadArticle as Article

libzim/writer.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ def get_data(self):
106106
]
107107

108108

109+
def pascalize(keyword):
110+
""" Converts python case to pascal case. example: long_description-> LongDescription """
111+
return "".join(keyword.title().split("_"))
112+
113+
109114
class Creator:
110115
"""
111116
A class to represent a Zim Creator.
@@ -132,9 +137,7 @@ class Creator:
132137

133138
def __init__(self, filename, main_page, index_language, min_chunk_size):
134139
print(filename)
135-
self._creatorWrapper = libzim_wrapper.Creator(
136-
filename, main_page, index_language, min_chunk_size
137-
)
140+
self._creatorWrapper = libzim_wrapper.Creator(filename, main_page, index_language, min_chunk_size)
138141
self.filename = filename
139142
self.main_page = main_page
140143
self.language = index_language
@@ -164,8 +167,6 @@ def mandatory_metadata_ok(self):
164167

165168
def update_metadata(self, **kwargs):
166169
"Updates article metadata" ""
167-
# Converts python case to pascal case. example: long_description-> LongDescription
168-
pascalize = lambda keyword: "".join(keyword.title().split("_"))
169170
new_metadata = {pascalize(k): v for k, v in kwargs.items()}
170171
self._metadata.update(new_metadata)
171172

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[build-system]
2+
requires = [ "setuptools >= 35.0.2", "wheel >= 0.29.0", "twine", "cython == 0.29.6" ]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.black]
6+
line-length = 110
7+
target-version = ['py36', 'py37', 'py38']

0 commit comments

Comments
 (0)