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
73 changes: 73 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: release
on:
release:
types: [published]
tags:
- 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_INCLUDE_PATH: include/zim
CYTHON_VERSION: 0.29.6

jobs:
release:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
# TODO: expand this to cross-platform builds (see V2 approach below)
# os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Cache libzim dylib & headers
uses: actions/cache@master
id: cache-libzim
with:
path: libzim_linux
key: ${{ env.LIBZIM_RELEASE }}-libzim-cache

- name: Download libzim dylib & headers from OpenZIM.org releases
if: steps.cache-libzim.outputs.cache-hit != 'true'
run: |
wget -q https://download.openzim.org/release/libzim/$LIBZIM_RELEASE.tar.gz
tar --gunzip --extract --file=$LIBZIM_RELEASE.tar.gz
mv $LIBZIM_RELEASE libzim_linux

- 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
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

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

- 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/
88 changes: 88 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: test
on: [push]

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

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v1
with:
python-version: 3.6
architecture: x64

- name: Autoformat with black
run: |
pip install black
black --check --exclude=setup.py .

- name: Lint with flake8
run: |
pip install flake8
# one pass for show-stopper syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --exclude=setup.py --show-source --statistics
# one pass for small stylistic things
flake8 . --count --exclude=setup.py --max-line-length=$MAX_LINE_LENGTH --statistics

test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
# TODO: expand this once macos and windows libzim releases become available
# os: [ubuntu-latest, windows-latest, macos-latest]
# alternatively we can compile libzim in docker and use the container as an action
python: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
architecture: x64

- name: Cache libzim dylib & headers
uses: actions/cache@master
id: cache-libzim
with:
path: libzim_linux
key: ${{ env.LIBZIM_RELEASE }}-libzim-cache

- name: Download libzim dylib & headers from OpenZIM.org releases
if: steps.cache-libzim.outputs.cache-hit != 'true'
run: |
wget -q https://download.openzim.org/release/libzim/$LIBZIM_RELEASE.tar.gz
tar --gunzip --extract --file=$LIBZIM_RELEASE.tar.gz
mv $LIBZIM_RELEASE libzim_linux

- 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
ln -s $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_INCLUDE_PATH include/zim

- name: Build cython, sdist, and bdist_wheel
run: |
pip install --upgrade cython==$CYTHON_VERSION setuptools pip wheel
python3 setup.py build_ext
python3 setup.py sdist bdist_wheel

- name: Test built package with pytest
run: |
export LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH
sudo ldconfig
pip install pytest
pip install -e .
pytest .
22 changes: 20 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# General cruft
.DS_Store
.venv
.venv-docker
.mypy_cache
__pycache__
build
*.pyc
.tox

# Compiled binaries and package builds
*.so
build/
dist/
*.egg-info/

# Dylibs and headers
lib/*
include/*
libzim_linux-*/

# Autogenerated files
libzim_wrapper.*.so
libzim/libzim_wrapper.cpp
libzim/libzim_wrapper.h
libzim/libzim_wrapper_api.h
*.egg-info
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include LICENSE
include README.md
include tests/*.py
include pyproject.toml

recursive-include lib *
recursive-include include *
recursive-include libzim *
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"
cython = "==0.29.6"
e1839a8 = {editable = true, path = "."}

[packages]
File renamed without changes.
1 change: 1 addition & 0 deletions include/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Put your zim/*.h folder in here.
1 change: 1 addition & 0 deletions lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Put your libzim.so file in here.
2 changes: 2 additions & 0 deletions libzim/reader.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# flake8: noqa

from libzim_wrapper import File
from libzim_wrapper import ReadArticle as Article
11 changes: 6 additions & 5 deletions libzim/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def get_data(self):
]


def pascalize(keyword):
""" Converts python case to pascal case. example: long_description-> LongDescription """
return "".join(keyword.title().split("_"))


class Creator:
"""
A class to represent a Zim Creator.
Expand All @@ -132,9 +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 = libzim_wrapper.Creator(filename, main_page, index_language, min_chunk_size)
self.filename = filename
self.main_page = main_page
self.language = index_language
Expand Down Expand Up @@ -164,8 +167,6 @@ def mandatory_metadata_ok(self):

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

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
requires = [ "setuptools >= 35.0.2", "wheel >= 0.29.0", "twine", "cython == 0.29.6" ]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 110
target-version = ['py36', 'py37', 'py38']
Loading