Skip to content

Commit 17da950

Browse files
committed
updated
1 parent 985a08d commit 17da950

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

setup.py

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
from pathlib import Path
2-
from os import getenv, environ
1+
import subprocess
32
import sys
3+
from os import environ, getenv
44

5-
from setuptools import setup, Extension, find_packages
6-
from setuptools.command.build_ext import build_ext
75
import numpy
6+
from setuptools import Extension, find_packages, setup
7+
from setuptools.command.build_ext import build_ext
88

9-
libraries = ['usb-1.0', 'bladeRF']
9+
libraries = ['bladeRF']
1010

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']
1312

1413
INSTALL_REQUIRES = []
1514
SETUP_REQUIRES = []
@@ -19,30 +18,42 @@
1918
if getenv('LIBLINK'):
2019
PLATFORM = 'android'
2120

22-
# detect cython
2321
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')
2727

2828
cflags = environ.get('CFLAGS', '')
2929
ldflags = environ.get('LDFLAGS', '')
3030

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+
3748
elif PLATFORM == 'win32':
3849
pass
3950

4051
environ['CFLAGS'] = f'{cflags} {new_cflags}'.strip()
4152
environ['LDFLAGS'] = f'{ldflags} {new_ldflags}'.strip()
53+
4254
else:
43-
libraries = ['usb1.0', 'bladeRF']
55+
LIBHACKRF_FILES = ['python_bladerf/pylibbladerf/pybladerf_android.pyx', 'python_bladerf/pylibbladerf/cbladerf_android.pxd']
4456

45-
source_files = [str(fn) for fn in LIBBLADERF_FILES]
4657

4758
setup(
4859
name='python_bladerf',
@@ -52,19 +63,26 @@
5263
ext_modules=[
5364
Extension(
5465
name='python_bladerf.pylibbladerf.pybladerf',
55-
sources=source_files,
66+
sources=LIBBLADERF_FILES,
5667
libraries=libraries,
5768
include_dirs=['python_bladerf/pylibbladerf', numpy.get_include()],
5869
extra_compile_args=['-w'],
5970
),
6071
Extension(
6172
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'],
6380
include_dirs=['python_bladerf/pybladerf_tools', numpy.get_include()],
6481
extra_compile_args=['-w'],
65-
)
82+
),
6683
],
84+
include_package_data=True,
6785
packages=find_packages(),
6886
package_dir={'': '.'},
69-
include_package_data=True,
87+
zip_safe=False,
7088
)

0 commit comments

Comments
 (0)