Skip to content

Commit e5302af

Browse files
committed
add .p4a configuration. If found, all the lines minus comments will be added as options to the comamnd line
1 parent 3bfadba commit e5302af

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

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/toolchain.py

Lines changed: 15 additions & 0 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
@@ -2517,6 +2518,8 @@ def __init__(self):
25172518
type=bool, default=False)
25182519

25192520

2521+
self._read_configuration()
2522+
25202523
args, unknown = parser.parse_known_args(sys.argv[1:])
25212524
self.dist_args = args
25222525

@@ -2563,6 +2566,18 @@ def __init__(self):
25632566
# # print("Architectures restricted to: {}".format(archs))
25642567
# build_recipes(args.recipe, ctx)
25652568

2569+
def _read_configuration(self):
2570+
# search for a .p4a configuration file in the current directory
2571+
if not exists(".p4a"):
2572+
return
2573+
info("Reading .p4a configuration")
2574+
with open(".p4a") as fd:
2575+
lines = fd.readlines()
2576+
lines = [shlex.split(line) for line in lines if not line.startswith("#")]
2577+
for line in lines:
2578+
for arg in line:
2579+
sys.argv.append(arg)
2580+
25662581
@property
25672582
def ctx(self):
25682583
if self._ctx is None:

0 commit comments

Comments
 (0)