Skip to content

Commit e76aad9

Browse files
jtc0deinclement
jtc0de
authored andcommitted
Also copy the service/main.py when building with setup.py (kivy#1936)
1 parent 9e93257 commit e76aad9

File tree

1 file changed

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

1 file changed

+28
-8
lines changed

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,36 @@ def make_package(args):
321321
'full private data into .apk.')
322322
tar_dirs.append(args.private)
323323
else:
324-
print('Copying main.py ONLY, since other app data is '
325-
'expected in site-packages.')
324+
print("Copying main.py's ONLY, since other app data is "
325+
"expected in site-packages.")
326326
main_py_only_dir = tempfile.mkdtemp()
327327
_temp_dirs_to_clean.append(main_py_only_dir)
328-
if exists(join(args.private, "main.pyo")):
329-
shutil.copyfile(join(args.private, "main.pyo"),
330-
join(main_py_only_dir, "main.pyo"))
331-
elif exists(join(args.private, "main.py")):
332-
shutil.copyfile(join(args.private, "main.py"),
333-
join(main_py_only_dir, "main.py"))
328+
329+
# Check all main.py files we need to copy:
330+
copy_paths = ["main.py", join("service", "main.py")]
331+
for copy_path in copy_paths:
332+
variants = [
333+
copy_path,
334+
copy_path.partition(".")[0] + ".pyc",
335+
copy_path.partition(".")[0] + ".pyo",
336+
]
337+
# Check in all variants with all possible endings:
338+
for variant in variants:
339+
if exists(join(args.private, variant)):
340+
# Make sure surrounding directly exists:
341+
dir_path = os.path.dirname(variant)
342+
if (len(dir_path) > 0 and
343+
not exists(
344+
join(main_py_only_dir, dir_path)
345+
)):
346+
os.mkdir(join(main_py_only_dir, dir_path))
347+
# Copy actual file:
348+
shutil.copyfile(
349+
join(args.private, variant),
350+
join(main_py_only_dir, variant),
351+
)
352+
353+
# Append directory with all main.py's to result apk paths:
334354
tar_dirs.append(main_py_only_dir)
335355
for python_bundle_dir in ('private', '_python_bundle'):
336356
if exists(python_bundle_dir):

0 commit comments

Comments
 (0)