Skip to content

Commit a930d64

Browse files
author
Kim Rinnewitz
committed
Extend numpy recipe to support python3
This patch extends the existing numpy recipe to also support python3crystax. Additionally, the existing recipe code is cleaned up a bit and numpy is upgraded to version 1.15.1.
1 parent 0ac1013 commit a930d64

File tree

6 files changed

+193
-119
lines changed

6 files changed

+193
-119
lines changed

pythonforandroid/recipes/numpy/__init__.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
22
from pythonforandroid.toolchain import warning
3+
from os.path import join
34

45

56
class NumpyRecipe(CompiledComponentsPythonRecipe):
67

7-
version = '1.9.2'
8-
url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.tar.gz'
9-
site_packages_name= 'numpy'
8+
version = '1.15.1'
9+
url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.zip'
10+
site_packages_name = 'numpy'
1011

11-
depends = ['python2']
12+
depends = [('python2', 'python3crystax')]
1213

13-
patches = ['patches/fix-numpy.patch',
14-
'patches/prevent_libs_check.patch',
15-
'patches/ar.patch',
16-
'patches/lib.patch']
14+
patches = [
15+
join('patches', 'fix-numpy.patch'),
16+
join('patches', 'prevent_libs_check.patch'),
17+
join('patches', 'ar.patch'),
18+
join('patches', 'lib.patch'),
19+
join('patches', 'python2-fixes.patch')
20+
]
1721

1822
def get_recipe_env(self, arch):
19-
""" looks like numpy has no proper -L flags. Code copied and adapted from
20-
https://github.com/frmdstryr/p4a-numpy/
21-
"""
22-
2323
env = super(NumpyRecipe, self).get_recipe_env(arch)
24-
#: Hack add path L to crystax as a CFLAG
25-
26-
py_ver = '3.5'
27-
if {'python2crystax', 'python2'} & set(self.ctx.recipe_build_order):
28-
py_ver = '2.7'
2924

30-
py_so = '2.7' if py_ver == '2.7' else '3.5m'
25+
flags = " -L{} --sysroot={}".format(
26+
join(self.ctx.ndk_platform, 'usr', 'lib'),
27+
self.ctx.ndk_platform
28+
)
29+
30+
if self.ctx.ndk == 'crystax':
31+
py_ver = self.ctx.python_recipe.version[0:3]
32+
src_dir = join(self.ctx.ndk_dir, 'sources')
33+
py_inc_dir = join(src_dir, 'python', py_ver, 'include', 'python')
34+
py_lib_dir = join(src_dir, 'python', py_ver, 'libs', arch.arch)
35+
cry_inc_dir = join(src_dir, 'crystax', 'include')
36+
cry_lib_dir = join(src_dir, 'crystax', 'libs', arch.arch)
37+
flags += ' -I{}'.format(py_inc_dir)
38+
flags += ' -L{} -lpython{}m'.format(py_lib_dir, py_ver)
39+
flags += " -I{}".format(cry_inc_dir)
40+
flags += " -L{}".format(cry_lib_dir)
3141

32-
api_ver = self.ctx.android_api
33-
34-
platform = 'arm' if 'arm' in arch.arch else arch.arch
35-
#: Not sure why but we have to inject these into the CC and LD env's for it to
36-
#: use the correct arguments.
37-
flags = " -L{ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}/usr/lib/" \
38-
" --sysroot={ctx.ndk_dir}/platforms/android-{api_ver}/arch-{platform}" \
39-
.format(ctx=self.ctx, arch=arch, platform=platform, api_ver=api_ver,
40-
py_so=py_so, py_ver=py_ver)
4142
if flags not in env['CC']:
4243
env['CC'] += flags
4344
if flags not in env['LD']:
4445
env['LD'] += flags + ' -shared'
45-
4646
return env
4747

4848
def prebuild_arch(self, arch):
Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1-
--- a/numpy/distutils/unixccompiler.py 2015-02-01 17:38:21.000000000 +0100
2-
+++ b/numpy/distutils/unixccompiler.py 2015-07-08 17:21:05.742468485 +0200
3-
@@ -82,6 +82,8 @@
4-
pass
5-
self.mkpath(os.path.dirname(output_filename))
6-
tmp_objects = objects + self.objects
7-
+ from os import environ
8-
+ self.archiver[0] = 'arm-linux-androideabi-ar'
1+
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
2+
index 632bcb4..c1e0dd5 100644
3+
--- a/numpy/core/code_generators/generate_umath.py
4+
+++ b/numpy/core/code_generators/generate_umath.py
5+
@@ -970,6 +970,7 @@ def make_arrays(funcdict):
6+
funclist.append('%s_%s' % (tname, name))
7+
if t.simd is not None:
8+
for vt in t.simd:
9+
+ continue
10+
code2list.append(textwrap.dedent("""\
11+
#ifdef HAVE_ATTRIBUTE_TARGET_{ISA}
12+
if (npy_cpu_supports("{isa}")) {{
13+
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py
14+
index b03fb96..f9e6cd0 100644
15+
--- a/numpy/distutils/ccompiler.py
16+
+++ b/numpy/distutils/ccompiler.py
17+
@@ -275,6 +275,7 @@ def CCompiler_compile(self, sources, output_dir=None, macros=None,
18+
self._setup_compile(output_dir, macros, include_dirs, sources,
19+
depends, extra_postargs)
20+
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
21+
+ cc_args += os.environ['CFLAGS'].split()
22+
display = "compile options: '%s'" % (' '.join(cc_args))
23+
if extra_postargs:
24+
display += "\nextra options: '%s'" % (' '.join(extra_postargs))
25+
diff --git a/numpy/distutils/unixccompiler.py b/numpy/distutils/unixccompiler.py
26+
index 11b2cce..f6dde79 100644
27+
--- a/numpy/distutils/unixccompiler.py
28+
+++ b/numpy/distutils/unixccompiler.py
29+
@@ -54,6 +54,7 @@ def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts
30+
deps = []
31+
32+
try:
33+
+ self.linker_so = [os.environ['LD']+" "+os.environ['LDFLAGS']]
34+
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + deps +
35+
extra_postargs, display = display)
36+
except DistutilsExecError:
37+
@@ -111,6 +112,7 @@ def UnixCCompiler_create_static_lib(self, objects, output_libname,
938
while tmp_objects:
1039
objects = tmp_objects[:50]
1140
tmp_objects = tmp_objects[50:]
41+
+ self.archiver[0] = 'arm-linux-androideabi-ar'
42+
display = '%s: adding %d object files to %s' % (
43+
os.path.basename(self.archiver[0]),
44+
len(objects), output_filename)
Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,17 @@
1-
diff --git a/numpy/core/src/multiarray/numpyos.c b/numpy/core/src/multiarray/numpyos.c
2-
index 44b32f4..378e199 100644
3-
--- a/numpy/core/src/multiarray/numpyos.c
4-
+++ b/numpy/core/src/multiarray/numpyos.c
5-
@@ -165,8 +165,7 @@ ensure_decimal_point(char* buffer, size_t buf_size)
6-
static void
7-
change_decimal_from_locale_to_dot(char* buffer)
8-
{
9-
- struct lconv *locale_data = localeconv();
10-
- const char *decimal_point = locale_data->decimal_point;
11-
+ const char *decimal_point = ".";
12-
13-
if (decimal_point[0] != '.' || decimal_point[1] != 0) {
14-
size_t decimal_point_len = strlen(decimal_point);
15-
@@ -448,8 +447,7 @@ NumPyOS_ascii_strtod_plain(const char *s, char** endptr)
16-
NPY_NO_EXPORT double
17-
NumPyOS_ascii_strtod(const char *s, char** endptr)
18-
{
19-
- struct lconv *locale_data = localeconv();
20-
- const char *decimal_point = locale_data->decimal_point;
21-
+ const char *decimal_point = ".";
22-
size_t decimal_point_len = strlen(decimal_point);
23-
24-
char buffer[FLOAT_FORMATBUFLEN+1];
25-
diff --git a/numpy/core/src/private/npy_config.h b/numpy/core/src/private/npy_config.h
26-
index f768c90..4e5d168 100644
27-
--- a/numpy/core/src/private/npy_config.h
28-
+++ b/numpy/core/src/private/npy_config.h
29-
@@ -41,4 +41,10 @@
30-
#undef HAVE_ATAN2
31-
#endif
32-
33-
+/* Android only */
34-
+#ifdef ANDROID
35-
+#undef HAVE_LDEXPL
36-
+#undef HAVE_FREXPL
37-
+#endif
38-
+
39-
#endif
401
diff --git a/numpy/testing/__init__.py b/numpy/testing/__init__.py
41-
index 258cbe9..ce4e0eb 100644
2+
index a7c8593..007ce26 100644
423
--- a/numpy/testing/__init__.py
434
+++ b/numpy/testing/__init__.py
44-
@@ -1,16 +1,7 @@
5+
@@ -1,22 +1,8 @@
456
-"""Common test support for all numpy test scripts.
46-
-
7+
+# fake tester, android don't have unittest
8+
+class Tester(object):
9+
+ def test(self, *args, **kwargs):
10+
+ pass
11+
+ def bench(self, *args, **kwargs):
12+
+ pass
13+
+test = Tester().test
14+
4715
-This single module should provide all the common functionality for numpy tests
4816
-in a single location, so that test scripts can just import it and work right
4917
-away.
@@ -53,14 +21,14 @@ index 258cbe9..ce4e0eb 100644
5321
-
5422
-from unittest import TestCase
5523
-
56-
-from . import decorators as dec
57-
-from .utils import *
58-
-from .nosetester import NoseTester as Tester
59-
-from .nosetester import run_module_suite
60-
+# fake tester, android don't have unittest
61-
+class Tester(object):
62-
+ def test(self, *args, **kwargs):
63-
+ pass
64-
+ def bench(self, *args, **kwargs):
65-
+ pass
66-
test = Tester().test
24+
-from ._private.utils import *
25+
-from ._private import decorators as dec
26+
-from ._private.nosetester import (
27+
- run_module_suite, NoseTester as Tester
28+
- )
29+
-
30+
-__all__ = _private.utils.__all__ + ['TestCase', 'run_module_suite']
31+
-
32+
-from ._private.pytesttester import PytestTester
33+
-test = PytestTester(__name__)
34+
-del PytestTester

pythonforandroid/recipes/numpy/patches/lib.patch

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
1-
--- a/numpy/linalg/setup.py 2015-07-09 14:15:59.850853336 +0200
2-
+++ b/numpy/linalg/setup.py 2015-07-09 14:21:59.403889000 +0200
3-
@@ -37,7 +37,8 @@
4-
config.add_extension('lapack_lite',
5-
sources = [get_lapack_lite_sources],
6-
depends = ['lapack_litemodule.c'] + lapack_lite_src,
7-
- extra_info = lapack_info
8-
+ extra_info = lapack_info,
9-
+ libraries = ['m'],
10-
)
11-
12-
# umath_linalg module
13-
@@ -46,7 +47,7 @@
14-
sources = [get_lapack_lite_sources],
15-
depends = ['umath_linalg.c.src'] + lapack_lite_src,
16-
extra_info = lapack_info,
17-
- libraries = ['npymath'],
18-
+ libraries = ['npymath','m'],
19-
)
20-
21-
return config
22-
--- a/numpy/fft/setup.py 2015-07-09 14:35:22.299888028 +0200
23-
+++ b/numpy/fft/setup.py 2015-07-09 14:33:54.858392578 +0200
24-
@@ -9,7 +9,8 @@
1+
diff --git a/numpy/fft/setup.py b/numpy/fft/setup.py
2+
index cd99a82d7..e614ecd07 100644
3+
--- a/numpy/fft/setup.py
4+
+++ b/numpy/fft/setup.py
5+
@@ -9,7 +9,8 @@ def configuration(parent_package='',top_path=None):
256

267
# Configure fftpack_lite
278
config.add_extension('fftpack_lite',
289
- sources=['fftpack_litemodule.c', 'fftpack.c']
2910
+ sources=['fftpack_litemodule.c', 'fftpack.c'],
30-
+ libraries = ['m']
11+
+ libraries=['m']
3112
)
3213

14+
return config
15+
diff --git a/numpy/linalg/setup.py b/numpy/linalg/setup.py
16+
index 66c07c9e1..d34bd930a 100644
17+
--- a/numpy/linalg/setup.py
18+
+++ b/numpy/linalg/setup.py
19+
@@ -43,6 +43,7 @@ def configuration(parent_package='', top_path=None):
20+
sources=['lapack_litemodule.c', get_lapack_lite_sources],
21+
depends=['lapack_lite/f2c.h'],
22+
extra_info=lapack_info,
23+
+ libraries=['m'],
24+
)
25+
26+
# umath_linalg module
27+
@@ -51,7 +52,7 @@ def configuration(parent_package='', top_path=None):
28+
sources=['umath_linalg.c.src', get_lapack_lite_sources],
29+
depends=['lapack_lite/f2c.h'],
30+
extra_info=lapack_info,
31+
- libraries=['npymath'],
32+
+ libraries=['npymath', 'm'],
33+
)
34+
return config
3335

34-
--- a/numpy/random/setup.orig.py 2015-07-09 14:44:41.105174826 +0200
35-
+++ b/numpy/random/setup.py 2015-07-09 14:46:08.592679877 +0200
36-
@@ -38,7 +38,7 @@
36+
diff --git a/numpy/random/setup.py b/numpy/random/setup.py
37+
index 3f3b773a4..c1db9f783 100644
38+
--- a/numpy/random/setup.py
39+
+++ b/numpy/random/setup.py
40+
@@ -40,7 +40,7 @@ def configuration(parent_package='',top_path=None):
3741
if needs_mingw_ftime_workaround():
3842
defs.append(("NPY_NEEDS_MINGW_TIME_WORKAROUND", None))
3943

pythonforandroid/recipes/numpy/patches/prevent_libs_check.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py
2-
index a050430..471e958 100644
2+
index bea120cf9..a448a83fc 100644
33
--- a/numpy/distutils/system_info.py
44
+++ b/numpy/distutils/system_info.py
5-
@@ -610,6 +610,7 @@ class system_info:
5+
@@ -719,6 +719,7 @@ class system_info(object):
66
return self.get_paths(self.section, key)
77

88
def get_libs(self, key, default):
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c
2+
index c70f852..695efd5 100644
3+
--- a/numpy/core/src/multiarray/common.c
4+
+++ b/numpy/core/src/multiarray/common.c
5+
@@ -852,3 +852,12 @@ _may_have_objects(PyArray_Descr *dtype)
6+
return (PyDataType_HASFIELDS(base) ||
7+
PyDataType_FLAGCHK(base, NPY_ITEM_HASOBJECT) );
8+
}
9+
+
10+
+/*
11+
+ * Dummy to fix android NDK problem with missing reference.
12+
+ */
13+
+void *
14+
+__emutls_get_address(struct __emutls_object *obj)
15+
+{
16+
+ return NULL;
17+
+}
18+
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py
19+
index 8118e2f..b586442 100644
20+
--- a/numpy/distutils/exec_command.py
21+
+++ b/numpy/distutils/exec_command.py
22+
@@ -260,7 +260,7 @@ def _exec_command(command, use_shell=None, use_tee = None, **env):
23+
return 127, ''
24+
25+
text, err = proc.communicate()
26+
- text = text.decode(locale.getpreferredencoding(False),
27+
+ text = text.decode('UTF-8',
28+
errors='replace')
29+
30+
text = text.replace('\r\n', '\n')
31+
diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py
32+
index f2d677a..758b1ed 100644
33+
--- a/numpy/distutils/misc_util.py
34+
+++ b/numpy/distutils/misc_util.py
35+
@@ -9,7 +9,6 @@ import atexit
36+
import tempfile
37+
import subprocess
38+
import shutil
39+
-import multiprocessing
40+
41+
import distutils
42+
from distutils.errors import DistutilsError
43+
@@ -93,10 +92,7 @@ def get_num_build_jobs():
44+
45+
"""
46+
from numpy.distutils.core import get_distribution
47+
- try:
48+
- cpu_count = len(os.sched_getaffinity(0))
49+
- except AttributeError:
50+
- cpu_count = multiprocessing.cpu_count()
51+
+ cpu_count = 1
52+
envjobs = int(os.environ.get("NPY_NUM_BUILD_JOBS", cpu_count))
53+
dist = get_distribution()
54+
# may be None during configuration
55+
diff --git a/setup.py b/setup.py
56+
index fed178e..b0266eb 100755
57+
--- a/setup.py
58+
+++ b/setup.py
59+
@@ -377,9 +377,8 @@ def setup_package():
60+
# Raise errors for unsupported commands, improve help output, etc.
61+
run_build = parse_setuppy_commands()
62+
63+
- from setuptools import setup
64+
+ from numpy.distutils.core import setup
65+
if run_build:
66+
- from numpy.distutils.core import setup
67+
cwd = os.path.abspath(os.path.dirname(__file__))
68+
if not os.path.exists(os.path.join(cwd, 'PKG-INFO')):
69+
# Generate Cython sources, unless building from source release

0 commit comments

Comments
 (0)