Skip to content

Commit 1acb0c9

Browse files
committed
cleaned up the code
1 parent 10804d2 commit 1acb0c9

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

android/libusb/__init__.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1+
# ruff: noqa: RUF012
12
import os
23
import shutil
3-
from typing import Any
4+
from typing import Any, override
45

5-
import sh # type: ignore
6-
from pythonforandroid.archs import Arch # type: ignore
7-
from pythonforandroid.logger import shprint # type: ignore
8-
from pythonforandroid.recipe import NDKRecipe # type: ignore
9-
from pythonforandroid.util import current_directory # type: ignore
6+
import sh
7+
from pythonforandroid.archs import Arch
8+
from pythonforandroid.logger import shprint
9+
from pythonforandroid.recipe import NDKRecipe
10+
from pythonforandroid.util import current_directory
1011

1112

12-
class LibusbRecipe(NDKRecipe): # type: ignore
13+
class LibusbRecipe(NDKRecipe):
1314

1415
url = 'https://github.com/libusb/libusb/archive/refs/tags/v{version}.tar.gz'
15-
generated_libraries = ('libusb-1.0.so', )
16+
generated_libraries = ['libusb-1.0.so']
1617
site_packages_name = 'libusb'
1718
version = '1.0.26'
1819
name = 'libusb'
1920

21+
@override
2022
def should_build(self, arch: Arch) -> bool:
2123
return not os.path.exists(os.path.join(self.ctx.get_libs_dir(arch.arch), 'libusb1.0.so'))
2224

25+
@override
2326
def get_jni_dir(self, arch: Arch) -> str:
2427
return os.path.join(self.get_build_dir(arch.arch), 'android', 'jni')
2528

29+
@override
2630
def get_lib_dir(self, arch: Arch) -> str:
2731
return os.path.join(self.get_build_dir(arch.arch), 'android', 'obj', 'local', arch.arch)
2832

29-
def build_arch(self, arch: Arch, *extra_args: Any) -> None:
33+
@override
34+
def build_arch(self, arch: Arch, *args: Any) -> None:
3035
env = self.get_recipe_env(arch)
3136
with current_directory(self.get_build_dir(arch.arch)):
3237
shprint(
@@ -35,7 +40,7 @@ def build_arch(self, arch: Arch, *extra_args: Any) -> None:
3540
'APP_PLATFORM=android-' + str(self.ctx.ndk_api),
3641
'NDK=' + self.ctx.ndk_dir,
3742
'APP_ABI=' + arch.arch,
38-
*extra_args,
43+
*args,
3944
_env=env,
4045
)
4146

android/python_bladerf/__init__.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1+
# ruff: noqa: RUF012
12
import os
2-
from typing import Any
3+
from typing import Any, override
34

4-
from pythonforandroid.archs import Arch # type: ignore
5-
from pythonforandroid.recipe import ( # type: ignore
6-
CythonRecipe,
5+
from pythonforandroid.archs import Arch
6+
from pythonforandroid.recipe import (
7+
PyProjectRecipe,
78
Recipe,
89
)
910

1011

11-
class PythonBladerfRecipe(CythonRecipe): # type: ignore
12+
class PythonBladerfRecipe(PyProjectRecipe):
1213
url = 'https://github.com/GvozdevLeonid/python_bladerf/releases/download/v.{version}/python_bladerf-{version}.tar.gz'
13-
depends = ('python3', 'setuptools', 'numpy', 'pyjnius', 'libbladerf')
14+
depends = ['python3', 'setuptools', 'numpy', 'pyjnius', 'libbladerf']
15+
hostpython_prerequisites = ['Cython>=3.1.0,<3.2']
1416
site_packages_name = 'python_bladerf'
1517
name = 'python_bladerf'
16-
version = '1.3.1'
18+
version = '1.4.0'
1719

18-
def get_recipe_env(self, arch: Arch) -> dict[str, Any]:
19-
env: dict[str, Any] = super().get_recipe_env(arch)
20+
@override
21+
def get_recipe_env(self, arch: Arch, **kwargs: Any) -> dict[str, Any]:
22+
env: dict[str, Any] = super().get_recipe_env(arch, **kwargs)
2023

2124
libbladerf_recipe = Recipe.get_recipe('libbladerf', arch)
22-
2325
libbladerf_h_dir = os.path.join(libbladerf_recipe.get_build_dir(arch), 'host', 'libraries', 'libbladeRF', 'include')
2426

25-
env['LDFLAGS'] += f' -L{self.ctx.get_libs_dir(arch.arch)}'
26-
env['CFLAGS'] += f' -I{libbladerf_h_dir}'
27+
env['LDFLAGS'] = env['LDFLAGS'] + f' -L{self.ctx.get_libs_dir(arch.arch)} -lbladeRF'
28+
env['CFLAGS'] = env['CFLAGS'] + f' -I{libbladerf_h_dir}'
29+
30+
env['PYTHON_BLADERF_LIBBLADERF_H_PATH'] = libbladerf_h_dir
31+
env['LDSHARED'] = env['CC'] + ' -shared'
32+
env['LIBLINK'] = 'NOTNONE'
2733

2834
return env
2935

0 commit comments

Comments
 (0)