|
1 |
| -import os |
2 |
| -from distutils.core import setup |
3 |
| -from distutils.extension import Extension |
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +python-libzim (the openzim/libzim bindings for Python) |
| 4 | +
|
| 5 | +The project is compiled in two steps: |
| 6 | +
|
| 7 | + 1. Cython: compile the cython format files (.pyx, .pyd) to C++ (.cpp and .h) |
| 8 | + 2. Cythonize: compile the generated C++ to a python-importable binary extension .so |
| 9 | +
|
| 10 | +The Cython and Cythonize compilation is done automatically during packaging with setup.py: |
| 11 | +
|
| 12 | + $ python3 setup.py build_ext |
| 13 | + $ python3 setup.py sdist bdist_wheel |
| 14 | +
|
| 15 | +
|
| 16 | +To compile or run this project, you must first get the libzim headers & binary: |
| 17 | +
|
| 18 | + - You can get the headers here and build and install the binary from source: |
| 19 | + https://github.com/openzim/libzim |
| 20 | +
|
| 21 | + - Or you can download a full prebuilt release (if one exists for your platform): |
| 22 | + https://download.openzim.org/release/libzim/ |
| 23 | +
|
| 24 | +Either place the `libzim.so` and `zim/*.h` files in `./lib/` and `./include/`, |
| 25 | + or set these environment variables to use custom libzim header and dylib paths: |
| 26 | +
|
| 27 | + $ export CFLAGS="-I/tmp/libzim_linux-x86_64-6.1.1/include" |
| 28 | + $ export LDFLAGS="-L/tmp/libzim_linux-x86_64-6.1.1/lib/x86_64-linux-gnu" |
| 29 | + $ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/tmp/libzim_linux-x86_64-6.1.1/lib/x86_64-linux-gnu" |
| 30 | +""" |
| 31 | +from pathlib import Path |
| 32 | +from ctypes.util import find_library |
| 33 | + |
| 34 | +from setuptools import setup, Extension |
4 | 35 | from Cython.Build import cythonize
|
5 | 36 |
|
6 |
| -# Utility function to read the README file. |
7 |
| -# Used for the long_description. It's nice, because now 1) we have a top levegit checkout masterl |
8 |
| -# README file and 2) it's easier to type in the README file than to put a raw |
9 |
| -# string in below ... |
10 |
| -def read(fname): |
11 |
| - return open(os.path.join(os.path.dirname(__file__), fname)).read() |
| 37 | + |
| 38 | +PACKAGE_NAME = "libzim_wrapper" |
| 39 | +VERSION = "0.0.1" # pegged to be the same version as libzim since they are always released together |
| 40 | +LICENSE = "GPLv3+" |
| 41 | +DESCRIPTION = "A python-facing API for creating and interacting with ZIM files" |
| 42 | +AUTHOR = "Monadical Inc." |
| 43 | +AUTHOR_EMAIL = "[email protected]" |
| 44 | +GITHUB_URL = "https://github.com/openzim/python-libzim" |
| 45 | + |
| 46 | +BASE_DIR = Path(__file__).parent |
| 47 | +BINDINGS_CYTHON_DIR = 'libzim' # the cython binding source dir (containing .pyx, .pyd, etc.) |
| 48 | +LIBZIM_INCLUDE_DIR = 'include' # the libzim C++ header src dir (containing zim/*.h) |
| 49 | +LIBZIM_LIBRARY_DIR = 'lib' # the libzim .so binary lib dir (containing libzim.so) |
| 50 | + |
| 51 | + |
| 52 | +# Check for the CPP Libzim library headers in expected directory |
| 53 | +if not (BASE_DIR / LIBZIM_INCLUDE_DIR / 'zim/zim.h').exists(): |
| 54 | + print( |
| 55 | + f"[!] Warning: Couldn't find zim/*.h in ./{LIBZIM_INCLUDE_DIR}!\n" |
| 56 | + f" Hint: You can install them from source from https://github.com/openzim/libzim\n" |
| 57 | + f" or download a prebuilt release's headers into ./include/zim/*.h\n" |
| 58 | + f" (or set CFLAGS='-I/tmp/libzim_linux-x86_64-{VERSION}/include')" |
| 59 | + ) |
| 60 | + |
| 61 | +# Check for the CPP Libzim shared library in expected directory or system paths |
| 62 | +if not ((BASE_DIR / LIBZIM_LIBRARY_DIR / 'libzim.so').exists() or find_library('zim')): |
| 63 | + print( |
| 64 | + f"[!] Warning: Couldn't find libzim.so in ./{LIBZIM_LIBRARY_DIR} or system library paths!" |
| 65 | + f" Hint: You can install it from source from https://github.com/openzim/libzim\n" |
| 66 | + f" or download a prebuilt zimlib.so release into ./lib.\n" |
| 67 | + f" (or set LDFLAGS='-L/tmp/libzim_linux-x86_64-{VERSION}/lib/x86_64-linux-gnu')" |
| 68 | + ) |
12 | 69 |
|
13 | 70 | setup(
|
14 |
| - name = "python-libzim", |
15 |
| - version = "0.0.1", |
16 |
| - author = "Monadical SAS", |
17 |
| - author_email = "[email protected]", |
18 |
| - description = ("A python-facing API for creating and interacting with ZIM files"), |
19 |
| - license = "GPLv3+", |
20 |
| - long_description=read('README.md'), |
21 |
| - ext_modules = cythonize([ |
22 |
| - Extension("libzim_wrapper", ["libzim/*.pyx", "libzim/lib.cxx"], |
23 |
| - include_dirs=["libzim"], |
24 |
| - libraries=["zim"], |
25 |
| - extra_compile_args=["-std=c++11"], |
26 |
| - language="c++"), |
| 71 | + name=PACKAGE_NAME, |
| 72 | + version=VERSION, |
| 73 | + url=GITHUB_URL, |
| 74 | + project_urls={ |
| 75 | + 'Source': GITHUB_URL, |
| 76 | + 'Bug Tracker': f'{GITHUB_URL}/issues', |
| 77 | + 'Changelog': f'{GITHUB_URL}/releases', |
| 78 | + 'Documentation': f'{GITHUB_URL}/blob/master/README.md', |
| 79 | + 'Donate': 'https://www.kiwix.org/en/support-us/', |
| 80 | + }, |
| 81 | + author=AUTHOR, |
| 82 | + author_email=AUTHOR_EMAIL, |
| 83 | + license=LICENSE, |
| 84 | + description=DESCRIPTION, |
| 85 | + long_description=(BASE_DIR / 'README.md').read_text(), |
| 86 | + long_description_content_type="text/markdown", |
| 87 | + python_requires='>=3.6', |
| 88 | + include_package_data=True, |
| 89 | + ext_modules=cythonize( |
| 90 | + [ |
| 91 | + Extension( |
| 92 | + "libzim_wrapper", |
| 93 | + sources=[ |
| 94 | + f"{BINDINGS_CYTHON_DIR}/*.pyx", |
| 95 | + f"{BINDINGS_CYTHON_DIR}/lib.cxx", |
| 96 | + ], |
| 97 | + include_dirs=[ |
| 98 | + BINDINGS_CYTHON_DIR, |
| 99 | + LIBZIM_INCLUDE_DIR, |
| 100 | + ], |
| 101 | + libraries=[ |
| 102 | + 'zim', |
| 103 | + ], |
| 104 | + library_dirs=[ |
| 105 | + LIBZIM_LIBRARY_DIR, |
| 106 | + ], |
| 107 | + extra_compile_args=[ |
| 108 | + "-std=c++11", |
| 109 | + "-Wall", |
| 110 | + "-Wextra", |
| 111 | + ], |
| 112 | + language="c++", |
| 113 | + ) |
27 | 114 | ],
|
28 |
| - compiler_directives={'language_level' : "3"} |
| 115 | + compiler_directives={"language_level" : "3"}, |
29 | 116 | ),
|
| 117 | + zip_safe=False, |
| 118 | + classifiers=[ |
| 119 | + "Development Status :: 3 - Alpha", |
| 120 | + |
| 121 | + "Topic :: Utilities", |
| 122 | + "Topic :: Software Development :: Libraries", |
| 123 | + "Topic :: Software Development :: Libraries :: Python Modules", |
| 124 | + "Topic :: System :: Archiving", |
| 125 | + "Topic :: System :: Archiving :: Compression", |
| 126 | + "Topic :: System :: Archiving :: Mirroring", |
| 127 | + "Topic :: System :: Archiving :: Backup", |
| 128 | + "Topic :: Internet :: WWW/HTTP", |
| 129 | + "Topic :: Internet :: WWW/HTTP :: Indexing/Search", |
| 130 | + "Topic :: Sociology :: History", |
| 131 | + |
| 132 | + "Intended Audience :: Developers", |
| 133 | + "Intended Audience :: Education", |
| 134 | + "Intended Audience :: End Users/Desktop", |
| 135 | + "Intended Audience :: Information Technology", |
| 136 | + "Intended Audience :: System Administrators", |
| 137 | + |
| 138 | + "Programming Language :: Cython", |
| 139 | + "Programming Language :: Python :: 3", |
| 140 | + "Programming Language :: Python :: 3.6", |
| 141 | + "Programming Language :: Python :: 3.7", |
| 142 | + "Programming Language :: Python :: 3.8", |
| 143 | + # "Typing :: Typed", |
| 144 | + |
| 145 | + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", |
| 146 | + "Natural Language :: English", |
| 147 | + "Operating System :: OS Independent", |
| 148 | + ], |
30 | 149 | )
|
0 commit comments