Allow setting custom p4a URL instead of fork (#1305)

* Allow setting custom p4a URL instead of fork

* Apply suggestions from code review

Co-authored-by: Pol Canelles <canellestudi@gmail.com>

* Add tests for p4a clone URL

Co-authored-by: Pol Canelles <canellestudi@gmail.com>
This commit is contained in:
Kostiantyn Syrykh 2021-03-14 11:47:27 +02:00 committed by GitHub
parent d2944ad54c
commit 1a3fb61b37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 12 deletions

View file

@ -251,7 +251,10 @@ android.allow_backup = True
# Python for android (p4a) specific
#
# (str) python-for-android fork to use, defaults to upstream (kivy)
# (str) python-for-android URL to use for checkout
#p4a.url =
# (str) python-for-android fork to use in case if p4a.url is not specified, defaults to upstream (kivy)
#p4a.fork = kivy
# (str) python-for-android branch to use, defaults to master

View file

@ -692,6 +692,9 @@ class TargetAndroid(Target):
p4a_fork = self.buildozer.config.getdefault(
'app', 'p4a.fork', self.p4a_fork
)
p4a_url = self.buildozer.config.getdefault(
'app', 'p4a.url', f'https://github.com/{p4a_fork}/python-for-android.git'
)
p4a_branch = self.buildozer.config.getdefault(
'app', 'p4a.branch', self.p4a_branch
)
@ -707,21 +710,19 @@ class TargetAndroid(Target):
self.buildozer.error('')
raise BuildozerException()
else:
# check that fork/branch has not been changed
# check that url/branch has not been changed
if self.buildozer.file_exists(p4a_dir):
cur_fork = cmd(
cur_url = cmd(
'git config --get remote.origin.url',
get_stdout=True,
cwd=p4a_dir,
)[0].split('/')[3]
)[0].strip()
cur_branch = cmd(
'git branch -vv', get_stdout=True, cwd=p4a_dir
)[0].split()[1]
if any([cur_fork != p4a_fork, cur_branch != p4a_branch]):
if any([cur_url != p4a_url, cur_branch != p4a_branch]):
self.buildozer.info(
"Detected old fork/branch ({}/{}), deleting...".format(
cur_fork, cur_branch
)
f"Detected old url/branch ({cur_url}/{cur_branch}), deleting..."
)
rmtree(p4a_dir)
@ -729,11 +730,10 @@ class TargetAndroid(Target):
cmd(
(
'git clone -b {p4a_branch} --single-branch '
'https://github.com/{p4a_fork}/python-for-android.git '
'{p4a_dir}'
'{p4a_url} {p4a_dir}'
).format(
p4a_branch=p4a_branch,
p4a_fork=p4a_fork,
p4a_url=p4a_url,
p4a_dir=self.p4a_directory_name,
),
cwd=self.buildozer.platform_dir,

View file

@ -1,5 +1,6 @@
import os
import tempfile
from six import StringIO
from unittest import mock
import pytest
@ -350,3 +351,44 @@ class TestTargetAndroid:
]
)
]
def test_install_platform_p4a_clone_url(self):
"""The `p4a.url` config should be used for cloning p4a before the `p4a.fork` option."""
target_android = init_target(self.temp_dir, {
'p4a.url': 'https://custom-p4a-url/p4a.git',
'p4a.fork': 'myfork',
})
with patch_buildozer_cmd() as m_cmd, mock.patch('buildozer.targets.android.open') as m_open:
m_open.return_value = StringIO('install_reqs = []') # to stub setup.py parsing
target_android._install_p4a()
assert mock.call(
'git clone -b master --single-branch https://custom-p4a-url/p4a.git python-for-android',
cwd=mock.ANY) in m_cmd.call_args_list
def test_install_platform_p4a_clone_fork(self):
"""The `p4a.fork` config should be used for cloning p4a."""
target_android = init_target(self.temp_dir, {
'p4a.fork': 'fork'
})
with patch_buildozer_cmd() as m_cmd, mock.patch('buildozer.targets.android.open') as m_open:
m_open.return_value = StringIO('install_reqs = []') # to stub setup.py parsing
target_android._install_p4a()
assert mock.call(
'git clone -b master --single-branch https://github.com/fork/python-for-android.git python-for-android',
cwd=mock.ANY) in m_cmd.call_args_list
def test_install_platform_p4a_clone_default(self):
"""The default URL should be used for cloning p4a if no config options `p4a.url` and `p4a.fork` are set."""
target_android = init_target(self.temp_dir)
with patch_buildozer_cmd() as m_cmd, mock.patch('buildozer.targets.android.open') as m_open:
m_open.return_value = StringIO('install_reqs = []') # to stub setup.py parsing
target_android._install_p4a()
assert mock.call(
'git clone -b master --single-branch https://github.com/kivy/python-for-android.git python-for-android',
cwd=mock.ANY) in m_cmd.call_args_list

View file

@ -53,7 +53,7 @@ def init_buildozer(temp_dir, target, options=None):
spec = []
for line in default_spec:
if line.strip():
match = re.search(r"[#\s]?([a-z_\.]+)", line)
match = re.search(r"[#\s]?([0-9a-z_.]+)", line)
key = match and match.group(1)
if key in options:
line = "{} = {}\n".format(key, options[key])