Skip to content

Commit 4964ec2

Browse files
committed
Made site-packages copying exclude some files/folders
(in a temporary hacky way)
1 parent d786718 commit 4964ec2

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def run_distribute(self):
3636
with open('local.properties', 'w') as fileh:
3737
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
3838

39-
# TODO: Move the packaged python building to the python recipes
4039
with current_directory(self.dist_dir):
4140
info("Copying Python distribution")
4241

pythonforandroid/recipe.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -789,14 +789,10 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
789789
join(ndk_dir_python, 'libs', arch.arch))
790790
env['LDFLAGS'] += ' -lpython{}m'.format(python_short_version)
791791
elif 'python3' in self.ctx.recipe_build_order:
792-
# TODO: Make the recipe env get these details from the
793-
# python recipe instead of hardcoding
794-
env['PYTHON_ROOT'] = Recipe.get_recipe('python3', self.ctx).get_build_dir(arch.arch)
795-
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/Include'
796-
env['LDFLAGS'] += (
797-
' -L' +
798-
join(env['PYTHON_ROOT'], 'android-build') +
799-
' -lpython3.7m')
792+
env['CFLAGS'] += ' -I{}'.format(self.ctx.python_recipe.include_root(arch.arch))
793+
env['LDFLAGS'] += ' -L{} -lpython{}m'.format(
794+
self.ctx.python_recipe.link_root(arch.arch),
795+
self.ctx.python_recipe.major_minor_version_string)
800796

801797
hppath = []
802798
hppath.append(join(dirname(self.hostpython_location), 'Lib'))

pythonforandroid/recipes/python3/__init__.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
check_all, is_api_lt, is_ndk)
55
from pythonforandroid.logger import logger, info
66
from pythonforandroid.util import ensure_dir, walk_valid_filens
7-
from os.path import exists, join, realpath, basename
7+
from os.path import exists, join, realpath, dirname
88
from os import environ, listdir, walk
99
import glob
1010
import sh
@@ -18,14 +18,21 @@
1818
'ensurepip',
1919
'idlelib',
2020
'tkinter',
21-
}
21+
}
2222

2323
STDLIB_FILEN_BLACKLIST = [
2424
'*.pyc',
2525
'*.exe',
2626
'*.whl',
27-
]
27+
]
2828

29+
# TODO: Move to a generic location so all recipes use the same blacklist
30+
SITE_PACKAGES_DIR_BLACKLIST = {
31+
'__pycache__',
32+
'tests'
33+
}
34+
35+
SITE_PACKAGES_FILEN_BLACKLIST = []
2936

3037

3138
class Python3Recipe(TargetPythonRecipe):
@@ -151,12 +158,19 @@ def create_python_bundle(self, dirn, arch):
151158
# zip up the standard library
152159
stdlib_zip = join(dirn, 'stdlib.zip')
153160
with current_directory(join(self.get_build_dir(arch.arch), 'Lib')):
154-
stdlib_filens = walk_valid_filens('.', STDLIB_DIR_BLACKLIST, STDLIB_FILEN_BLACKLIST)
161+
stdlib_filens = walk_valid_filens(
162+
'.', STDLIB_DIR_BLACKLIST, STDLIB_FILEN_BLACKLIST)
155163
shprint(sh.zip, stdlib_zip, *stdlib_filens)
156164

157165
# copy the site-packages into place
158-
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(),
159-
join(dirn, 'site-packages'))
166+
ensure_dir(join(dirn, 'site-packages'))
167+
# TODO: Improve the API around walking and copying the files
168+
with current_directory(self.ctx.get_python_install_dir()):
169+
filens = list(walk_valid_filens(
170+
'.', SITE_PACKAGES_DIR_BLACKLIST, SITE_PACKAGES_FILEN_BLACKLIST))
171+
for filen in filens:
172+
ensure_dir(join(dirn, 'site-packages', dirname(filen)))
173+
sh.cp(filen, join(dirn, 'site-packages', filen))
160174

161175
# copy the python .so files into place
162176
python_build_dir = join(self.get_build_dir(arch.arch),

pythonforandroid/util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ def walk_valid_filens(base_dir, invalid_dir_names, invalid_file_patterns):
140140
141141
"""
142142

143-
return_filens = []
144143
for dirn, subdirs, filens in walk(base_dir):
145144

146145
# Remove invalid subdirs so that they will not be walked

0 commit comments

Comments
 (0)