Skip to content

Commit ecd0bf6

Browse files
authored
Merge pull request kivy#1401 from AndreMiras/feature/ticket1382_conditional_builds
Conditional recipe build fixes kivy#1382
2 parents 1c5b3aa + 7dd7d17 commit ecd0bf6

File tree

7 files changed

+150
-17
lines changed

7 files changed

+150
-17
lines changed

.travis.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,27 @@ services:
66
- docker
77

88
before_install:
9-
- sudo apt-get update -qq
10-
- sudo apt-get install -qq python2.7 python3
9+
- sudo apt update -qq
10+
- sudo apt install -qq python2.7 python3
1111
- sudo pip install tox>=2.0
12+
# https://github.com/travis-ci/travis-ci/issues/6069#issuecomment-266546552
13+
- git remote set-branches --add origin master
14+
- git fetch
1215

1316
env:
14-
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python2.py apk --sdk-dir /opt/android/android-sdk --ndk-dir /opt/android/android-ndk'
15-
# overrides requirements to skip `peewee` pure python module, see:
16-
# https://github.com/kivy/python-for-android/issues/1263#issuecomment-390421054
17-
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python2_sqlite_openssl.py apk --sdk-dir /opt/android/android-sdk --ndk-dir /opt/android/android-ndk --requirements sdl2,pyjnius,kivy,python2,openssl,requests,sqlite3,setuptools'
18-
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python2.py apk --sdk-dir /opt/android/android-sdk --ndk-dir /opt/android/android-ndk --bootstrap sdl2 --requirements python2,numpy'
19-
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python3.py apk --sdk-dir /opt/android/android-sdk --ndk-dir /opt/android/crystax-ndk'
20-
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python3.py apk --sdk-dir /opt/android/android-sdk --ndk-dir /opt/android/crystax-ndk --requirements python3crystax,setuptools,android'
17+
global:
18+
- ANDROID_SDK_HOME=/opt/android/android-sdk
19+
- ANDROID_NDK_HOME=/opt/android/android-ndk
20+
- CRYSTAX_NDK_HOME=/opt/android/crystax-ndk
21+
matrix:
22+
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python2.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME'
23+
# overrides requirements to skip `peewee` pure python module, see:
24+
# https://github.com/kivy/python-for-android/issues/1263#issuecomment-390421054
25+
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python2_sqlite_openssl.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --requirements sdl2,pyjnius,kivy,python2,openssl,requests,sqlite3,setuptools'
26+
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python2.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --bootstrap sdl2 --requirements python2,numpy'
27+
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python3.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $CRYSTAX_NDK_HOME --requirements python3crystax,setuptools,android,sdl2,pyjnius,kivy'
28+
# builds only the recipes that moved
29+
- COMMAND='. venv/bin/activate && ./ci/rebuild_updated_recipes.py'
2130

2231
before_script:
2332
# we want to fail fast on tox errors without having to `docker build` first

ci/__init__.py

Whitespace-only changes.

ci/rebuild_updated_recipes.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Continuous Integration helper script.
5+
Automatically detects recipes modified in a changeset (compares with master)
6+
and recompiles them.
7+
8+
To run locally, set the environment variables before running:
9+
```
10+
ANDROID_SDK_HOME=~/.buildozer/android/platform/android-sdk-20
11+
ANDROID_NDK_HOME=~/.buildozer/android/platform/android-ndk-r9c
12+
CRYSTAX_NDK_HOME=~/.buildozer/crystax-ndk
13+
./ci/rebuild_update_recipes.py
14+
```
15+
16+
Current limitations:
17+
- handle the case with conflicting requirements
18+
e.g. https://travis-ci.org/AndreMiras/python-for-android/builds/438840800
19+
the list was huge and result was:
20+
[ERROR]: Didn't find any valid dependency graphs.
21+
[ERROR]: This means that some of your requirements pull in conflicting dependencies.
22+
- currently only builds on target python3crystax (even though python2 is supported)
23+
- comprehensive list of working/broken recipes is not yet known
24+
- only rebuilds on sdl2 bootstrap
25+
"""
26+
import sh
27+
import os
28+
from enum import Enum
29+
from pythonforandroid.toolchain import current_directory
30+
31+
32+
class TargetPython(Enum):
33+
python2 = 0
34+
python3crystax = 1
35+
36+
37+
# recipes that currently break the build
38+
# a recipe could be broken for a target Python and not for the other,
39+
# hence we're maintaining one list per Python target
40+
BROKEN_RECIPES_PYTHON2 = set([])
41+
BROKEN_RECIPES_PYTHON3_CRYSTAX = set([
42+
# not yet python3crystax compatible
43+
'apsw', 'atom', 'boost', 'brokenrecipe', 'cdecimal', 'cherrypy',
44+
'coverage',
45+
# https://github.com/kivy/python-for-android/issues/550
46+
'audiostream',
47+
# enum34 is not compatible with Python 3.6 standard library
48+
# https://stackoverflow.com/a/45716067/185510
49+
'enum34',
50+
# https://github.com/kivy/python-for-android/issues/1398
51+
'ifaddrs',
52+
# https://github.com/kivy/python-for-android/issues/1399
53+
'libglob',
54+
# cannot find -lcrystax
55+
'cffi',
56+
])
57+
BROKEN_RECIPES = {
58+
TargetPython.python2: BROKEN_RECIPES_PYTHON2,
59+
TargetPython.python3crystax: BROKEN_RECIPES_PYTHON3_CRYSTAX,
60+
}
61+
# recipes that are were already built
62+
CORE_RECIPES = set([
63+
'pyjnius', 'kivy', 'openssl', 'requests', 'sqlite3', 'setuptools',
64+
'numpy', 'android',
65+
])
66+
67+
68+
def modified_recipes(branch='origin/master'):
69+
"""
70+
Returns a set of modified recipes between the current branch and the one
71+
in param.
72+
"""
73+
# using the contrib version on purpose rather than sh.git, since it comes
74+
# with a bunch of fixes, e.g. disabled TTY, see:
75+
# https://stackoverflow.com/a/20128598/185510
76+
git_diff = sh.contrib.git.diff('--name-only', branch)
77+
recipes = set()
78+
for file_path in git_diff:
79+
if 'pythonforandroid/recipes/' in file_path:
80+
recipe = file_path.split('/')[2]
81+
recipes.add(recipe)
82+
return recipes
83+
84+
85+
def build(target_python, requirements):
86+
"""
87+
Builds an APK given a target Python and a set of requirements.
88+
"""
89+
if not requirements:
90+
return
91+
testapp = 'setup_testapp_python2.py'
92+
android_sdk_home = os.environ['ANDROID_SDK_HOME']
93+
android_ndk_home = os.environ['ANDROID_NDK_HOME']
94+
crystax_ndk_home = os.environ['CRYSTAX_NDK_HOME']
95+
if target_python == TargetPython.python3crystax:
96+
android_ndk_home = crystax_ndk_home
97+
testapp = 'setup_testapp_python3.py'
98+
requirements.add(target_python.name)
99+
requirements = ','.join(requirements)
100+
print('requirements:', requirements)
101+
with current_directory('testapps/'):
102+
try:
103+
for line in sh.python(
104+
testapp, 'apk', '--sdk-dir', android_sdk_home,
105+
'--ndk-dir', android_ndk_home, '--bootstrap', 'sdl2', '--requirements',
106+
requirements, _err_to_out=True, _iter=True):
107+
print(line)
108+
except sh.ErrorReturnCode as e:
109+
raise
110+
111+
112+
def main():
113+
target_python = TargetPython.python3crystax
114+
recipes = modified_recipes()
115+
print('recipes modified:', recipes)
116+
broken_recipes = BROKEN_RECIPES[target_python]
117+
recipes = recipes - (CORE_RECIPES | broken_recipes)
118+
print('recipes to build:', recipes)
119+
build(target_python, recipes)
120+
print(recipes)
121+
122+
123+
if __name__ == '__main__':
124+
main()

pythonforandroid/recipes/babel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class BabelRecipe(PythonRecipe):
55
name = 'babel'
6-
version = '2.1.1'
6+
version = '2.2.0'
77
url = 'https://pypi.python.org/packages/source/B/Babel/Babel-{version}.tar.gz'
88

99
depends = [('python2', 'python3crystax'), 'setuptools', 'pytz']

pythonforandroid/recipes/cffi/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
class CffiRecipe(CompiledComponentsPythonRecipe):
6+
"""
7+
Extra system dependencies: autoconf, automake and libtool.
8+
"""
69
name = 'cffi'
710
version = '1.4.2'
811
url = 'https://pypi.python.org/packages/source/c/cffi/cffi-{version}.tar.gz'

setup.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
data_files = []
1717

1818

19-
if os.name == 'nt':
20-
install_reqs = ['appdirs', 'colorama>=0.3.3', 'jinja2',
21-
'six']
22-
else:
23-
install_reqs = ['appdirs', 'colorama>=0.3.3', 'sh>=1.10', 'jinja2',
24-
'six']
19+
install_reqs = ['appdirs', 'colorama>=0.3.3', 'jinja2', 'six', 'enum34']
20+
if os.name != 'nt':
21+
install_reqs.append('sh>=1.10')
2522

2623
# By specifying every file manually, package_data will be able to
2724
# include them in binary distributions. Note that we have to add

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ commands = pytest {posargs:tests/}
1111

1212
[testenv:pep8]
1313
deps = flake8
14-
commands = flake8 pythonforandroid/ tests/
14+
commands = flake8 pythonforandroid/ tests/ ci/
1515

1616
[flake8]
1717
ignore =

0 commit comments

Comments
 (0)