@@ -40,10 +40,6 @@ def get_hostpython():
40
40
return get_dist_info_for ('hostpython' )
41
41
42
42
43
- def get_python_version ():
44
- return get_dist_info_for ('python_version' )
45
-
46
-
47
43
def get_bootstrap_name ():
48
44
return get_dist_info_for ('bootstrap' )
49
45
@@ -58,7 +54,6 @@ def get_bootstrap_name():
58
54
curdir = dirname (__file__ )
59
55
60
56
PYTHON = get_hostpython ()
61
- PYTHON_VERSION = get_python_version ()
62
57
if PYTHON is not None and not exists (PYTHON ):
63
58
PYTHON = None
64
59
@@ -73,17 +68,16 @@ def get_bootstrap_name():
73
68
'~' ,
74
69
'*.bak' ,
75
70
'*.swp' ,
71
+
72
+ # Android artifacts
73
+ '*.apk' ,
74
+ '*.aab' ,
76
75
]
77
- # pyc/py
78
- if PYTHON is not None :
79
- BLACKLIST_PATTERNS .append ('*.py' )
80
76
81
77
WHITELIST_PATTERNS = []
82
78
if get_bootstrap_name () in ('sdl2' , 'webview' , 'service_only' ):
83
79
WHITELIST_PATTERNS .append ('pyconfig.h' )
84
80
85
- python_files = []
86
-
87
81
88
82
environment = jinja2 .Environment (loader = jinja2 .FileSystemLoader (
89
83
join (curdir , 'templates' )))
@@ -150,23 +144,11 @@ def listfiles(d):
150
144
yield fn
151
145
152
146
153
- def make_tar (tfn , source_dirs , ignore_path = [] , optimize_python = True ):
147
+ def make_tar (tfn , source_dirs , byte_compile_python = False , optimize_python = True ):
154
148
'''
155
149
Make a zip file `fn` from the contents of source_dis.
156
150
'''
157
151
158
- # selector function
159
- def select (fn ):
160
- rfn = realpath (fn )
161
- for p in ignore_path :
162
- if p .endswith ('/' ):
163
- p = p [:- 1 ]
164
- if rfn .startswith (p ):
165
- return False
166
- if rfn in python_files :
167
- return False
168
- return not is_blacklist (fn )
169
-
170
152
def clean (tinfo ):
171
153
"""cleaning function (for reproducible builds)"""
172
154
tinfo .uid = tinfo .gid = 0
@@ -178,9 +160,12 @@ def clean(tinfo):
178
160
files = []
179
161
for sd in source_dirs :
180
162
sd = realpath (sd )
181
- compile_dir (sd , optimize_python = optimize_python )
182
- files += [(x , relpath (realpath (x ), sd )) for x in listfiles (sd )
183
- if select (x )]
163
+ for fn in listfiles (sd ):
164
+ if is_blacklist (fn ):
165
+ continue
166
+ if fn .endswith ('.py' ) and byte_compile_python :
167
+ fn = compile_py_file (fn , optimize_python = optimize_python )
168
+ files .append ((fn , relpath (realpath (fn ), sd )))
184
169
files .sort () # deterministic
185
170
186
171
# create tar.gz of thoses files
@@ -210,18 +195,15 @@ def clean(tinfo):
210
195
gf .close ()
211
196
212
197
213
- def compile_dir ( dfn , optimize_python = True ):
198
+ def compile_py_file ( python_file , optimize_python = True ):
214
199
'''
215
- Compile *.py in directory `dfn` to *.pyo
200
+ Compile python_file to *.pyc and return the filename of the *.pyc file.
216
201
'''
217
202
218
203
if PYTHON is None :
219
204
return
220
205
221
- if int (PYTHON_VERSION [0 ]) >= 3 :
222
- args = [PYTHON , '-m' , 'compileall' , '-b' , '-f' , dfn ]
223
- else :
224
- args = [PYTHON , '-m' , 'compileall' , '-f' , dfn ]
206
+ args = [PYTHON , '-m' , 'compileall' , '-b' , '-f' , python_file ]
225
207
if optimize_python :
226
208
# -OO = strip docstrings
227
209
args .insert (1 , '-OO' )
@@ -233,16 +215,18 @@ def compile_dir(dfn, optimize_python=True):
233
215
'error, see logs above' )
234
216
exit (1 )
235
217
218
+ return "." .join ([os .path .splitext (python_file )[0 ], "pyc" ])
219
+
236
220
237
221
def make_package (args ):
238
- # If no launcher is specified, require a main.py/main.pyo :
222
+ # If no launcher is specified, require a main.py/main.pyc :
239
223
if (get_bootstrap_name () != "sdl" or args .launcher is None ) and \
240
224
get_bootstrap_name () not in ["webview" , "service_library" ]:
241
225
# (webview doesn't need an entrypoint, apparently)
242
226
if args .private is None or (
243
227
not exists (join (realpath (args .private ), 'main.py' )) and
244
- not exists (join (realpath (args .private ), 'main.pyo ' ))):
245
- print ('''BUILD FAILURE: No main.py(o ) found in your app directory. This
228
+ not exists (join (realpath (args .private ), 'main.pyc ' ))):
229
+ print ('''BUILD FAILURE: No main.py(c ) found in your app directory. This
246
230
file must exist to act as the entry point for you app. If your app is
247
231
started by a file with a different name, rename it to main.py or add a
248
232
main.py that loads it.''' )
@@ -290,7 +274,6 @@ def make_package(args):
290
274
variants = [
291
275
copy_path ,
292
276
copy_path .partition ("." )[0 ] + ".pyc" ,
293
- copy_path .partition ("." )[0 ] + ".pyo" ,
294
277
]
295
278
# Check in all variants with all possible endings:
296
279
for variant in variants :
@@ -326,11 +309,17 @@ def make_package(args):
326
309
for arch in get_dist_info_for ("archs" ):
327
310
libs_dir = f"libs/{ arch } "
328
311
make_tar (
329
- join (libs_dir , 'libpybundle.so' ), [f'_python_bundle__{ arch } ' ], args .ignore_path ,
330
- optimize_python = args .optimize_python )
312
+ join (libs_dir , "libpybundle.so" ),
313
+ [f"_python_bundle__{ arch } " ],
314
+ byte_compile_python = args .byte_compile_python ,
315
+ optimize_python = args .optimize_python ,
316
+ )
331
317
make_tar (
332
- join (assets_dir , 'private.tar' ), private_tar_dirs , args .ignore_path ,
333
- optimize_python = args .optimize_python )
318
+ join (assets_dir , "private.tar" ),
319
+ private_tar_dirs ,
320
+ byte_compile_python = args .byte_compile_python ,
321
+ optimize_python = args .optimize_python ,
322
+ )
334
323
finally :
335
324
for directory in _temp_dirs_to_clean :
336
325
shutil .rmtree (directory )
@@ -824,8 +813,6 @@ def parse_args_and_make_package(args=None):
824
813
ap .add_argument ('--try-system-python-compile' , dest = 'try_system_python_compile' ,
825
814
action = 'store_true' ,
826
815
help = 'Use the system python during compileall if possible.' )
827
- ap .add_argument ('--no-compile-pyo' , dest = 'no_compile_pyo' , action = 'store_true' ,
828
- help = 'Do not optimise .py files to .pyo.' )
829
816
ap .add_argument ('--sign' , action = 'store_true' ,
830
817
help = ('Try to sign the APK with your credentials. You must set '
831
818
'the appropriate environment variables.' ))
@@ -844,9 +831,12 @@ def parse_args_and_make_package(args=None):
844
831
'files (containing your main.py entrypoint). '
845
832
'See https://developer.android.com/guide/topics/data/'
846
833
'autobackup#IncludingFiles for more information' ))
834
+ ap .add_argument ('--no-byte-compile-python' , dest = 'byte_compile_python' ,
835
+ action = 'store_false' , default = True ,
836
+ help = 'Skip byte compile for .py files.' )
847
837
ap .add_argument ('--no-optimize-python' , dest = 'optimize_python' ,
848
838
action = 'store_false' , default = True ,
849
- help = ('Whether to compile to optimised .pyo files, using -OO '
839
+ help = ('Whether to compile to optimised .pyc files, using -OO '
850
840
'(strips docstrings and asserts)' ))
851
841
ap .add_argument ('--extra-manifest-xml' , default = '' ,
852
842
help = ('Extra xml to write directly inside the <manifest> element of'
@@ -881,8 +871,6 @@ def _read_configuration():
881
871
882
872
args = ap .parse_args (args )
883
873
884
- args .ignore_path = []
885
-
886
874
if args .name and args .name [0 ] == '"' and args .name [- 1 ] == '"' :
887
875
args .name = args .name [1 :- 1 ]
888
876
@@ -925,10 +913,6 @@ def _read_configuration():
925
913
else :
926
914
PYTHON = python_executable
927
915
928
- if args .no_compile_pyo :
929
- PYTHON = None
930
- BLACKLIST_PATTERNS .remove ('*.py' )
931
-
932
916
if args .blacklist :
933
917
with open (args .blacklist ) as fd :
934
918
patterns = [x .strip () for x in fd .read ().splitlines ()
0 commit comments