From 1f24eb3f64c2edae86bf70407d314bc44a771a60 Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 8 Feb 2024 09:52:51 +0100 Subject: [PATCH] Enforce C++ compiler for Cython and fix Python binding - Standardized the C++ compiler across build environments by setting it in `setup.py`, ensuring consistent compilation of Cython extensions. - Transitioned to using `setuptools.build_meta` as the build backend in `pyproject.toml` for enhanced package build processes. - Modified the extension module path in `setup.py` to align with the new Python binding structure. - Introduced Python property decorators to `PyLimeConfig` class in `limedriver.pyx` for getter methods, enhancing the Pythonic interface of the Cython module. - Facilitated direct import of the binding in `__init__.py`, streamlining the usage of the `limedriver` package. --- pyproject.toml | 4 +++- setup.py | 5 +++-- src/limedriver/__init__.py | 1 + src/limedriver/limedriver.pyx | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index edccba0..6ec0c05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,4 +18,6 @@ requires = [ "setuptools", "wheel", "Cython" -] \ No newline at end of file +] + +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.py b/setup.py index 9236031..1ace92b 100644 --- a/setup.py +++ b/setup.py @@ -6,11 +6,12 @@ import os from Cython.Build import cythonize +os.environ['CXX'] = 'h5c++' + class BuildExtCommand(build_ext): """Custom build_ext command to ensure that the submodule is retrieved and built.""" def build_extensions(self): - os.environ['CXX'] = 'h5c++' super().build_extensions() def run(self): @@ -31,7 +32,7 @@ class BuildExtCommand(build_ext): ext_modules = [ Extension( - 'limedriver', + 'limedriver.binding', sources=['src/limedriver/limedriver.pyx', 'extern/limedriver/src/limedriver.cpp'], include_dirs=["extern/limedriver/src/"], libraries=["LimeSuite"], diff --git a/src/limedriver/__init__.py b/src/limedriver/__init__.py index e69de29..a04dc42 100644 --- a/src/limedriver/__init__.py +++ b/src/limedriver/__init__.py @@ -0,0 +1 @@ +import limedriver.binding diff --git a/src/limedriver/limedriver.pyx b/src/limedriver/limedriver.pyx index 69d0726..cced676 100644 --- a/src/limedriver/limedriver.pyx +++ b/src/limedriver/limedriver.pyx @@ -156,6 +156,7 @@ cdef class PyLimeConfig: def TX_IcorrDC(self, int value): self._config.TX_IcorrDC = value + @property def TX_QcorrDC(self): return self._config.TX_QcorrDC @@ -234,6 +235,7 @@ cdef class PyLimeConfig: for i in range(4): self._config.RX_gain_rback[i] = values[i] + @property def TX_gain_rback(self): return [self._config.TX_gain_rback[i] for i in range(3)] @@ -297,3 +299,4 @@ cdef class PyLimeConfig: @stamp_end.setter def stamp_end(self, value): self._config.stamp_end = value.encode('utf-8') +