|
| 1 | +from distutils.core import setup, Extension |
| 2 | +from distutils.command.build_ext import build_ext |
| 3 | + |
| 4 | + |
| 5 | +# Found this on stack overflow: |
| 6 | +# https://stackoverflow.com/questions/4529555/building-a-ctypes-based-c-library-with-distutils |
| 7 | +# noinspection PyPep8Naming |
| 8 | +class build_ext(build_ext): |
| 9 | + |
| 10 | + def build_extension(self, ext): |
| 11 | + # noinspection PyAttributeOutsideInit |
| 12 | + self._ctypes = isinstance(ext, CTypesExtension) |
| 13 | + return super().build_extension(ext) |
| 14 | + |
| 15 | + def get_export_symbols(self, ext): |
| 16 | + if self._ctypes: |
| 17 | + return ext.export_symbols |
| 18 | + return super().get_export_symbols(ext) |
| 19 | + |
| 20 | + def get_ext_filename(self, ext_name): |
| 21 | + if self._ctypes: |
| 22 | + return ext_name + '.so' |
| 23 | + return super().get_ext_filename(ext_name) |
| 24 | + |
| 25 | + |
| 26 | +class CTypesExtension(Extension): |
| 27 | + pass |
| 28 | + |
| 29 | + |
| 30 | +extension = CTypesExtension( |
| 31 | + 'vl53l0x_python', |
| 32 | + define_macros=[], |
| 33 | + include_dirs=['.', 'Api/core/inc', 'platform/inc'], |
| 34 | + libraries=[], |
| 35 | + library_dirs=[], |
| 36 | + sources=['Api/core/src/vl53l0x_api_calibration.c', |
| 37 | + 'Api/core/src/vl53l0x_api_core.c', |
| 38 | + 'Api/core/src/vl53l0x_api_ranging.c', |
| 39 | + 'Api/core/src/vl53l0x_api_strings.c', |
| 40 | + 'Api/core/src/vl53l0x_api.c', |
| 41 | + 'platform/src/vl53l0x_platform.c', |
| 42 | + 'python_lib/vl53l0x_python.c']) |
| 43 | + |
| 44 | +setup(name='VL53L0X_rasp_python', |
| 45 | + version='1.0.2', |
| 46 | + description='VL53L0X sensor for raspberry PI', |
| 47 | + # author='?', |
| 48 | + # author_email='?', |
| 49 | + url='https://github.com/johnbryanmoore/VL53L0X_rasp_python', |
| 50 | + long_description=''' |
| 51 | +VL53L0X sensor for raspberry PI. |
| 52 | +''', |
| 53 | + ext_modules=[extension], |
| 54 | + package_dir={'': 'python'}, |
| 55 | + py_modules=['VL53L0X'], |
| 56 | + cmdclass={'build_ext': build_ext}) |
0 commit comments