summaryrefslogtreecommitdiffstats
path: root/scripts/gen_bindings.py
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-08-09 15:02:21 +0400
committerEthan Werner <mail@ethanwerner.com>2026-08-09 15:02:21 +0400
commit3d92926a902017e7cf1f5738e99ff62da596ce12 (patch)
tree2b55422c26a48759d56fa91f06df24449e9dfa88 /scripts/gen_bindings.py
parent07e18043145f3d91c8ea7ec3ad41b3c905585277 (diff)
Diffstat (limited to 'scripts/gen_bindings.py')
-rw-r--r--scripts/gen_bindings.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/scripts/gen_bindings.py b/scripts/gen_bindings.py
index 845c8a5..f7c0486 100644
--- a/scripts/gen_bindings.py
+++ b/scripts/gen_bindings.py
@@ -36,6 +36,7 @@ MIN_PARAM_DEFAULTS = {
"choppiness_index": {"k": 2},
"performance_ratio": {"k": 2},
"standard_error": {"k": 2},
+ "mesa_sine_wave": {"k": 2},
}
@@ -64,6 +65,7 @@ def main():
f.write("import ctypes\n")
f.write("import ctypes.util\n")
f.write("import os\n")
+ f.write("import subprocess\n")
f.write("import numpy as np\n")
f.write("import threading\n\n")
@@ -81,11 +83,14 @@ def main():
f.write(" libdir = subprocess.check_output(\n")
f.write(' ["pkg-config", "--variable=libdir", "ts"],\n')
f.write(" stderr=subprocess.DEVNULL,\n")
+ f.write(" timeout=10,\n")
f.write(" ).decode().strip()\n")
f.write(
' return ctypes.CDLL(os.path.join(libdir, "libts.so"), ctypes.RTLD_GLOBAL)\n'
)
- f.write(" except (OSError, subprocess.CalledProcessError):\n")
+ f.write(
+ " except (OSError, subprocess.CalledProcessError, subprocess.TimeoutExpired):\n"
+ )
f.write(" pass\n")
f.write(" build_dir = os.path.join(\n")
f.write(
@@ -100,7 +105,11 @@ def main():
' raise OSError("Cannot find libts.so. Run make install or build from source.")\n\n\n'
)
- f.write("__version__ = '0.1.0'\n\n")
+ f.write("try:\n")
+ f.write(" from importlib.metadata import version as _version\n")
+ f.write(" __version__ = _version(__name__)\n")
+ f.write("except Exception:\n")
+ f.write(" __version__ = '0.1.0'\n\n")
f.write("_lib = _find_lib()\n\n")
# --- Helpers ---
@@ -108,7 +117,11 @@ def main():
f.write("def _cp(arr):\n")
f.write(' """Copy numpy array to ctypes buffer (tracked in TLS list)."""\n')
- f.write(" buf = (_CD * len(arr))(*arr)\n")
+ f.write(" if len(arr) == 0:\n")
+ f.write(" buf = (_CD * 1)()\n")
+ f.write(" buf[0] = 0.0\n")
+ f.write(" else:\n")
+ f.write(" buf = (_CD * len(arr))(*arr)\n")
f.write(" if not hasattr(_tls, 'bufs'):\n")
f.write(" _tls.bufs = []\n")
f.write(" _tls.bufs.append(buf)\n")
@@ -119,7 +132,7 @@ def main():
f.write(" try:\n")
f.write(" if hasattr(_tls, 'bufs'):\n")
f.write(" _tls.bufs.clear()\n")
- f.write(" except Exception:\n")
+ f.write(" except AttributeError:\n")
f.write(" pass\n\n\n")
# --- Parameter structs ---