- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.py
More file actions
Latest commit
136 lines (116 loc) · 5.28 KB
/
Copy pathsetup.py
File metadata and controls
136 lines (116 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
importsubprocess# noqa I001
importsys
fromosimportenviron, getenv, path
importnumpy
fromsetuptoolsimportExtension, find_packages, setup
fromsetuptools.command.build_extimportbuild_ext
fromsetuptools.command.installimportinstall
fromCython.Buildimportcythonize
INSTALL_REQUIRES= ['Cython>=3.1.0,<3.2.1', 'numpy']
SETUP_REQUIRES= ['Cython>=3.1.0,<3.2.1', 'numpy']
libhackrf_h_paths= []
PLATFORM=sys.platform
ifgetenv('LIBLINK'):
PLATFORM='android'
ifPLATFORM!='android':
cflags=environ.get('CFLAGS', '')
ldflags=environ.get('LDFLAGS', '')
new_cflags=''
new_ldflags=''
ifPLATFORMin {'linux', 'darwin'}:
ifenviron.get('PYTHON_HACKRF_CFLAGS', None) isNone:
try:
new_cflags=subprocess.check_output(['pkg-config', '--cflags', 'libhackrf']).decode('utf-8').strip()
libhackrf_h_paths= [new_cflag[2:] fornew_cflaginnew_cflags.split()]
exceptException:
raiseRuntimeError('Unable to run pkg-config. Set cflags manually export PYTHON_HACKRF_CFLAGS=') fromNone
else:
new_cflags=environ.get('PYTHON_HACKRF_CFLAGS', '')
libhackrf_h_paths= [new_cflag[2:] fornew_cflaginnew_cflags.split()]
ifenviron.get('PYTHON_HACKRF_LDFLAGS', None) isNone:
try:
new_ldflags=subprocess.check_output(['pkg-config', '--libs', 'libhackrf']).decode('utf-8').strip()
exceptException:
raiseRuntimeError('Unable to run pkg-config. Set libs manually export PYTHON_HACKRF_LDFLAGS=') fromNone
else:
new_ldflags=environ.get('PYTHON_HACKRF_LDFLAGS', '')
elifPLATFORM.startswith('win'):
include_path='C:\\Program Files\\HackRF\\include'
lib_path='C:\\Program Files\\HackRF\\lib'
libhackrf_h_paths= [include_path]
ifenviron.get('PYTHON_HACKRF_INCLUDE_PATH', None) isNone:
new_cflags=f'-I"{include_path}"'
else:
include_path=environ.get('PYTHON_HACKRF_INCLUDE_PATH', '')
libhackrf_h_paths= [include_path]
new_cflags=f'-I"{include_path}"'
ifenviron.get('PYTHON_HACKRF_LIB_PATH', None) isNone:
new_ldflags=f'-L"{lib_path}" -lhackrf'
else:
lib_path=environ.get('PYTHON_HACKRF_LIB_PATH', '')
new_ldflags=f'-L"{lib_path}" -lhackrf'
environ['CL'] =f'/I"{include_path}"'
environ['LINK'] =f'/LIBPATH:"{lib_path}" hackrf.lib'
environ['CFLAGS'] =f'{cflags}{new_cflags}'.strip()
environ['LDFLAGS'] =f'{ldflags}{new_ldflags}'.strip()
else:
libhackrf_h_paths= [environ.get('PYTHON_HACKRF_LIBHACKRF_H_PATH', '')]
classCustomBuildExt(build_ext):
defrun(self) ->None: # type: ignore
compile_env= {'ANDROID': PLATFORM=='android'}
self.distribution.ext_modules=cythonize( # type: ignore
self.distribution.ext_modules,
compile_time_env=compile_env,
)
super().run() # type: ignore
classInstallWithPth(install):
defrun(self) ->None: # type: ignore
super().run() # type: ignore
ifPLATFORM.startswith('win'):
pth_code= (
'import os; '
'os.add_dll_directory(os.getenv("HACKRF_LIB_DIR", r"C:\\Program Files\\HackRF\\lib"))'
)
withopen(path.join(self.install_lib, "python_hackrf.pth"), mode='w', encoding='utf-8') asfile: # type: ignore
file.write(pth_code)
setup( # type: ignore
name='python_hackrf',
cmdclass={'build_ext': CustomBuildExt, 'install': InstallWithPth},
install_requires=INSTALL_REQUIRES,
setup_requires=SETUP_REQUIRES,
ext_modules=[
Extension( # type: ignore
name='python_hackrf.pylibhackrf.pyhackrf',
sources=['python_hackrf/pylibhackrf/pyhackrf.pyx'],
libraries=['hackrf'],
include_dirs=['python_hackrf/pylibhackrf', *libhackrf_h_paths, numpy.get_include()],
extra_compile_args=['-w'],
language='c++',
),
Extension( # type: ignore
name='python_hackrf.pyhackrf_tools.pyhackrf_sweep',
sources=['python_hackrf/pyhackrf_tools/pyhackrf_sweep.pyx'],
include_dirs=['python_hackrf/pylibhackrf', 'python_hackrf/pyhackrf_tools', *libhackrf_h_paths, numpy.get_include()],
extra_compile_args=['-w'],
language='c++',
),
Extension( # type: ignore
name='python_hackrf.pyhackrf_tools.pyhackrf_scan',
sources=['python_hackrf/pyhackrf_tools/pyhackrf_scan.pyx'],
include_dirs=['python_hackrf/pylibhackrf', 'python_hackrf/pyhackrf_tools', *libhackrf_h_paths, numpy.get_include()],
extra_compile_args=['-w'],
language='c++',
),
Extension( # type: ignore
name='python_hackrf.pyhackrf_tools.pyhackrf_transfer',
sources=['python_hackrf/pyhackrf_tools/pyhackrf_transfer.pyx'],
include_dirs=['python_hackrf/pylibhackrf', 'python_hackrf/pyhackrf_tools', *libhackrf_h_paths, numpy.get_include()],
extra_compile_args=['-w'],
language='c++',
),
],
include_package_data=True,
packages=find_packages(),
package_dir={'': '.'},
zip_safe=False,
)