Skip to content

Commit 72b8f7c

Browse files
committed
speedup copy that can be very very long (up to 2 minutes). This is now almost instant (1/2s.)
1 parent bde6fe1 commit 72b8f7c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

pythonforandroid/python.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from os import environ
88
import glob
99
import sh
10+
from shutil import copy2
1011

1112
from pythonforandroid.recipe import Recipe, TargetPythonRecipe
1213
from pythonforandroid.logger import logger, info, error, shprint
@@ -344,16 +345,19 @@ def create_python_bundle(self, dirn, arch):
344345
'2' if self.version[0] == '2' else '',
345346
self.major_minor_version_string
346347
))
347-
module_filens = (glob.glob(join(modules_build_dir, '*.so')) +
348+
module_filens = list(glob.glob(join(modules_build_dir, '*.so')) +
348349
glob.glob(join(modules_build_dir, '*.py')))
350+
info("Copy {} files into the bundle".format(len(module_filens)))
349351
for filen in module_filens:
350-
shprint(sh.cp, filen, modules_dir)
352+
info(" - copy {}".format(filen))
353+
copy2(filen, modules_dir)
351354

352355
# zip up the standard library
353356
stdlib_zip = join(dirn, 'stdlib.zip')
354357
with current_directory(join(self.get_build_dir(arch.arch), 'Lib')):
355-
stdlib_filens = walk_valid_filens(
356-
'.', self.stdlib_dir_blacklist, self.stdlib_filen_blacklist)
358+
stdlib_filens = list(walk_valid_filens(
359+
'.', self.stdlib_dir_blacklist, self.stdlib_filen_blacklist))
360+
info("Zip {} files into the bundle".format(len(stdlib_filens)))
357361
shprint(sh.zip, stdlib_zip, *stdlib_filens)
358362

359363
# copy the site-packages into place
@@ -364,9 +368,11 @@ def create_python_bundle(self, dirn, arch):
364368
filens = list(walk_valid_filens(
365369
'.', self.site_packages_dir_blacklist,
366370
self.site_packages_filen_blacklist))
371+
info("Copy {} files into the site-packages".format(len(filens)))
367372
for filen in filens:
373+
info(" - copy {}".format(filen))
368374
ensure_dir(join(dirn, 'site-packages', dirname(filen)))
369-
sh.cp(filen, join(dirn, 'site-packages', filen))
375+
copy2(filen, join(dirn, 'site-packages', filen))
370376

371377
# copy the python .so files into place
372378
python_build_dir = join(self.get_build_dir(arch.arch),
@@ -375,8 +381,9 @@ def create_python_bundle(self, dirn, arch):
375381
if self.major_minor_version_string[0] == '3':
376382
python_lib_name += 'm'
377383
for lib in [python_lib_name + '.so', python_lib_name + '.so.1.0']:
378-
shprint(sh.cp, join(python_build_dir, lib),
379-
'libs/{}'.format(arch.arch))
384+
filename = join(python_build_dir, lib)
385+
if exists(filename):
386+
shprint(sh.cp, filename, 'libs/{}'.format(arch.arch))
380387

381388
info('Renaming .so files to reflect cross-compile')
382389
self.reduce_object_file_names(join(dirn, 'site-packages'))

0 commit comments

Comments
 (0)