diff --git a/README.md b/README.md index 419cd17..f99f4c0 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ $ cd build && meson install A python wrapper, installed as follows, is available in the `python` directory. ```sh -$ python3 -m pip install ./python +$ python3 -m pip install . ``` Decoding and encoding tools are provided in `python/tools`, like C tools, diff --git a/meson.build b/meson.build index 135f8a0..3c9313d 100644 --- a/meson.build +++ b/meson.build @@ -32,3 +32,7 @@ subdir('src') if get_option('tools') subdir('tools') endif + +if get_option('python') + subdir('python') +endif diff --git a/meson_options.txt b/meson_options.txt index 5249131..d840d1c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -16,3 +16,8 @@ option('tools', type: 'boolean', value: false, description: 'Build tools') + +option('python', + type: 'boolean', + value: false, + description: 'Build python bindings') diff --git a/python/pyproject.toml b/pyproject.toml similarity index 65% rename from python/pyproject.toml rename to pyproject.toml index c1bb77c..4806a64 100644 --- a/python/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,11 @@ [build-system] -requires = ["hatchling"] -build-backend = "hatchling.build" +requires = ["meson-python"] +build-backend = "mesonpy" [project] name = "lc3" version = "0.0.1" -license = "Apache-2.0" +license = { text="Apache-2.0" } authors = [ { name="Antoine Soulier", email="asoulier@google.com" }, ] @@ -14,3 +14,6 @@ requires-python = ">=3.10" [project.urls] Homepage = "https://github.com/google/liblc3" + +[tool.meson-python.args] +setup = ['-Dpython=true'] diff --git a/python/lc3.py b/python/lc3.py index 4245b23..e07efee 100644 --- a/python/lc3.py +++ b/python/lc3.py @@ -17,6 +17,8 @@ import array import ctypes import enum +import glob +import os from ctypes import c_bool, c_byte, c_int, c_uint, c_size_t, c_void_p from ctypes.util import find_library @@ -55,7 +57,12 @@ class _Base: raise ValueError("Invalid sample rate: %d Hz" % samplerate) if libpath is None: - libpath = find_library("lc3") + mesonpy_lib = glob.glob(os.path.join(os.path.dirname(__file__), '.lc3.mesonpy.libs', '*lc3*')) + + if mesonpy_lib: + libpath = mesonpy_lib[0] + else: + libpath = find_library("lc3") if not libpath: raise Exception("LC3 library not found") diff --git a/python/meson.build b/python/meson.build new file mode 100644 index 0000000..e63c768 --- /dev/null +++ b/python/meson.build @@ -0,0 +1,3 @@ +py = import('python').find_installation() + +py.install_sources('lc3.py')