2828
2929# Try to find a host version of Python that matches our ARM version.
3030PYTHON = 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
3235BLACKLIST_PATTERNS = [
3336 # code versionning
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
4953WHITELIST_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
372376def 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 ()
0 commit comments