Skip to content

Commit 692ac31

Browse files
authored
Merge branch 'master' into update_contributing_doc
2 parents 3a71b95 + 1d375fb commit 692ac31

File tree

9 files changed

+98
-34
lines changed

9 files changed

+98
-34
lines changed

.coveragerc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[run]
2+
omit =
3+
*test*
4+
5+
[report]
6+
exclude_lines =
7+
pragma: no cover
8+
def __repr__
9+
raise NotImplementedError
10+
if __name__ == .__main__.:

.travis.yml

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@ dist: xenial # needed for more recent python 3 and python3-venv
44

55
language: generic
66

7+
stages:
8+
- lint
9+
- test
10+
711
services:
812
- docker
913

1014
before_install:
1115
- travis_retry sudo apt update -qq
12-
- travis_retry sudo apt install -qq --no-install-recommends python2.7 python3 python3-venv python3-virtualenv
16+
# to successfully send the coveralls reports we need pyOpenSSL
17+
- travis_retry sudo apt install -qq --no-install-recommends
18+
python2.7 python3 python3-venv python3-virtualenv python3-pip
19+
python3-setuptools python3-openssl
1320
# (venv/virtualenv are both used by tests/test_pythonpackage.py)
1421
- sudo pip install tox>=2.0
22+
- sudo pip3 install coveralls
1523
# https://github.com/travis-ci/travis-ci/issues/6069#issuecomment-266546552
1624
- git remote set-branches --add origin master
1725
- git fetch
@@ -20,25 +28,42 @@ env:
2028
global:
2129
- ANDROID_SDK_HOME=/opt/android/android-sdk
2230
- ANDROID_NDK_HOME=/opt/android/android-ndk
23-
matrix:
24-
- COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python3_sqlite_openssl.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --requirements libffi,sdl2,pyjnius,kivy,python3,openssl,requests,sqlite3,setuptools'
25-
# overrides requirements to skip `peewee` pure python module, see:
26-
# https://github.com/kivy/python-for-android/issues/1263#issuecomment-390421054
27-
- 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'
28-
- 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'
29-
# builds only the recipes that moved
30-
- COMMAND='. venv/bin/activate && ./ci/rebuild_updated_recipes.py'
31-
32-
before_script:
33-
# we want to fail fast on tox errors without having to `docker build` first
34-
- tox -- tests/ --ignore tests/test_pythonpackage.py
35-
# (we ignore test_pythonpackage.py since these run way too long!! test_pythonpackage_basic.py will still be run.)
36-
37-
script:
38-
# Run a background process to make sure that travis will not kill our tests in
39-
# case that the travis log doesn't produce any output for more than 10 minutes
40-
- while sleep 540; do echo "==== Still running (travis, don't kill me) ===="; done &
41-
- docker build --tag=p4a --file Dockerfile.py3 .
42-
- docker run -e CI p4a /bin/sh -c "$COMMAND"
43-
# kill the background process started before run docker
44-
- kill %1
31+
32+
jobs:
33+
include:
34+
- stage: lint
35+
name: "Tox tests and coverage"
36+
script:
37+
# we want to fail fast on tox errors without having to `docker build` first
38+
- tox -- tests/ --ignore tests/test_pythonpackage.py
39+
# (we ignore test_pythonpackage.py since these run way too long!!
40+
# test_pythonpackage_basic.py will still be run.)
41+
after_success:
42+
- coveralls
43+
44+
- &testing
45+
stage: test
46+
before_script:
47+
# build docker image
48+
- docker build --tag=p4a --file Dockerfile.py3 .
49+
# Run a background process to make sure that travis will not kill our tests in
50+
# case that the travis log doesn't produce any output for more than 10 minutes
51+
- while sleep 540; do echo "==== Still running (travis, don't kill me) ===="; done &
52+
script:
53+
- docker run -e CI -e TRAVIS_JOB_ID="$TRAVIS_JOB_ID" -e TRAVIS_BRANCH="$TRAVIS_BRANCH" p4a /bin/sh -c "$COMMAND"
54+
after_script:
55+
# kill the background process started before run docker
56+
- kill %1
57+
name: Python 3 basic
58+
# overrides requirements to skip `peewee` pure python module, see:
59+
# https://github.com/kivy/python-for-android/issues/1263#issuecomment-390421054
60+
env: COMMAND='. venv/bin/activate && cd testapps/ && python setup_testapp_python3_sqlite_openssl.py apk --sdk-dir $ANDROID_SDK_HOME --ndk-dir $ANDROID_NDK_HOME --requirements libffi,sdl2,pyjnius,kivy,python3,openssl,requests,sqlite3,setuptools'
61+
- <<: *testing
62+
name: Python 2 basic
63+
env: 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'
64+
- <<: *testing
65+
name: Python 2 numpy
66+
env: 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'
67+
- <<: *testing
68+
name: Rebuild updated recipes
69+
env: COMMAND='. venv/bin/activate && ./ci/rebuild_updated_recipes.py'

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ python-for-android
22
==================
33

44
[![Build Status](https://travis-ci.org/kivy/python-for-android.svg?branch=master)](https://travis-ci.org/kivy/python-for-android)
5-
[![Backers on Open Collective](https://opencollective.com/kivy/backers/badge.svg)](#backers)
6-
[![Sponsors on Open Collective](https://opencollective.com/kivy/sponsors/badge.svg)](#sponsors)
5+
[![Coverage Status](https://coveralls.io/repos/github/kivy/python-for-android/badge.svg?branch=master&kill_cache=1)](https://coveralls.io/github/kivy/python-for-android?branch=master)
6+
[![Backers on Open Collective](https://opencollective.com/kivy/backers/badge.svg)](#backers)
7+
[![Sponsors on Open Collective](https://opencollective.com/kivy/sponsors/badge.svg)](#sponsors)
78

89
python-for-android is a packager for Python apps on Android. You can
910
create your own Python distribution including the modules and

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonService.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
import org.renpy.android.Hardware;
2020

21+
//imports for channel definition
22+
import android.app.NotificationManager;
23+
import android.app.NotificationChannel;
24+
import android.graphics.Color;
2125

2226
public class PythonService extends Service implements Runnable {
2327

@@ -90,13 +94,13 @@ public int onStartCommand(Intent intent, int flags, int startId) {
9094
protected void doStartForeground(Bundle extras) {
9195
String serviceTitle = extras.getString("serviceTitle");
9296
String serviceDescription = extras.getString("serviceDescription");
93-
9497
Notification notification;
9598
Context context = getApplicationContext();
9699
Intent contextIntent = new Intent(context, PythonActivity.class);
97100
PendingIntent pIntent = PendingIntent.getActivity(context, 0, contextIntent,
98101
PendingIntent.FLAG_UPDATE_CURRENT);
99-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
102+
103+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
100104
notification = new Notification(
101105
context.getApplicationInfo().icon, serviceTitle, System.currentTimeMillis());
102106
try {
@@ -109,7 +113,19 @@ protected void doStartForeground(Bundle extras) {
109113
IllegalArgumentException | InvocationTargetException e) {
110114
}
111115
} else {
112-
Notification.Builder builder = new Notification.Builder(context);
116+
// for android 8+ we need to create our own channel
117+
// https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1
118+
String NOTIFICATION_CHANNEL_ID = "org.kivy.p4a"; //TODO: make this configurable
119+
String channelName = "PythonSerice"; //TODO: make this configurable
120+
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName,
121+
NotificationManager.IMPORTANCE_NONE);
122+
123+
chan.setLightColor(Color.BLUE);
124+
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
125+
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
126+
manager.createNotificationChannel(chan);
127+
128+
Notification.Builder builder = new Notification.Builder(context, NOTIFICATION_CHANNEL_ID);
113129
builder.setContentTitle(serviceTitle);
114130
builder.setContentText(serviceDescription);
115131
builder.setContentIntent(pIntent);

pythonforandroid/bootstraps/service_only/build/templates/AndroidManifest.tmpl.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@
7171

7272
{% if service %}
7373
<service android:name="org.kivy.android.PythonService"
74-
android:process=":pythonservice" />
74+
android:process=":pythonservice"
75+
android:exported="true"/>
7576
{% endif %}
7677
{% for name in service_names %}
7778
<service android:name="{{ args.package }}.Service{{ name|capitalize }}"
78-
android:process=":service_{{ name }}" />
79+
android:process=":service_{{ name }}"
80+
android:exported="true" />
7981
{% endfor %}
8082

8183
{% if args.billing_pubkey %}

pythonforandroid/bootstraps/service_only/build/templates/Service.tmpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Service{{ name|capitalize }} extends PythonService {
1717
* {@inheritDoc}
1818
*/
1919
@Override
20-
public int getStartType() {
20+
public int startType() {
2121
return START_STICKY;
2222
}
2323
{% endif %}

pythonforandroid/recipes/android/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ def prebuild_arch(self, arch):
3838
bootstrap = bootstrap_name = ctx_bootstrap
3939

4040
is_sdl2 = bootstrap_name in ('sdl2', 'sdl2python3', 'sdl2_gradle')
41-
is_webview = bootstrap_name in ('webview',)
41+
is_webview = bootstrap_name == 'webview'
42+
is_service_only = bootstrap_name == 'service_only'
4243

43-
if is_sdl2 or is_webview:
44+
if is_sdl2 or is_webview or is_service_only:
4445
if is_sdl2:
4546
bootstrap = 'sdl2'
4647
java_ns = u'org.kivy.android'

testapps/setup_testapp_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
'blacklist-requirements': 'openssl,sqlite3',
88
'android-api': 27,
99
'ndk-api': 21,
10-
'ndk-dir': '/home/asandy/android/crystax-ndk-10.3.2',
10+
'sdk-dir':'/opt/android/android-sdk/',
11+
'ndk-dir':'/opt/android/android-ndk-r17c/',
1112
'dist-name': 'testapp_service',
1213
'ndk-version': '10.3.2',
1314
'bootstrap': 'service_only',

tox.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ deps =
77
mock
88
pytest
99
virtualenv
10+
py3: coveralls
1011
# makes it possible to override pytest args, e.g.
1112
# tox -- tests/test_graph.py
1213
commands = pytest {posargs:tests/}
14+
passenv = TRAVIS TRAVIS_*
1315
setenv =
1416
PYTHONPATH={toxinidir}
1517

18+
[testenv:py3]
19+
# for py3 env we will get code coverage
20+
commands =
21+
coverage run --branch --source=pythonforandroid -m pytest {posargs:tests/}
22+
coverage report -m
23+
1624
[testenv:pep8]
1725
deps = flake8
1826
commands = flake8 pythonforandroid/ tests/ ci/

0 commit comments

Comments
 (0)