Skip to content

Commit 7f94527

Browse files
committed
Merge pull request kivy#323 from FeralBytes/python3
Rebase Python3 Branch
2 parents 5faaed7 + 8940bd9 commit 7f94527

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2475
-917
lines changed

distribute.sh

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ if [ "X$VIRTUALENV_NAME" == "X" ]; then
4242
VIRTUALENV_NAME="$(which virtualenv)"
4343
fi
4444

45+
# Resolve Cython path
46+
CYTHON="$(which cython2)"
47+
if [ "X$CYTHON" == "X" ]; then
48+
CYTHON="$(which cython)"
49+
fi
50+
4551
# Paths
4652
ROOT_PATH="$(dirname $($PYTHON -c 'from __future__ import print_function; import os,sys;print(os.path.realpath(sys.argv[1]))' $0))"
4753
RECIPES_PATH="$ROOT_PATH/recipes"
@@ -54,13 +60,16 @@ JNI_PATH="$SRC_PATH/jni"
5460
DIST_PATH="$ROOT_PATH/dist/default"
5561
SITEPACKAGES_PATH="$BUILD_PATH/python-install/lib/python2.7/site-packages/"
5662
HOSTPYTHON="$BUILD_PATH/python-install/bin/python.host"
63+
CYTHON+=" -t"
5764

5865
# Tools
5966
export LIBLINK_PATH="$BUILD_PATH/objects"
6067
export LIBLINK="$ROOT_PATH/src/tools/liblink"
6168
export BIGLINK="$ROOT_PATH/src/tools/biglink"
62-
export PIP=$PIP_NAME
63-
export VIRTUALENV=$VIRTUALENV_NAME
69+
export PIP=${PIP_NAME:-pip}
70+
export VIRTUALENV=${VIRTUALENV_NAME:-virtualenv}
71+
72+
export COPYLIBS=0
6473

6574
MD5SUM=$(which md5sum)
6675
if [ "X$MD5SUM" == "X" ]; then
@@ -146,7 +155,7 @@ function get_directory() {
146155
}
147156

148157
function push_arm() {
149-
info "Entering in ARM enviromnent"
158+
info "Entering in ARM environment"
150159

151160
# save for pop
152161
export OLD_PATH=$PATH
@@ -189,8 +198,11 @@ function push_arm() {
189198
export TOOLCHAIN_PREFIX=arm-linux-androideabi
190199
export TOOLCHAIN_VERSION=4.4.3
191200
elif [ "X${ANDROIDNDKVER:0:2}" == "Xr9" ]; then
192-
export TOOLCHAIN_PREFIX=arm-linux-androideabi
193-
export TOOLCHAIN_VERSION=4.8
201+
export TOOLCHAIN_PREFIX=arm-linux-androideabi
202+
export TOOLCHAIN_VERSION=4.8
203+
elif [ "X${ANDROIDNDKVER:0:3}" == "Xr10" ]; then
204+
export TOOLCHAIN_PREFIX=arm-linux-androideabi
205+
export TOOLCHAIN_VERSION=4.9
194206
else
195207
echo "Error: Please report issue to enable support for newer ndk."
196208
exit 1
@@ -216,6 +228,10 @@ function push_arm() {
216228
export LD="$TOOLCHAIN_PREFIX-ld"
217229
export STRIP="$TOOLCHAIN_PREFIX-strip --strip-unneeded"
218230
export MAKE="make -j5"
231+
export READELF="$TOOLCHAIN_PREFIX-readelf"
232+
233+
# This will need to be updated to support Python versions other than 2.7
234+
export BUILDLIB_PATH="$BUILD_hostpython/build/lib.linux-`uname -m`-2.7/"
219235

220236
# Use ccache ?
221237
which ccache &>/dev/null
@@ -252,6 +268,10 @@ function usage() {
252268
echo " -f Restart from scratch (remove the current build)"
253269
echo " -x display expanded values (execute 'set -x')"
254270
echo
271+
echo "Advanced:"
272+
echo " -C Copy libraries instead of using biglink"
273+
echo " (may not work before Android 4.3)"
274+
echo
255275
echo "For developers:"
256276
echo " -u 'mod1 mod2' Modules to update (if already compiled)"
257277
echo
@@ -279,7 +299,7 @@ function check_build_deps() {
279299
DIST=$(lsb_release -is)
280300
info "Check build dependencies for $DIST"
281301
case $DIST in
282-
Debian|Ubuntu)
302+
Debian|Ubuntu|LinuxMint)
283303
check_pkg_deb_installed "build-essential zlib1g-dev cython"
284304
;;
285305
*)
@@ -344,6 +364,15 @@ function run_prepare() {
344364
fi
345365
done
346366

367+
if [ "$COPYLIBS" == "1" ]; then
368+
info "Library files will be copied to the distribution (no biglink)"
369+
error "NOTICE: This option is still beta!"
370+
error "\tIf you encounter an error 'Failed to locate needed libraries!' and"
371+
error "\tthe libraries listed are not supposed to be provided by your app or"
372+
error "\tits dependencies, please submit a bug report at"
373+
error "\thttps://github.com/kivy/python-for-android/issues"
374+
fi
375+
347376
info "Distribution will be located at $DIST_PATH"
348377
if [ -e "$DIST_PATH" ]; then
349378
error "The distribution $DIST_PATH already exist"
@@ -526,6 +555,10 @@ function run_get_packages() {
526555
try mkdir -p $BUILD_PATH/$module
527556
fi
528557

558+
if [ ! -d "$PACKAGES_PATH/$module" ]; then
559+
try mkdir -p "$PACKAGES_PATH/$module"
560+
fi
561+
529562
if [ "X$url" == "X" ]; then
530563
debug "No package for $module"
531564
continue
@@ -535,7 +568,7 @@ function run_get_packages() {
535568
marker_filename=".mark-$filename"
536569
do_download=1
537570

538-
cd $PACKAGES_PATH
571+
cd "$PACKAGES_PATH/$module"
539572

540573
# check if the file is already present
541574
if [ -f $filename ]; then
@@ -605,7 +638,7 @@ function run_get_packages() {
605638
fi
606639

607640
# decompress
608-
pfilename=$PACKAGES_PATH/$filename
641+
pfilename=$PACKAGES_PATH/$module/$filename
609642
info "Extract $pfilename"
610643
case $pfilename in
611644
*.tar.gz|*.tgz )
@@ -704,7 +737,7 @@ function run_pymodules_install() {
704737
debug "We want to install: $PYMODULES"
705738

706739
debug "Check if $VIRTUALENV and $PIP are present"
707-
for tool in $VIRTUALENV $PIP; do
740+
for tool in "$VIRTUALENV" "$PIP"; do
708741
which $tool &>/dev/null
709742
if [ $? -ne 0 ]; then
710743
error "Tool $tool is missing"
@@ -719,10 +752,13 @@ function run_pymodules_install() {
719752
fi
720753

721754
debug "Create a requirement file for pure-python modules"
722-
try echo "$PYMODULES" | try sed 's/\ /\n/g' > requirements.txt
755+
try echo "" > requirements.txt
756+
for mod in $PYMODULES; do
757+
echo $mod >> requirements.txt
758+
done
723759

724760
debug "Install pure-python modules via pip in venv"
725-
try bash -c "source venv/bin/activate && env CC=/bin/false CXX=/bin/false $PIP install --target '$SITEPACKAGES_PATH' --download-cache '$PACKAGES_PATH' -r requirements.txt"
761+
try bash -c "source venv/bin/activate && env CC=/bin/false CXX=/bin/false pip install --target '$SITEPACKAGES_PATH' --download-cache '$PACKAGES_PATH' -r requirements.txt"
726762

727763
}
728764

@@ -759,7 +795,14 @@ function run_distribute() {
759795
debug "Fill private directory"
760796
try cp -a python-install/lib private/
761797
try mkdir -p private/include/python2.7
762-
try mv libs/$ARCH/libpymodules.so private/
798+
799+
if [ "$COPYLIBS" == "1" ]; then
800+
if [ -s "libs/$ARCH/copylibs" ]; then
801+
try sh -c "cat libs/$ARCH/copylibs | xargs -d'\n' cp -t private/"
802+
fi
803+
else
804+
try mv libs/$ARCH/libpymodules.so private/
805+
fi
763806
try cp python-install/include/python2.7/pyconfig.h private/include/python2.7/
764807

765808
debug "Reduce private directory from unwanted files"
@@ -786,7 +829,11 @@ function run_distribute() {
786829

787830
function run_biglink() {
788831
push_arm
789-
try $BIGLINK $LIBS_PATH/libpymodules.so $LIBLINK_PATH
832+
if [ "$COPYLIBS" == "0" ]; then
833+
try $BIGLINK $LIBS_PATH/libpymodules.so $LIBLINK_PATH
834+
else
835+
try $BIGLINK $LIBS_PATH/copylibs $LIBLINK_PATH
836+
fi
790837
pop_arm
791838
}
792839

@@ -828,11 +875,16 @@ function arm_deduplicate() {
828875

829876

830877
# Do the build
831-
while getopts ":hvlfxm:u:d:s" opt; do
878+
while getopts ":hCvlfxm:u:d:s" opt; do
832879
case $opt in
833880
h)
834881
usage
835882
;;
883+
C)
884+
COPYLIBS=1
885+
LIBLINK=${LIBLINK}-jb
886+
BIGLINK=${BIGLINK}-jb
887+
;;
836888
l)
837889
list_modules
838890
;;

docs/source/android.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
Python API
22
==========
33

4-
The Python for android project includes a Python module called "android". It
5-
consists of multiple parts which are mostly there to facilitate the use of the Java API.
4+
The Python for Android project includes a Python module called
5+
``android`` which consists of multiple parts that are mostly there to
6+
facilitate the use of the Java API.
67

7-
This module is not designed to be comprehensive. Most of the Java API is also accessible with PyJNIus,
8-
so if you can't find what you need here you can try using the Java API directly instead.
8+
This module is not designed to be comprehensive. Most of the Java API
9+
is also accessible with PyJNIus, so if you can't find what you need
10+
here you can try using the Java API directly instead.
911

1012

1113
Android (``android``)
@@ -88,7 +90,7 @@ This billing module gives an access to the `In-App Billing <http://developer.and
8890

8991
#. `Setup some In-App product <http://developer.android.com/guide/google/play/billing/billing_admin.html>`_ to buy. Let's say you've created a product with the id "org.kivy.gopremium"
9092

91-
#. In your application, you can use the billing module like this::
93+
#. In your application, you can use the ``billing`` module like this::
9294

9395

9496
from android.billing import BillingService
@@ -123,7 +125,7 @@ This billing module gives an access to the `In-App Billing <http://developer.and
123125
# Return all the items purchased
124126
return self.service.get_purchased_items()
125127

126-
#. To initiate an in-app purchase, just call the buy() method::
128+
#. To initiate an in-app purchase, just call the ``buy()`` method::
127129

128130
# Note: start the service at the start, and never twice!
129131
bs = MyBillingService()
@@ -136,7 +138,7 @@ This billing module gives an access to the `In-App Billing <http://developer.and
136138

137139
#. You'll receive all the notifications about the billing process in the callback.
138140

139-
#. Last step, create your application with `--with-billing $BILLING_PUBKEY`::
141+
#. Last step, create your application with ``--with-billing $BILLING_PUBKEY``::
140142

141143
./build.py ... --with-billing $BILLING_PUBKEY
142144

docs/source/contribute.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ Extending Python for android native support
55
-------------------------------------------
66

77
So, you want to get into python-for-android and extend what's available
8-
to python on android ?
8+
to Python on Android ?
99

1010
Turns out it's not very complicated, here is a little introduction on how to go
11-
about it. Without Pyjnius, the schema to access to Java API from Cython is::
11+
about it. Without Pyjnius, the schema to access the Java API from Cython is::
1212

1313
[1] Cython -> [2] C JNI -> [3] Java
1414

15-
Think about acceleration sensors : you want to get the acceleration values in
16-
python nothing is available natively, but you have a java API for that : the
17-
google API is available here
15+
Think about acceleration sensors: you want to get the acceleration
16+
values in Python, but nothing is available natively. Lukcily you have
17+
a Java API for that : the Google API is available here
1818
http://developer.android.com/reference/android/hardware/Sensor.html
1919

2020
You can't use it directly, you need to do your own API to use it in python,
@@ -82,14 +82,14 @@ Jni gottchas
8282
Create your own recipes
8383
-----------------------
8484

85-
A recipe is a script that contain the "definition" of a module to compile.
85+
A recipe is a script that contains the "definition" of a module to compile.
8686
The directory layout of a recipe for a <modulename> is something like::
8787

8888
python-for-android/recipes/<modulename>/recipe.sh
8989
python-for-android/recipes/<modulename>/patches/
9090
python-for-android/recipes/<modulename>/patches/fix-path.patch
9191

92-
When building, all the recipe build must go to::
92+
When building, all the recipe builds must go to::
9393

9494
python-for-android/build/<modulename>/<archiveroot>
9595

@@ -101,5 +101,5 @@ For example, if you want to create a recipe for sdl, do::
101101
sed -i 's#XXX#sdl#' sdl/recipe.sh
102102

103103
Then, edit the sdl/recipe.sh to adjust other information (version, url) and
104-
complete build function.
104+
complete the build function.
105105

docs/source/example_helloworld.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ with this project.
77

88
.. note::
99

10-
Don't forget that Python for android is not Kivy only, and you might want
11-
to use other toolkit libraries. When other toolkits will be available, this
12-
documentation will be enhanced.
10+
Don't forget that Python for Android is not Kivy only, and you
11+
might want to use other toolkit libraries. When other toolkits
12+
will be available, this documentation will be enhanced.
1313

1414
Let's create a simple Hello world application, with one Label and one Button.
1515

@@ -43,7 +43,7 @@ Let's create a simple Hello world application, with one Label and one Button.
4343
class HelloWorldScreen(GridLayout):
4444
counter = NumericProperty(0)
4545
def my_callback(self):
46-
print 'The button have been pushed'
46+
print 'The button has been pushed'
4747
self.counter += 1
4848

4949
class HelloWorldApp(App):
@@ -55,15 +55,16 @@ Let's create a simple Hello world application, with one Label and one Button.
5555

5656
#. Go to the ``python-for-android`` directory
5757

58-
#. Create a distribute with kivy::
58+
#. Create a distribution with kivy::
5959

6060
./distribute.sh -m kivy
6161

6262
#. Go to the newly created ``default`` distribution::
6363

6464
cd dist/default
6565

66-
#. Plug your android device, and ensure you can install development application
66+
#. Plug your android device, and ensure you can install development
67+
application
6768

6869
#. Build your hello world application in debug mode::
6970

@@ -72,7 +73,7 @@ Let's create a simple Hello world application, with one Label and one Button.
7273

7374
#. Take your device, and start the application!
7475

75-
#. If it's goes wrong, open the logcat by doing::
76+
#. If something goes wrong, open the logcat by doing::
7677

7778
adb logcat
7879

docs/source/examples.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ Examples
44
Prebuilt VirtualBox
55
-------------------
66

7-
A good starting point to build an APK are prebuilt VirtualBox images, where
8-
the Android NDK, the Android SDK and the Kivy Python-For-Android sources
9-
are prebuilt in an VirtualBox image. Please search the `Download Section
10-
<http://kivy.org/#download>`__ for
11-
such an image.
7+
A good starting point to build an APK are prebuilt VirtualBox images,
8+
where the Android NDK, the Android SDK, and the Kivy
9+
Python-For-Android sources are prebuilt in an VirtualBox image. Please
10+
search the `Download Section <http://kivy.org/#download>`__ for such
11+
an image. You will also need to create a device filter for the Android
12+
USB device using the VirtualBox OS settings.
1213

1314
.. include:: example_helloworld.rst
1415
.. include:: example_compass.rst

docs/source/faq.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ Android. Go to :doc:`prerequisites.rst` to see which one are working.
1010
_sqlite3.so not found
1111
---------------------
1212

13-
We recently fixed sqlite3 compilation. In case of, you must:
13+
We recently fixed sqlite3 compilation. In case of this error, you
14+
must:
1415

15-
* Install development headers for sqlite3 if it's not already installed. On Ubuntu:
16+
* Install development headers for sqlite3 if they are not already
17+
installed. On Ubuntu:
1618

1719
apt-get install libsqlite3-dev
1820

@@ -26,4 +28,4 @@ We recently fixed sqlite3 compilation. In case of, you must:
2628
sqlite3/*
2729
lib-dynload/_sqlite3.so
2830

29-
And then, sqlite3 will be compiled, and included in your APK.
31+
Then sqlite3 will be compiled and included in your APK.

0 commit comments

Comments
 (0)