Skip to content

add scikit-learn recipe and dependencies #2539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TargetPython(Enum):
'sympy',
'vlc',
# need extra gfortran NDK system add-on
'lapack', 'scipy',
'lapack', 'scipy', 'scikit-learn',
# Outdated and there's a chance that is now useless.
'zope_interface',
# Requires zope_interface, which is broken.
Expand Down
14 changes: 14 additions & 0 deletions pythonforandroid/recipes/joblib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pythonforandroid.recipe import PythonRecipe


class JoblibRecipe(PythonRecipe):
org = 'joblib'
name = 'joblib'
version = '0.17.0'
url = f'https://github.com/{org}/{name}/archive/{version}.zip'
depends = ['setuptools']
call_hostpython_via_targetpython = False
patches = ['multiprocessing.patch']


recipe = JoblibRecipe()
32 changes: 32 additions & 0 deletions pythonforandroid/recipes/joblib/multiprocessing.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/joblib/externals/loky/backend/__init__.py b/joblib/externals/loky/backend/__init__.py
index a65ce0e..9efdb46 100644
--- a/joblib/externals/loky/backend/__init__.py
+++ b/joblib/externals/loky/backend/__init__.py
@@ -10,7 +10,7 @@ if sys.version_info > (3, 4):
return name

# monkey patch the name creation for multiprocessing
- from multiprocessing import synchronize
- synchronize.SemLock._make_name = staticmethod(_make_name)
+ #from multiprocessing import synchronize
+ #synchronize.SemLock._make_name = staticmethod(_make_name)

__all__ = ["get_context"]
diff --git a/joblib/externals/loky/backend/queues.py b/joblib/externals/loky/backend/queues.py
index 62735db..156e235 100644
--- a/joblib/externals/loky/backend/queues.py
+++ b/joblib/externals/loky/backend/queues.py
@@ -9,6 +9,8 @@
# * Add some custom reducers for the Queues/SimpleQueue to tweak the
# pickling process. (overload Queue._feed/SimpleQueue.put)
#
+from queue import Queue, SimpleQueue, Full
+'''
import os
import sys
import errno
@@ -245,3 +247,4 @@ class SimpleQueue(mp_SimpleQueue):
else:
with self._wlock:
self._writer.send_bytes(obj)
+'''
40 changes: 40 additions & 0 deletions pythonforandroid/recipes/scikit-learn/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pythonforandroid.recipe import CompiledComponentsPythonRecipe, Recipe
from multiprocessing import cpu_count


class ScikitlearnRecipe(CompiledComponentsPythonRecipe):

site_packages_name = 'scikit-learn'
version = '0.23.2'
url = f'https://github.com/{site_packages_name}/{site_packages_name}/archive/{version}.zip'
depends = ['setuptools', 'scipy', 'joblib', 'threadpoolctl']
call_hostpython_via_targetpython = False
need_stl_shared = True
patches = ['cross-compile.patch']

def build_compiled_components(self, arch):
self.setup_extra_args = ['-j', str(cpu_count())]
super().build_compiled_components(arch)
self.setup_extra_args = []

def rebuild_compiled_components(self, arch, env):
self.setup_extra_args = ['-j', str(cpu_count())]
super().rebuild_compiled_components(arch, env)
self.setup_extra_args = []

def strip_ccache(self, env):
for key, value in env.items():
parts = value.split(' ')
if 'ccache' in parts[0]:
env[key] = ' '.join(parts[1:])

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
self.strip_ccache(env)
scipy_build_dir = Recipe.get_recipe('scipy', self.ctx).get_build_dir(arch.arch)
env['PYTHONPATH'] += f':{scipy_build_dir}'
env['CXX'] += f' -Wl,-l{self.stl_lib_name}'
return env


recipe = ScikitlearnRecipe()
30 changes: 30 additions & 0 deletions pythonforandroid/recipes/scikit-learn/cross-compile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/setup.py b/setup.py
index 90162b6..946af48 100755
--- a/setup.py
+++ b/setup.py
@@ -291,7 +291,7 @@ def setup_package():

check_package_status('numpy', NUMPY_MIN_VERSION)

- check_package_status('scipy', SCIPY_MIN_VERSION)
+ #check_package_status('scipy', SCIPY_MIN_VERSION)

from numpy.distutils.core import setup

diff --git a/sklearn/_build_utils/pre_build_helpers.py b/sklearn/_build_utils/pre_build_helpers.py
index bc3d832..fe1819e 100644
--- a/sklearn/_build_utils/pre_build_helpers.py
+++ b/sklearn/_build_utils/pre_build_helpers.py
@@ -48,8 +48,10 @@ def compile_test_program(code, extra_preargs=[], extra_postargs=[]):

# Run test program
# will raise a CalledProcessError if return code was non-zero
- output = subprocess.check_output('./test_program')
- output = output.decode(sys.stdout.encoding or 'utf-8').splitlines()
+ assert os.path.exists('./test_program')
+ output = ['nthreads=4'] * 4
+ #output = subprocess.check_output('./test_program')
+ #output = output.decode(sys.stdout.encoding or 'utf-8').splitlines()
except Exception:
raise
finally:
14 changes: 14 additions & 0 deletions pythonforandroid/recipes/threadpoolctl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pythonforandroid.recipe import PythonRecipe


class ThreadpoolctlRecipe(PythonRecipe):
org = 'joblib'
name = 'threadpoolctl'
version = '2.1.0'
url = f'https://github.com/{org}/{name}/archive/{version}.zip'
depends = ['setuptools']
call_hostpython_via_targetpython = False
patches = ['docstring.patch', 'setuptools.patch']


recipe = ThreadpoolctlRecipe()
13 changes: 13 additions & 0 deletions pythonforandroid/recipes/threadpoolctl/docstring.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/threadpoolctl.py b/threadpoolctl.py
index b94d7a1..faf7a44 100644
--- a/threadpoolctl.py
+++ b/threadpoolctl.py
@@ -98,7 +98,7 @@ _ALL_OPENMP_LIBRARIES = list(

def _format_docstring(*args, **kwargs):
def decorator(o):
- o.__doc__ = o.__doc__.format(*args, **kwargs)
+ #o.__doc__ = o.__doc__.format(*args, **kwargs)
return o

return decorator
15 changes: 15 additions & 0 deletions pythonforandroid/recipes/threadpoolctl/setuptools.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..b18d2fd
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,9 @@
+from setuptools import setup
+import threadpoolctl
+
+if __name__ == '__main__':
+ setup(name='threadpoolctl',
+ version=threadpoolctl.__version__,
+ py_modules = ['threadpoolctl'],
+ python_requires='>=3.6',
+ )