|
23 | 23 | import jinja2 |
24 | 24 |
|
25 | 25 |
|
26 | | -def get_dist_info_for(key): |
| 26 | +def get_dist_info_for(key, error_if_missing=True): |
27 | 27 | try: |
28 | 28 | with open(join(dirname(__file__), 'dist_info.json'), 'r') as fileh: |
29 | 29 | info = json.load(fileh) |
30 | | - value = str(info[key]) |
| 30 | + value = info[key] |
31 | 31 | except (OSError, KeyError) as e: |
| 32 | + if not error_if_missing: |
| 33 | + return None |
32 | 34 | print("BUILD FAILURE: Couldn't extract the key `" + key + "` " + |
33 | 35 | "from dist_info.json: " + str(e)) |
34 | 36 | sys.exit(1) |
@@ -304,18 +306,45 @@ def make_package(args): |
304 | 306 | f.write("P4A_MINSDK=" + str(args.min_sdk_version) + "\n") |
305 | 307 |
|
306 | 308 | # Package up the private data (public not supported). |
| 309 | + use_setup_py = get_dist_info_for("use_setup_py", |
| 310 | + error_if_missing=False) is True |
307 | 311 | tar_dirs = [env_vars_tarpath] |
308 | | - if args.private: |
309 | | - tar_dirs.append(args.private) |
310 | | - for python_bundle_dir in ('private', 'crystax_python', '_python_bundle'): |
311 | | - if exists(python_bundle_dir): |
312 | | - tar_dirs.append(python_bundle_dir) |
313 | | - if get_bootstrap_name() == "webview": |
314 | | - tar_dirs.append('webview_includes') |
315 | | - if args.private or args.launcher: |
316 | | - make_tar( |
317 | | - join(assets_dir, 'private.mp3'), tar_dirs, args.ignore_path, |
318 | | - optimize_python=args.optimize_python) |
| 312 | + _temp_dirs_to_clean = [] |
| 313 | + try: |
| 314 | + if args.private: |
| 315 | + if not use_setup_py or ( |
| 316 | + not exists(join(args.private, "setup.py")) and |
| 317 | + not exists(join(args.private, "pyproject.toml")) |
| 318 | + ): |
| 319 | + print('No setup.py/pyproject.toml used, copying ' |
| 320 | + 'full private data into .apk.') |
| 321 | + tar_dirs.append(args.private) |
| 322 | + else: |
| 323 | + print('Copying main.py ONLY, since other app data is ' |
| 324 | + 'expected in site-packages.') |
| 325 | + main_py_only_dir = tempfile.mkdtemp() |
| 326 | + _temp_dirs_to_clean.append(main_py_only_dir) |
| 327 | + if exists(join(args.private, "main.pyo")): |
| 328 | + shutil.copyfile(join(args.private, "main.pyo"), |
| 329 | + join(main_py_only_dir, "main.pyo")) |
| 330 | + elif exists(join(args.private, "main.py")): |
| 331 | + shutil.copyfile(join(args.private, "main.py"), |
| 332 | + join(main_py_only_dir, "main.py")) |
| 333 | + tar_dirs.append(main_py_only_dir) |
| 334 | + for python_bundle_dir in ('private', |
| 335 | + 'crystax_python', |
| 336 | + '_python_bundle'): |
| 337 | + if exists(python_bundle_dir): |
| 338 | + tar_dirs.append(python_bundle_dir) |
| 339 | + if get_bootstrap_name() == "webview": |
| 340 | + tar_dirs.append('webview_includes') |
| 341 | + if args.private or args.launcher: |
| 342 | + make_tar( |
| 343 | + join(assets_dir, 'private.mp3'), tar_dirs, args.ignore_path, |
| 344 | + optimize_python=args.optimize_python) |
| 345 | + finally: |
| 346 | + for directory in _temp_dirs_to_clean: |
| 347 | + shutil.rmtree(directory) |
319 | 348 |
|
320 | 349 | # Remove extra env vars tar-able directory: |
321 | 350 | shutil.rmtree(env_vars_tarpath) |
@@ -361,9 +390,7 @@ def make_package(args): |
361 | 390 | version_code = 0 |
362 | 391 | if not args.numeric_version: |
363 | 392 | # Set version code in format (arch-minsdk-app_version) |
364 | | - with open(join(dirname(__file__), 'dist_info.json'), 'r') as dist_info: |
365 | | - dist_data = json.load(dist_info) |
366 | | - arch = dist_data["archs"][0] |
| 393 | + arch = get_dist_info_for("archs")[0] |
367 | 394 | arch_dict = {"x86_64": "9", "arm64-v8a": "8", "armeabi-v7a": "7", "x86": "6"} |
368 | 395 | arch_code = arch_dict.get(arch, '1') |
369 | 396 | min_sdk = args.min_sdk_version |
|
0 commit comments