|
1 | | -from pathlib import Path |
2 | | -from os import getenv, environ |
| 1 | +import subprocess |
3 | 2 | import sys |
| 3 | +from os import environ, getenv |
4 | 4 |
|
5 | | -from setuptools import setup, Extension, find_packages |
6 | | -from setuptools.command.build_ext import build_ext |
7 | 5 | import numpy |
| 6 | +from setuptools import Extension, find_packages, setup |
| 7 | +from setuptools.command.build_ext import build_ext |
8 | 8 |
|
9 | | -libraries = ['usb-1.0', 'bladeRF'] |
| 9 | +libraries = ['bladeRF'] |
10 | 10 |
|
11 | | -LIBBLADERF_FILES = list(Path('python_bladerf/pylibbladerf').rglob('*.pyx')) |
12 | | -PYBLADERF_TOOLS_FILES = list(Path('python_bladerf/pybladerf_tools').rglob('*.pyx')) |
| 11 | +LIBBLADERF_FILES = ['python_bladerf/pylibbladerf/pybladerf.pyx', 'python_bladerf/pylibbladerf/cbladerf.pxd'] |
13 | 12 |
|
14 | 13 | INSTALL_REQUIRES = [] |
15 | 14 | SETUP_REQUIRES = [] |
|
19 | 18 | if getenv('LIBLINK'): |
20 | 19 | PLATFORM = 'android' |
21 | 20 |
|
22 | | -# detect cython |
23 | 21 | if PLATFORM != 'android': |
24 | | - SETUP_REQUIRES.append('cython==0.29.36') |
25 | | - INSTALL_REQUIRES.append('cython==0.29.36') |
26 | | - INSTALL_REQUIRES.append('numpy>=1.26') |
| 22 | + SETUP_REQUIRES.append('Cython==0.29.37') |
| 23 | + INSTALL_REQUIRES.append('Cython==0.29.37') |
| 24 | + |
| 25 | + SETUP_REQUIRES.append('numpy') |
| 26 | + INSTALL_REQUIRES.append('numpy') |
27 | 27 |
|
28 | 28 | cflags = environ.get('CFLAGS', '') |
29 | 29 | ldflags = environ.get('LDFLAGS', '') |
30 | 30 |
|
31 | | - if PLATFORM == 'darwin': |
32 | | - new_cflags = '-I/opt/homebrew/include/libusb-1.0 -I/opt/homebrew/include' |
33 | | - new_ldflags = '-L/opt/homebrew/lib' |
34 | | - elif PLATFORM.startswith('linux'): |
35 | | - new_cflags = '-I/usr/include/libusb-1.0 -I/usr/include' |
36 | | - new_ldflags = '-L/usr/lib64 -L/usr/lib' |
| 31 | + if PLATFORM in {'linux', 'darwin'}: |
| 32 | + if environ.get('PYTHON_BLADERF_CFLAGS', None) is None: |
| 33 | + try: |
| 34 | + new_cflags = subprocess.check_output(['pkg-config', '--cflags', 'libbladerf']).decode('utf-8').strip() |
| 35 | + except Exception: |
| 36 | + raise RuntimeError('Unable to run pkg-config. Set cflags manually export PYTHON_BLADERF_CFLAGS=') from None |
| 37 | + else: |
| 38 | + new_cflags = environ.get('PYTHON_BLADERF_CFLAGS', '') |
| 39 | + |
| 40 | + if environ.get('PYTHON_BLADERF_LDFLAGS', None) is None: |
| 41 | + try: |
| 42 | + new_ldflags = subprocess.check_output(['pkg-config', '--libs', 'libbladerf']).decode('utf-8').strip() |
| 43 | + except Exception: |
| 44 | + raise RuntimeError('Unable to run pkg-config. Set libs manually export PYTHON_BLADERF_LDFLAGS=') from None |
| 45 | + else: |
| 46 | + new_ldflags = environ.get('PYTHON_BLADERF_LDFLAGS', '') |
| 47 | + |
37 | 48 | elif PLATFORM == 'win32': |
38 | 49 | pass |
39 | 50 |
|
40 | 51 | environ['CFLAGS'] = f'{cflags} {new_cflags}'.strip() |
41 | 52 | environ['LDFLAGS'] = f'{ldflags} {new_ldflags}'.strip() |
| 53 | + |
42 | 54 | else: |
43 | | - libraries = ['usb1.0', 'bladeRF'] |
| 55 | + LIBHACKRF_FILES = ['python_bladerf/pylibbladerf/pybladerf_android.pyx', 'python_bladerf/pylibbladerf/cbladerf_android.pxd'] |
44 | 56 |
|
45 | | -source_files = [str(fn) for fn in LIBBLADERF_FILES] |
46 | 57 |
|
47 | 58 | setup( |
48 | 59 | name='python_bladerf', |
|
52 | 63 | ext_modules=[ |
53 | 64 | Extension( |
54 | 65 | name='python_bladerf.pylibbladerf.pybladerf', |
55 | | - sources=source_files, |
| 66 | + sources=LIBBLADERF_FILES, |
56 | 67 | libraries=libraries, |
57 | 68 | include_dirs=['python_bladerf/pylibbladerf', numpy.get_include()], |
58 | 69 | extra_compile_args=['-w'], |
59 | 70 | ), |
60 | 71 | Extension( |
61 | 72 | name='python_bladerf.pybladerf_tools.pybladerf_sweep', |
62 | | - sources=[str(fn) for fn in PYBLADERF_TOOLS_FILES], |
| 73 | + sources=['python_bladerf/pybladerf_tools/pybladerf_sweep.pyx'], |
| 74 | + include_dirs=['python_bladerf/pylibbladerf', 'python_bladerf/pybladerf_tools', numpy.get_include()], |
| 75 | + extra_compile_args=['-w'], |
| 76 | + ), |
| 77 | + Extension( |
| 78 | + name='python_bladerf.pybladerf_tools.pybladerf_transfer', |
| 79 | + sources=['python_bladerf/pybladerf_tools/pybladerf_transfer.pyx'], |
63 | 80 | include_dirs=['python_bladerf/pybladerf_tools', numpy.get_include()], |
64 | 81 | extra_compile_args=['-w'], |
65 | | - ) |
| 82 | + ), |
66 | 83 | ], |
| 84 | + include_package_data=True, |
67 | 85 | packages=find_packages(), |
68 | 86 | package_dir={'': '.'}, |
69 | | - include_package_data=True, |
| 87 | + zip_safe=False, |
70 | 88 | ) |
0 commit comments