@@ -184,7 +184,7 @@ def select(fn):
184
184
zf .close ()
185
185
186
186
187
- def make_tar (tfn , source_dirs , ignore_path = []):
187
+ def make_tar (tfn , source_dirs , ignore_path = [], optimize_python = True ):
188
188
'''
189
189
Make a zip file `fn` from the contents of source_dis.
190
190
'''
@@ -205,7 +205,7 @@ def select(fn):
205
205
files = []
206
206
for sd in source_dirs :
207
207
sd = realpath (sd )
208
- compile_dir (sd )
208
+ compile_dir (sd , optimize_python = optimize_python )
209
209
files += [(x , relpath (realpath (x ), sd )) for x in listfiles (sd )
210
210
if select (x )]
211
211
@@ -233,7 +233,7 @@ def select(fn):
233
233
tf .close ()
234
234
235
235
236
- def compile_dir (dfn ):
236
+ def compile_dir (dfn , optimize_python = True ):
237
237
'''
238
238
Compile *.py in directory `dfn` to *.pyo
239
239
'''
@@ -244,7 +244,10 @@ def compile_dir(dfn):
244
244
# -OO = strip docstrings
245
245
if PYTHON is None :
246
246
return
247
- subprocess .call ([PYTHON , '-OO' , '-m' , 'compileall' , '-f' , dfn ])
247
+ args = [PYTHON , '-m' , 'compileall' , '-f' , dfn ]
248
+ if optimize_python :
249
+ args .insert (1 , '-OO' )
250
+ subprocess .call (args )
248
251
249
252
250
253
def make_package (args ):
@@ -283,10 +286,10 @@ def make_package(args):
283
286
tar_dirs .append (python_bundle_dir )
284
287
if get_bootstrap_name () == "webview" :
285
288
tar_dirs .append ('webview_includes' )
286
- if args .private :
287
- make_tar (join ( assets_dir , 'private.mp3' ), tar_dirs , args . ignore_path )
288
- elif args .launcher :
289
- make_tar ( join ( assets_dir , 'private.mp3' ), tar_dirs , args .ignore_path )
289
+ if args .private or args . launcher :
290
+ make_tar (
291
+ join ( assets_dir , 'private.mp3' ), tar_dirs , args .ignore_path ,
292
+ optimize_python = args .optimize_python )
290
293
291
294
# Prepare some variables for templating process
292
295
res_dir = "src/main/res"
@@ -644,6 +647,10 @@ def parse_args(args=None):
644
647
help = 'Set the launch mode of the main activity in the manifest.' )
645
648
ap .add_argument ('--allow-backup' , dest = 'allow_backup' , default = 'true' ,
646
649
help = "if set to 'false', then android won't backup the application." )
650
+ ap .add_argument ('--no-optimize-python' , dest = 'optimize_python' ,
651
+ action = 'store_false' , default = True ,
652
+ help = ('Whether to compile to optimised .pyo files, using -OO '
653
+ '(strips docstrings and asserts)' ))
647
654
648
655
# Put together arguments, and add those from .p4a config file:
649
656
if args is None :
0 commit comments