Skip to content

Also copy the service/main.py when building with setup.py #1936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Aug 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,36 @@ def make_package(args):
'full private data into .apk.')
tar_dirs.append(args.private)
else:
print('Copying main.py ONLY, since other app data is '
'expected in site-packages.')
print("Copying main.py's ONLY, since other app data is "
"expected in site-packages.")
main_py_only_dir = tempfile.mkdtemp()
_temp_dirs_to_clean.append(main_py_only_dir)
if exists(join(args.private, "main.pyo")):
shutil.copyfile(join(args.private, "main.pyo"),
join(main_py_only_dir, "main.pyo"))
elif exists(join(args.private, "main.py")):
shutil.copyfile(join(args.private, "main.py"),
join(main_py_only_dir, "main.py"))

# Check all main.py files we need to copy:
copy_paths = ["main.py", join("service", "main.py")]
for copy_path in copy_paths:
variants = [
copy_path,
copy_path.partition(".")[0] + ".pyc",
copy_path.partition(".")[0] + ".pyo",
]
# Check in all variants with all possible endings:
for variant in variants:
if exists(join(args.private, variant)):
# Make sure surrounding directly exists:
dir_path = os.path.dirname(variant)
if (len(dir_path) > 0 and
not exists(
join(main_py_only_dir, dir_path)
)):
os.mkdir(join(main_py_only_dir, dir_path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: What about creating the dir yes or yes? You know like mkdir -p so we can skip the if?
e.g.

os.mkdir(join(main_py_only_dir, dir_path), exist_ok=True)

Copy link
Author

@ghost ghost Aug 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trained to avoid this because of Python 2. Are we sure this code doesn't run in Python 2 when deploying for Python 2 android targets even with Python 3 host? It might be ok but I haven't tested just yet, and that's why I usually just avoid Python 3-only things

Edit: (this is more of an explanation of my behavior, not really a good reason/excuse of course)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I see, let's play it safe then 👍
Even though I don't really mind Python2 being broken :trollface:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also ensure_dir in util.py, which I used to use for this.

Copy link
Author

@ghost ghost Aug 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm my intuition is to stick more to standard functions for readability, especially since this will solve itself once we drop Python 2 entirely also as a target (which I assume we will do eventually?)

Edit: but as usual, happy to follow you guys' opinion on this

# Copy actual file:
shutil.copyfile(
join(args.private, variant),
join(main_py_only_dir, variant),
)

# Append directory with all main.py's to result apk paths:
tar_dirs.append(main_py_only_dir)
for python_bundle_dir in ('private', '_python_bundle'):
if exists(python_bundle_dir):
Expand Down