LimeDriverBindings/setup.py
Kumi 1f24eb3f64
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.
2024-02-08 09:52:51 +01:00

51 lines
1.2 KiB
Python

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import subprocess
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):
super().build_extensions()
def run(self):
if not os.path.exists('extern/limedriver'):
self.clone_limedriver()
self.build_limedriver()
super().run()
def clone_limedriver(self):
subprocess.check_call(['git', 'submodule', 'init'])
subprocess.check_call(['git', 'submodule', 'update'])
def build_limedriver(self):
subprocess.check_call(['./configure'], cwd='extern/limedriver')
subprocess.check_call(['make'], cwd='extern/limedriver')
ext_modules = [
Extension(
'limedriver.binding',
sources=['src/limedriver/limedriver.pyx', 'extern/limedriver/src/limedriver.cpp'],
include_dirs=["extern/limedriver/src/"],
libraries=["LimeSuite"],
language="c++",
),
]
setup(
name='limedriver',
cmdclass={
'build_ext': BuildExtCommand,
},
ext_modules=cythonize(ext_modules),
)