Skip to content

Commit d69ec31

Browse files
committed
fix numpy and matplotlib build
1 parent 3035ca5 commit d69ec31

5 files changed

Lines changed: 40 additions & 59 deletions

File tree

pythonforandroid/logger.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ def shprint(command, *args, **kwargs):
135135
kwargs["_out_bufsize"] = 1
136136
kwargs["_err_to_out"] = True
137137
kwargs["_bg"] = True
138+
139+
# silent mode
140+
silent = kwargs.get("silent", False)
141+
kwargs.pop("silent", False)
142+
if silent:
143+
kwargs["_out"] = None
144+
kwargs["_err"] = None
145+
138146
is_critical = kwargs.pop('_critical', False)
139147
tail_n = kwargs.pop('_tail', None)
140148
full_debug = False
@@ -190,6 +198,11 @@ def shprint(command, *args, **kwargs):
190198
Err_Style.RESET_ALL, ' ', width=(columns - 1)))
191199
stdout.flush()
192200
except sh.ErrorReturnCode as err:
201+
if silent:
202+
if is_critical:
203+
exit(1)
204+
else:
205+
raise
193206
if need_closing_newline:
194207
stdout.write('{}\r{:>{width}}\r'.format(
195208
Err_Style.RESET_ALL, ' ', width=(columns - 1)))

pythonforandroid/recipe.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ def lookup_prebuilt(self, arch):
12781278
pip_options.extend(["--dry-run", "-q"])
12791279
pip_env = self.get_hostrecipe_env()
12801280
try:
1281-
shprint(self._host_recipe.pip, *pip_options, _env=pip_env)
1281+
shprint(self._host_recipe.pip, *pip_options, _env=pip_env, silent=True)
12821282
except Exception:
12831283
return False
12841284
return True
@@ -1295,9 +1295,6 @@ def check_prebuilt(self, arch, msg=""):
12951295
return False
12961296

12971297
def get_recipe_env(self, arch, **kwargs):
1298-
# Custom hostpython
1299-
self.ctx.python_recipe.python_exe = join(
1300-
self.ctx.python_recipe.get_build_dir(arch), "android-build", "python3")
13011298
env = super().get_recipe_env(arch, **kwargs)
13021299
build_dir = self.get_build_dir(arch)
13031300
ensure_dir(build_dir)
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
from pythonforandroid.recipe import MesonRecipe
2-
from pythonforandroid.logger import shprint
3-
4-
from os.path import join
5-
import sh
62

73

84
class MatplotlibRecipe(MesonRecipe):
9-
version = '3.10.7'
10-
url = 'https://github.com/matplotlib/matplotlib/archive/v{version}.zip'
11-
depends = ['kiwisolver', 'numpy', 'pillow']
12-
python_depends = ['cycler', 'fonttools', 'packaging', 'pyparsing', 'python-dateutil']
13-
hostpython_prerequisites = ["setuptools_scm>=7"]
14-
patches = ["meson.patch"]
5+
version = "3.10.7"
6+
url = "https://github.com/matplotlib/matplotlib/archive/v{version}.zip"
7+
depends = ["kiwisolver", "numpy", "pillow"]
8+
python_depends = [
9+
"cycler",
10+
"fonttools",
11+
"packaging",
12+
"pyparsing",
13+
"python-dateutil",
14+
]
1515
need_stl_shared = True
1616

1717
def get_recipe_env(self, arch, **kwargs):
1818
env = super().get_recipe_env(arch, **kwargs)
19-
env['CXXFLAGS'] += ' -Wno-c++11-narrowing'
19+
env["CXXFLAGS"] += " -Wno-c++11-narrowing"
2020
return env
2121

22-
def build_arch(self, arch):
23-
python_path = join(self.ctx.python_recipe.get_build_dir(arch), "android-build", "python3")
24-
self.extra_build_args += [f'-Csetup-args=-Dpython3_program={python_path}']
25-
shprint(sh.cp, self.real_hostpython_location, python_path)
26-
super().build_arch(arch)
27-
2822

2923
recipe = MatplotlibRecipe()

pythonforandroid/recipes/matplotlib/meson.patch

Lines changed: 0 additions & 21 deletions
This file was deleted.

pythonforandroid/recipes/numpy/__init__.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22
from os.path import join
33
import shutil
44

5-
NUMPY_NDK_MESSAGE = "In order to build numpy, you must set minimum ndk api (minapi) to `24`.\n"
5+
NUMPY_NDK_MESSAGE = (
6+
"In order to build numpy, you must set minimum ndk api (minapi) to `24`.\n"
7+
)
68

79

810
class NumpyRecipe(MesonRecipe):
9-
version = 'v2.3.0'
10-
url = 'git+https://github.com/numpy/numpy'
11-
hostpython_prerequisites = ["Cython>=3.0.6", "numpy"] # meson does not detects venv's cython
12-
extra_build_args = ['-Csetup-args=-Dblas=none', '-Csetup-args=-Dlapack=none']
11+
version = "v2.3.0"
12+
url = "git+https://github.com/numpy/numpy"
13+
extra_build_args = ["-Csetup-args=-Dblas=none", "-Csetup-args=-Dlapack=none"]
1314
need_stl_shared = True
1415
min_ndk_api_support = 24
1516

1617
def get_recipe_meson_options(self, arch):
1718
options = super().get_recipe_meson_options(arch)
18-
# Custom python is required, so that meson
19-
# gets libs and config files properly
20-
options["binaries"]["python"] = self.ctx.python_recipe.python_exe
21-
options["binaries"]["python3"] = self.ctx.python_recipe.python_exe
22-
options["properties"]["longdouble_format"] = "IEEE_DOUBLE_LE" if arch.arch in ["armeabi-v7a", "x86"] else "IEEE_QUAD_LE"
19+
options["properties"]["longdouble_format"] = (
20+
"IEEE_DOUBLE_LE" if arch.arch in ["armeabi-v7a", "x86"] else "IEEE_QUAD_LE"
21+
)
2322
return options
2423

2524
def get_recipe_env(self, arch, **kwargs):
@@ -32,17 +31,16 @@ def get_recipe_env(self, arch, **kwargs):
3231
# NPY_DISABLE_SVML=1 allows numpy to build for non-AVX512 CPUs
3332
# See: https://github.com/numpy/numpy/issues/21196
3433
env["NPY_DISABLE_SVML"] = "1"
35-
env["TARGET_PYTHON_EXE"] = join(Recipe.get_recipe(
36-
"python3", self.ctx).get_build_dir(arch.arch), "android-build", "python")
34+
env["TARGET_PYTHON_EXE"] = join(
35+
Recipe.get_recipe("python3", self.ctx).get_build_dir(arch.arch),
36+
"android-build",
37+
"python",
38+
)
3739
return env
3840

39-
def build_arch(self, arch):
40-
super().build_arch(arch)
41-
self.restore_hostpython_prerequisites(["cython"])
42-
4341
def get_hostrecipe_env(self, arch=None):
4442
env = super().get_hostrecipe_env(arch=arch)
45-
env['RANLIB'] = shutil.which('ranlib')
43+
env["RANLIB"] = shutil.which("ranlib")
4644
return env
4745

4846

0 commit comments

Comments
 (0)