Skip to content

Commit

Permalink
Speed up Python and NumPy compilation process
Browse files Browse the repository at this point in the history
Uses `-j` flag on target/host python as well as numpy to run compilation
in parallel. In Python an optimum number of jobs is guessed if the flag
is used alone. In NumPy it must be explicitly set.
  • Loading branch information
AndreMiras committed Feb 1, 2019
1 parent b168978 commit cc379cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pythonforandroid/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def build_arch(self, arch):
py_version = self.major_minor_version_string
if self.major_minor_version_string[0] == '3':
py_version += 'm'
shprint(sh.make, 'all',
shprint(sh.make, 'all', '-j',
'INSTSONAME=libpython{version}.so'.format(
version=py_version), _env=env)

Expand Down Expand Up @@ -420,7 +420,7 @@ def build_arch(self, arch):
shprint(sh.cp, join('Modules', 'Setup.dist'),
join(build_dir, 'Modules', 'Setup'))

result = shprint(sh.make, '-C', build_dir)
result = shprint(sh.make, '-j', '-C', build_dir)
else:
info('Skipping {name} ({version}) build, as it has already '
'been completed'.format(name=self.name, version=self.version))
Expand Down
15 changes: 11 additions & 4 deletions pythonforandroid/recipes/numpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
from multiprocessing import cpu_count
from os.path import join


Expand All @@ -7,7 +8,6 @@ class NumpyRecipe(CompiledComponentsPythonRecipe):
version = '1.15.1'
url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.zip'
site_packages_name = 'numpy'

depends = [('python2', 'python3', 'python3crystax')]

patches = [
Expand All @@ -18,6 +18,16 @@ class NumpyRecipe(CompiledComponentsPythonRecipe):
join('patches', 'python-fixes.patch')
]

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

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

def get_recipe_env(self, arch):
env = super(NumpyRecipe, self).get_recipe_env(arch)

Expand All @@ -44,8 +54,5 @@ def get_recipe_env(self, arch):
env['LD'] += flags + ' -shared'
return env

def prebuild_arch(self, arch):
super(NumpyRecipe, self).prebuild_arch(arch)


recipe = NumpyRecipe()

0 comments on commit cc379cd

Please sign in to comment.