Skip to content

Commit 5fdbbd6

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 4407cfa + e5302af commit 5fdbbd6

File tree

5 files changed

+89
-34
lines changed

5 files changed

+89
-34
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@
1111
.optional-deps
1212

1313
*.pyc
14-
*.pyo
14+
*.pyo
15+
.packages
16+
python_for_android.egg-info
17+
src

doc/source/quickstart.rst

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ options available.
1010
.. warning:: These instructions are quite preliminary. The
1111
installation and use process will become more standard in
1212
the near future.
13-
13+
1414

1515
Installation
1616
------------
@@ -20,18 +20,18 @@ The easiest way to install is with pip. You need to have setuptools installed, t
2020
pip install git+https://github.com/kivy/python-for-android.git
2121

2222
This should install python-for-android (though you may need to run as root or add --user).
23-
23+
2424
You could also install python-for-android manually, either via git::
2525

2626
git clone https://github.com/kivy/python-for-android.git
2727
cd python-for-android
28-
28+
2929
Or by direct download::
3030

3131
wget https://github.com/kivy/python-for-android/archive/master.zip
3232
unzip revamp.zip
3333
cd python-for-android-revamp
34-
34+
3535
Then in both cases run ``python setup.py install``.
3636

3737
Dependencies
@@ -58,13 +58,13 @@ install most of these with::
5858
sudo dpkg --add-architecture i386
5959
sudo apt-get update
6060
sudo apt-get install -y build-essential ccache git zlib1g-dev python2.7 python2.7-dev libncurses5:i386 libstdc++6:i386 zlib1g:i386 openjdk-7-jdk unzip ant
61-
61+
6262
When installing the Android SDK and NDK, note the filepaths where they
6363
may be found, and the version of the NDK installed. You may need to
6464
set environment variables pointing to these later.
6565

6666
.. _basic_use:
67-
67+
6868
Basic use
6969
---------
7070

@@ -84,7 +84,7 @@ Android SDK and NDK, then:
8484
- Set the ``ANDROIDSDK`` env var to the ``/path/to/the/sdk``
8585
- Set the ``ANDROIDNDK`` env var to the ``/path/to/the/ndk``
8686
- Set the ``ANDROIDAPI`` to the targeted API version (or leave it
87-
unset to use the default of ``14``).
87+
unset to use the default of ``14``).
8888
- Set the ``ANDROIDNDKVER`` env var to the version of the NDK
8989
downloaded, e.g. the current NDK is ``r10e`` (or leave it unset to
9090
use the default of ``r9``.
@@ -97,41 +97,41 @@ To create a basic distribution, run .e.g::
9797

9898
python-for-android create --dist_name=testproject --bootstrap=pygame \
9999
--requirements=sdl,python2
100-
100+
101101
This will compile the distribution, which will take a few minutes, but
102102
will keep you informed about its progress. The arguments relate to the
103103
properties of the created distribution; the dist_name is an (optional)
104104
unique identifier, and the requirements is a list of any pure Python
105105
pypi modules, or dependencies with recipes available, that your app
106106
depends on. The full list of builtin internal recipes can be seen with
107107
``python-for-android recipes``.
108-
108+
109109
.. note:: Compiled dists are not located in the same place as with old
110110
python-for-android, but instead in an OS-dependent
111111
location. The build process will print this location when it
112112
finishes, but you no longer need to navigate there manually
113113
(see below).
114-
114+
115115
To build an APK, use the ``apk`` command::
116116

117117
python-for-android apk --private /path/to/your/app --package=org.example.packagename \
118118
--name="Your app name" --version=0.1
119-
119+
120120
The arguments to ``apk`` can be anything accepted by the old
121121
python-for-android build.py; the above is a minimal set to create a
122122
basic app. You can see the list with ``python-for-android apk help``.
123123

124124
A new feature of python-for-android is that you can do all of this with just one command::
125125

126126
python-for-android apk --private /path/to/your/app \
127-
--package=org.example.packagename --name="Your app name" --version=0.5
127+
--package=org.example.packagename --name="Your app name" --version=0.5
128128
--bootstrap=pygame --requirements=sdl,python2 --dist_name=testproject
129-
129+
130130
This combines the previous ``apk`` command with the arguments to
131131
``create``, and works in exactly the same way; if no internal
132132
distribution exists with these requirements then one is first built,
133133
before being used to package the APK. When the command is run again,
134-
the build step is skipped and the previous dist re-used.
134+
the build step is skipped and the previous dist re-used.
135135

136136
Using this method you don't have to worry about whether a dist exists,
137137
though it is recommended to use a different ``dist_name`` for each
@@ -183,9 +183,9 @@ order; setting any of these variables overrides all the later ones:
183183
python-for-android automatically checks the default buildozer
184184
download directory. This is intended to make testing
185185
python-for-android easy.
186-
186+
187187
If none of these is set, python-for-android will raise an error and exit.
188-
188+
189189
The Android API to target
190190
~~~~~~~~~~~~~~~~~~~~~~~~~
191191

@@ -209,7 +209,7 @@ several ways. Each choice overrides all the later ones:
209209
- The ``--android_api`` argument to any python-for-android command.
210210
- The ``ANDROIDAPI`` environment variables.
211211
- If neither of the above, the default target is used (currently 14).
212-
212+
213213
python-for-android checks if the target you select is available, and
214214
gives an error if not, so it's easy to test if you passed this
215215
variable correctly.
@@ -250,3 +250,15 @@ and means that you probably do *not* have to manually set this.
250250
If ``RELEASE.TXT`` exists but you manually set a different version,
251251
python-for-android will warn you about it, but will assume you are
252252
correct and try to continue the build.
253+
254+
Configuration file
255+
~~~~~~~~~~~~~~~~~~
256+
257+
python-for-android look on the current directory if there is a `.p4a`
258+
configuration file. If it found it, it adds all the lines as options
259+
to the command line. For example, you can put the options you would
260+
always write such as:
261+
262+
--dist_name my_example
263+
--android_api 19
264+
--requirements kivy,openssl

pythonforandroid/recipes/python2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def prebuild_armeabi(self):
3333
self.apply_patch(join('patches', 'fix-remove-corefoundation.patch'))
3434
self.apply_patch(join('patches', 'fix-dynamic-lookup.patch'))
3535
self.apply_patch(join('patches', 'fix-dlfcn.patch'))
36+
self.apply_patch(join('patches', 'parsetuple.patch'))
3637
# self.apply_patch(join('patches', 'ctypes-find-library.patch'))
3738
self.apply_patch(join('patches', 'ctypes-find-library-updated.patch'))
3839

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- Python-2.7.2/configure.orig 2015-06-24 17:47:39.181473779 +0200
2+
+++ Python-2.7.2/configure 2015-06-24 17:48:31.646173137 +0200
3+
@@ -5731,7 +5731,7 @@
4+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether gcc supports ParseTuple __format__" >&5
5+
$as_echo_n "checking whether gcc supports ParseTuple __format__... " >&6; }
6+
save_CFLAGS=$CFLAGS
7+
- CFLAGS="$CFLAGS -Werror"
8+
+ CFLAGS="$CFLAGS -Werror -Wformat"
9+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
10+
/* end confdefs.h. */
11+

pythonforandroid/toolchain.py

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import imp
2626
import contextlib
2727
import logging
28+
import shlex
2829
from copy import deepcopy
2930
from functools import wraps
3031
from datetime import datetime
@@ -43,7 +44,16 @@
4344
import argparse
4445
from appdirs import user_data_dir
4546
import sh
46-
from colorama import Style, Fore
47+
if sys.stdout.isatty():
48+
from colorama import Style, Fore
49+
else:
50+
from collections import defaultdict
51+
class colorama_shim(object):
52+
def __init__(self):
53+
self._dict = defaultdict(str)
54+
def __getattr__(self, key):
55+
return self._dict[key]
56+
Style = Fore = colorama_shim()
4757

4858
user_dir = dirname(realpath(os.path.curdir))
4959
toolchain_dir = dirname(__file__)
@@ -71,7 +81,7 @@ def format(self, record):
7181
# handler and reset the level
7282
logger.setLevel(logging.INFO)
7383
logger.touched = True
74-
ch = logging.StreamHandler(stdout)
84+
ch = logging.StreamHandler(stdout) if sys.stdout.isatty() else logging.NullHandler()
7585
formatter = LevelDifferentiatingFormatter('%(message)s')
7686
ch.setFormatter(formatter)
7787
logger.addHandler(ch)
@@ -2583,23 +2593,27 @@ def __init__(self):
25832593
description="Tool for managing the Android / Python toolchain",
25842594
usage="""toolchain <command> [<args>]
25852595
2586-
Currently available commands:
2587-
create Build an android project with all recipes
2588-
25892596
Available commands:
2590-
Not yet confirmed
2597+
adb Runs adb binary from the detected SDK dir
2598+
apk Create an APK using the given distribution
2599+
bootstraps List all the bootstraps available to build with.
2600+
build_status Informations about the current build
2601+
create Build an android project with all recipes
2602+
clean_all Delete all build components
2603+
clean_builds Delete all build caches
2604+
clean_dists Delete all compiled distributions
2605+
clean_download_cache Delete any downloaded recipe packages
2606+
clean_recipe_build Delete the build files of a recipe
2607+
distributions List all distributions
2608+
export_dist Copies a created dist to an output directory
2609+
logcat Runs logcat from the detected SDK dir
2610+
print_context_info Prints debug informations
2611+
recipes List all the available recipes
2612+
sdk_tools Runs android binary from the detected SDK dir
2613+
symlink_dist Symlinks a created dist to an output directory
25912614
25922615
Planned commands:
2593-
recipes
2594-
distributions
25952616
build_dist
2596-
symlink_dist
2597-
copy_dist
2598-
clean_all
2599-
status
2600-
clean_builds
2601-
clean_download_cache
2602-
clean_dists
26032617
""")
26042618
parser.add_argument("command", help="Command to run")
26052619

@@ -2643,6 +2657,8 @@ def __init__(self):
26432657
type=bool, default=False)
26442658

26452659

2660+
self._read_configuration()
2661+
26462662
args, unknown = parser.parse_known_args(sys.argv[1:])
26472663
self.dist_args = args
26482664

@@ -2689,6 +2705,18 @@ def __init__(self):
26892705
# # print("Architectures restricted to: {}".format(archs))
26902706
# build_recipes(args.recipe, ctx)
26912707

2708+
def _read_configuration(self):
2709+
# search for a .p4a configuration file in the current directory
2710+
if not exists(".p4a"):
2711+
return
2712+
info("Reading .p4a configuration")
2713+
with open(".p4a") as fd:
2714+
lines = fd.readlines()
2715+
lines = [shlex.split(line) for line in lines if not line.startswith("#")]
2716+
for line in lines:
2717+
for arg in line:
2718+
sys.argv.append(arg)
2719+
26922720
@property
26932721
def ctx(self):
26942722
if self._ctx is None:
@@ -2710,7 +2738,7 @@ def recipes(self, args):
27102738
print(" ".join(list(Recipe.list_recipes())))
27112739
else:
27122740
ctx = self.ctx
2713-
for name in Recipe.list_recipes():
2741+
for name in sorted(Recipe.list_recipes()):
27142742
recipe = Recipe.get_recipe(name, ctx)
27152743
version = str(recipe.version)
27162744
if args.color:

0 commit comments

Comments
 (0)