Skip to content

Commit 8d7b91b

Browse files
authored
Merge pull request kivy#944 from inclement/compile_pyo_with_sdl2
Compile pyo with sdl2
2 parents df84ca5 + 6d0cd30 commit 8d7b91b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pythonforandroid/bootstraps/sdl2/build/build.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
# Try to find a host version of Python that matches our ARM version.
3030
PYTHON = join(curdir, 'python-install', 'bin', 'python.host')
31+
if not exists(PYTHON):
32+
print('Could not find hostpython, will not compile to .pyo (this is normal with python3)')
33+
PYTHON = None
3134

3235
BLACKLIST_PATTERNS = [
3336
# code versionning
@@ -38,13 +41,14 @@
3841

3942
# pyc/py
4043
'*.pyc',
41-
# '*.py', # AND: Need to fix this to add it back
4244

4345
# temp files
4446
'~',
4547
'*.bak',
4648
'*.swp',
4749
]
50+
if PYTHON is not None:
51+
BLACKLIST_PATTERNS.append('*.py')
4852

4953
WHITELIST_PATTERNS = []
5054

@@ -202,9 +206,9 @@ def compile_dir(dfn):
202206
'''
203207
Compile *.py in directory `dfn` to *.pyo
204208
'''
205-
206-
return # AND: Currently leaving out the compile to pyo step because it's somehow broken
207209
# -OO = strip docstrings
210+
if PYTHON is None:
211+
return
208212
subprocess.call([PYTHON, '-OO', '-m', 'compileall', '-f', dfn])
209213

210214

@@ -370,7 +374,7 @@ def make_package(args):
370374

371375

372376
def parse_args(args=None):
373-
global BLACKLIST_PATTERNS, WHITELIST_PATTERNS
377+
global BLACKLIST_PATTERNS, WHITELIST_PATTERNS, PYTHON
374378
default_android_api = 12
375379
import argparse
376380
ap = argparse.ArgumentParser(description='''\
@@ -455,6 +459,8 @@ def parse_args(args=None):
455459
'NAME:PATH_TO_PY[:foreground]')
456460
ap.add_argument('--add-source', dest='extra_source_dirs', action='append',
457461
help='Include additional source dirs in Java build')
462+
ap.add_argument('--no-compile-pyo', dest='no_compile_pyo', action='store_true',
463+
help='Do not optimise .py files to .pyo.')
458464

459465
if args is None:
460466
args = sys.argv[1:]
@@ -480,6 +486,10 @@ def parse_args(args=None):
480486
if args.services is None:
481487
args.services = []
482488

489+
if args.no_compile_pyo:
490+
PYTHON = None
491+
BLACKLIST_PATTERNS.remove('*.py')
492+
483493
if args.blacklist:
484494
with open(args.blacklist) as fd:
485495
patterns = [x.strip() for x in fd.read().splitlines()

pythonforandroid/bootstraps/sdl2/build/src/org/kivy/android/PythonActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ protected void onCreate(Bundle savedInstanceState) {
8282
SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", "main.pyo");
8383
SDLActivity.nativeSetEnv("PYTHONHOME", app_root_dir);
8484
SDLActivity.nativeSetEnv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
85+
SDLActivity.nativeSetEnv("PYTHONOPTIMIZE", "2");
8586

8687
try {
8788
Log.v(TAG, "Access to our meta-data...");

0 commit comments

Comments
 (0)