diff options
author | David Robillard <d@drobilla.net> | 2021-06-14 19:26:34 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-28 22:21:07 -0500 |
commit | 5fb69c3e72d87df7552143bb9a41a8b62db26b28 (patch) | |
tree | ed7ad74545d9f9c7d8e36834d16e0833a3c44075 | |
parent | ccbbd538d001ae4e17c86839b0583716e0dd3527 (diff) | |
download | serd-5fb69c3e72d87df7552143bb9a41a8b62db26b28.tar.gz serd-5fb69c3e72d87df7552143bb9a41a8b62db26b28.tar.bz2 serd-5fb69c3e72d87df7552143bb9a41a8b62db26b28.zip |
[WIP] Build a Python package
-rw-r--r-- | bindings/python/MANIFEST.in | 5 | ||||
-rw-r--r-- | bindings/python/meson.build | 20 | ||||
-rw-r--r-- | bindings/python/serd.pyx | 2 | ||||
-rw-r--r-- | bindings/python/setup.py | 87 |
4 files changed, 108 insertions, 6 deletions
diff --git a/bindings/python/MANIFEST.in b/bindings/python/MANIFEST.in new file mode 100644 index 00000000..d5c06ad3 --- /dev/null +++ b/bindings/python/MANIFEST.in @@ -0,0 +1,5 @@ +include LICENSE +include NEWS +include README.md +include serd.h +include serd.pyx diff --git a/bindings/python/meson.build b/bindings/python/meson.build index 3a181870..d8d7b533 100644 --- a/bindings/python/meson.build +++ b/bindings/python/meson.build @@ -8,18 +8,28 @@ if cc.get_id() == 'clang' or cc.get_id() == 'gcc' ] endif +# Copy files to make this build directory a Python package +configure_file(copy: true, input: files('../../COPYING'), output: 'LICENSE') +configure_file(copy: true, input: files('../../NEWS'), output: 'NEWS') +configure_file(copy: true, input: files('../../README.md'), output: 'README.md') +configure_file(copy: true, input: files('MANIFEST.in'), output: 'MANIFEST.in') +configure_file(copy: true, input: files('setup.py'), output: 'setup.py') +configure_file(copy: true, input: files('../../include/serd/serd.h'), output: 'serd.h') + +serd_pyx = configure_file(copy: true, input: files('serd.pyx'), output: 'serd.pyx') + # Generate extension module C source code with cython -pyserd_c = custom_target( - 'serd.cpython.so', +cython_serd_c = custom_target( + 'serd.c cython extension', command: [cython, '-3', '--fast-fail', '-Wextra', '@INPUT0@', '-o', '@OUTPUT@'], - input: ['serd.pyx'], - output: 'pyserd.c', + input: serd_pyx, + output: 'serd.c', install: true, install_dir: py.get_install_dir()) # Compile extension module pyserd = py.extension_module('serd', - pyserd_c, + cython_serd_c, c_args: cython_c_args, dependencies: [py_dep, serd_dep]) diff --git a/bindings/python/serd.pyx b/bindings/python/serd.pyx index 143705a3..03bf4061 100644 --- a/bindings/python/serd.pyx +++ b/bindings/python/serd.pyx @@ -21,7 +21,7 @@ cdef extern from "stdarg.h": ctypedef struct va_list: pass -cdef extern from "serd/serd.h": +cdef extern from "serd.h": ctypedef struct SerdWorld ctypedef struct SerdNodes ctypedef struct SerdStatement diff --git a/bindings/python/setup.py b/bindings/python/setup.py new file mode 100644 index 00000000..a51b9c02 --- /dev/null +++ b/bindings/python/setup.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 + +import os + +from setuptools import setup, find_packages, Extension + +try: + from Cython.Build import cythonize +except ImportError: + cythonize = None + + +# https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#distributing-cython-modules +def no_cythonize(extensions, **_ignore): + for extension in extensions: + sources = [] + for sfile in extension.sources: + path, ext = os.path.splitext(sfile) + if ext in (".pyx", ".py"): + if extension.language == "c++": + ext = ".cpp" + else: + ext = ".c" + sfile = path + ext + sources.append(sfile) + extension.sources[:] = sources + return extensions + + +extensions = [Extension("serd", ["serd.pyx"], libraries=["serd-1"])] + +CYTHONIZE = bool(int(os.getenv("CYTHONIZE", 0))) and cythonize is not None + +if CYTHONIZE: + compiler_directives = { + "language_level": 3, + "embedsignature": True, + } + extensions = cythonize(extensions, compiler_directives=compiler_directives) +else: + extensions = no_cythonize(extensions) + +# with open("requirements.txt") as fp: +# install_requires = fp.read().strip().split("\n") + +# with open("requirements-dev.txt") as fp: +# dev_requires = fp.read().strip().split("\n") + +install_requires = [] +dev_requires = [] + +setup( + # install_requires=install_requires, + # extras_require={ + # "dev": dev_requires, + # "docs": ["sphinx", "sphinx-rtd-theme"], + # }, + name="serd", + version="1.0.1", # FIXME + description="A lightweight library for working with RDF data", + long_description=open("README.md", "r").read(), + long_description_content_type="text/markdown", + url="https://gitlab.com/drobilla/serd", + author="David Robillard", + author_email="d@drobilla.net", + zip_safe=False, + license="ISC", + # packages=["serd"], + ext_modules=extensions, + install_requires=[], + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: ISC License (ISCL)", + "Operating System :: POSIX", + "Programming Language :: C", + "Programming Language :: Cython", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + ], +) |