Skip to content

Commit f5e78b7

Browse files
committed
[docs] Add documentation: testing a pull request
1 parent 06b5958 commit f5e78b7

File tree

2 files changed

+227
-0
lines changed

2 files changed

+227
-0
lines changed

doc/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Contents
3838
troubleshooting
3939
docker
4040
contribute
41+
testing_pull_requests
4142

4243

4344
Indices and tables

doc/source/testing_pull_requests.rst

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
Testing an python-for-android pull request
2+
==========================================
3+
4+
In order to test a pull request, we recommend to consider the following points:
5+
6+
#. of course, check if the overall thing makes sense
7+
#. is the CI passing? if not what specifically fails
8+
#. is it working locally at compile time?
9+
#. is it working on device at runtime?
10+
11+
This document will focus on the third point:
12+
`is it working locally at compile time?` so we will give some hints about how
13+
to proceed in order to create a local copy of the pull requests and build an
14+
apk. We expect that the contributors has enough criteria/knowledge to perform
15+
the other steps mentioned, so let's begin...
16+
17+
To create an apk from a python-for-android pull request we contemplate three
18+
possible scenarios:
19+
20+
- using python-for-android commands directly from the pull request files
21+
that we want to test, without installing it (the recommended way for most
22+
of the test cases)
23+
- installing python-for-android using the github's branch of the pull request
24+
- using buildozer and a custom app
25+
26+
We will explain the first two methods using one of the distributed
27+
python-for-android test apps and we assume that you already have the
28+
python-for-android dependencies installed. For the `buildozer` method we also
29+
expect that you already have a a properly working app to test and a working
30+
installation/configuration of `buildozer`. There is one step that it's shared
31+
with all the testing methods that we propose in here...we named it
32+
`Common steps`.
33+
34+
35+
Common steps
36+
^^^^^^^^^^^^
37+
The first step to do it's to get a copy of the pull request, we can do it of
38+
several ways, and that it will depend of the circumstances but all the methods
39+
presented here will do the job, so...
40+
41+
Fetch the pull request by number
42+
--------------------------------
43+
For the example, we will use `1901` for the example) and the pull request
44+
branch that we will use is `feature-fix-numpy`, then you will use a variation
45+
of the following git command:
46+
`git fetch origin pull/<#>/head:<local_branch_name>`, eg.::
47+
48+
.. codeblock:: bash
49+
50+
git fetch upstream pull/1901/head:feature-fix-numpy
51+
52+
.. note:: Notice that we fetch from `upstream`, since that is the original
53+
project, where the pull request is supposed to be
54+
55+
.. tip:: The amount of work of some users maybe worth it to add his remote
56+
to your fork's git configuration, to do so with the imaginary
57+
github user `Obi-Wan Kenobi` which nickname is `obiwankenobi`, you
58+
will do::
59+
60+
.. codeblock:: bash
61+
62+
git remote add obiwankenobi https://github.com/obiwankenobi/python-for-android.git
63+
64+
And to fetch the pull request branch that we put as example, you
65+
would do::
66+
67+
.. codeblock:: bash
68+
69+
git fetch obiwankenobi
70+
git checkout obiwankenobi/feature-fix-numpy
71+
72+
73+
Clone the pull request branch from the user's fork
74+
--------------------------------------------------
75+
Sometimes you may prefer to use directly the fork of the user, so you will get
76+
the nickname of the user who created the pull request, let's take the same
77+
imaginary user than before `obiwankenobi`::
78+
79+
.. codeblock:: bash
80+
81+
git clone -b feature-fix-numpy \
82+
--single-branch \
83+
https://github.com/obiwankenobi/python-for-android.git \
84+
p4a-feature-fix-numpy
85+
86+
Here's the above command explained line by line:
87+
88+
- `git clone -b feature-fix-numpy`: we tell git that we want to clone the
89+
branch named `feature-fix-numpy`
90+
- `--single-branch`: we tell git that we only want that branch
91+
- `https://github.com/obiwankenobi/python-for-android.git`: noticed the
92+
nickname of the user that created the pull request: `obiwankenobi` in the
93+
middle of the line? that should be changed as needed for each pull
94+
request that you want to test
95+
- `p4a-feature-fix-numpy`: the name of the cloned repository, so we can
96+
have multiple clones of different prs in the same folder
97+
98+
.. note:: You can view the author/branch information looking at the
99+
subtitle of the pull request, near the pull request status (expected
100+
an `open` status)
101+
102+
Using python-for-android commands directly from the pull request files
103+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104+
105+
- Enter inside the directory of the cloned repository in the above
106+
step and run p4a command with proper args, eg::
107+
108+
.. codeblock:: bash
109+
110+
cd p4a-feature-fix-numpy
111+
PYTHONPATH=. python3 -m pythonforandroid.toolchain apk \
112+
--private=testapps/testapp_sqlite_openssl \
113+
--dist-name=dist_test_app_python3_libs \
114+
--package=org.kivy \
115+
--name=test_app_python3_sqlite_openssl \
116+
--version=0.1 \
117+
--requirements=requests,peewee,sdl2,pyjnius,kivy,python3 \
118+
--ndk-dir=/media/DEVEL/Android/android-ndk-r20 \
119+
--sdk-dir=/media/DEVEL/Android/android-sdk-linux \
120+
--android-api=27 \
121+
--arch=arm64-v8a \
122+
--permission=INTERNET \
123+
--debug
124+
125+
Things that you should know:
126+
127+
128+
- The example above will build an testapp we will make use of the files of
129+
the testapp named `testapp_sqlite_openssl.py` but we don't use the setup
130+
file to build it so we must tell python-for-android what we want via
131+
arguments
132+
- be sure to at least edit the following arguments when running the above
133+
command, since the default set in there it's unlikely that match your
134+
installation:
135+
136+
- `--ndk-dir`: An absolute path to your android's NDK dir
137+
- `--sdk-dir`: An absolute path to your android's SDK dir
138+
- `--debug`: this one enables the debug mode of python-for-android,
139+
which will show all log messages of the build. You can omit this
140+
one but it's worth it to be mentioned, since this it's useful to us
141+
when trying to find the source of the problem when things goes
142+
wrong
143+
- The apk generated by the above command should be located at the root of
144+
of the cloned repository, were you run the command to build the apk
145+
- The testapps distributed with python-for-android are located at
146+
`testapps` folder under the main folder project
147+
- All the builds of python-for-android are located at
148+
`~/.local/share/python-for-android`
149+
- You should have a downloaded copy of the android's NDK and SDK
150+
151+
Installing python-for-android using the github's branch of the pull request
152+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
153+
154+
- Enter inside the directory of the cloned repository mentioned in
155+
`Common steps` and install it via pip, eg.::
156+
157+
.. codeblock:: bash
158+
159+
cd p4a-feature-fix-numpy
160+
pip3 install . --upgrade --user
161+
162+
- Now, go inside the `testapps` directory (we assume that you still are inside
163+
the cloned repository)::
164+
165+
.. codeblock:: bash
166+
167+
cd testapps
168+
169+
- Run the build of the apk via the freshly installed copy of python-for-android
170+
by running a similar command than below::
171+
172+
.. code-block:: bash
173+
174+
python3 setup_testapp_python3_sqlite_openssl.py apk \
175+
--ndk-dir=/media/DEVEL/Android/android-ndk-r20 \
176+
--sdk-dir=/media/DEVEL/Android/android-sdk-linux \
177+
--android-api=27 \
178+
--arch=arm64-v8a \
179+
--debug
180+
181+
182+
Things that you should know:
183+
184+
- In the example above, we override some variables that are set in
185+
`setup_testapp_python3_sqlite_openssl.py`, you could also override them
186+
by editing this file
187+
- be sure to at least edit the following arguments when running the above
188+
command, since the default set in there it's unlikely that match your
189+
installation:
190+
191+
- `--ndk-dir`: An absolute path to your android's NDK dir
192+
- `--sdk-dir`: An absolute path to your android's SDK dir
193+
194+
.. tip:: if you don't want to mess up with the system's python, you could do
195+
the same steps but inside a virtualenv
196+
197+
.. warning:: Once you finish the pull request tests remember to go back to the
198+
master or develop versions of python-for-android, since you just
199+
installed the python-for-android files of the `pull request`
200+
201+
Using buildozer with a custom app
202+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
203+
204+
- Edit your `buildozer.spec` file. You should search for the key
205+
`p4a.source_dir` and set the right value so in the example posted in
206+
`Common steps` it would look like this::
207+
208+
p4a.source_dir = /home/user/p4a_pull_requests/p4a-feature-fix-numpy
209+
210+
- Run you buildozer command as usual, eg.::
211+
212+
buildozer android debug p4a --dist-name=dist-test-feature-fix-numpy
213+
214+
.. note:: this method has the advantage, can be run without installing the
215+
pull request version of python-for-android nor the android's
216+
dependencies but has one problem...when things goes wrong you must
217+
determine if it's a buildozer issue or a python-for-android one
218+
219+
.. warning:: Once you finish the pull request tests remember to comment/edit
220+
the `p4a.source_dir` constant that you just edited to test the
221+
pull request
222+
223+
.. tip:: this method it's useful for developing pull requests since you can
224+
edit `p4a.source_dir` to point to your python-for-android fork and you
225+
can test any branch you want only switching branches with:
226+
`git checkout <branch-name>` from inside your python-for-android fork

0 commit comments

Comments
 (0)