8000 Added --no-optimize-python option to remove -OO in sdl2 bootstrap · alensiljak/python-for-android@4d71add · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d71add

Browse files
inclementAndreMiras
authored andcommitted
Added --no-optimize-python option to remove -OO in sdl2 bootstrap
1 parent ea9f346 commit 4d71add

File tree

1 file changed

+15
-8
lines changed
  • pythonforandroid/bootstraps/common/build

1 file changed

+15
-8
lines changed

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def select(fn):
184184
zf.close()
185185

186186

187-
def make_tar(tfn, source_dirs, ignore_path=[]):
187+
def make_tar(tfn, source_dirs, ignore_path=[], optimize_python=True):
188188
'''
189189
Make a zip file `fn` from the contents of source_dis.
190190
'''
@@ -205,7 +205,7 @@ def select(fn):
205205
files = []
206206
for sd in source_dirs:
207207
sd = realpath(sd)
208-
compile_dir(sd)
208+
compile_dir(sd, optimize_python=optimize_python)
209209
files += [(x, relpath(realpath(x), sd)) for x in listfiles(sd)
210210
if select(x)]
211211

@@ -233,7 +233,7 @@ def select(fn):
233233
tf.close()
234234

235235

236-
def compile_dir(dfn):
236+
def compile_dir(dfn, optimize_python=True):
237237
'''
238238
Compile *.py in directory `dfn` to *.pyo
239239
'''
@@ -244,7 +244,10 @@ def compile_dir(dfn):
244244
# -OO = strip docstrings
245245
if PYTHON is None:
246246
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)
248251

249252

250253
def make_package(args):
@@ -283,10 +286,10 @@ def make_package(args):
283286
tar_dirs.append(python_bundle_dir)
284287
if get_bootstrap_name() == "webview":
285288
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)
290293

291294
# Prepare some variables for templating process
292295
res_dir = "src/main/res"
@@ -644,6 +647,10 @@ def parse_args(args=None):
644647
help='Set the launch mode of the main activity in the manifest.')
645648
ap.add_argument('--allow-backup', dest='allow_backup', default='true',
646649
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)'))
647654

648655
# Put together arguments, and add those from .p4a config file:
649656
if args is None:

0 commit comments

Comments
 (0)
0