|
| 1 | +Testing an python-for-android pull request |
| 2 | +========================================== |
| 3 | + |
| 4 | +In order to test a p4a pull requests we contemplate three possible scenarios: |
| 5 | + |
| 6 | + - using python-for-android commands directly from the pull request files |
| 7 | + that we want to test, without installing it (the recommended way for most |
| 8 | + of the test cases) |
| 9 | + - installing python-for-android using the github's branch of the pull request |
| 10 | + - using buildozer and a custom app |
| 11 | + |
| 12 | +We will explain the first two methods using one of the distributed |
| 13 | +python-for-android test apps and we assume that you already have the |
| 14 | +python-for-android dependencies installed. For the `buildozer` method we assume that you |
| 15 | +already have a a properly working app to test and a working |
| 16 | +installation/configuration of `buildozer`. There is one step that it's shared |
| 17 | +with all the testing methods that we propose in here...we named it |
| 18 | +`Common steps`. |
| 19 | + |
| 20 | + |
| 21 | +Common steps |
| 22 | +^^^^^^^^^^^^ |
| 23 | + |
| 24 | +- open a terminal, create a test directory and enter inside it, eg.:: |
| 25 | + |
| 26 | + .. codeblock:: bash |
| 27 | + |
| 28 | + mkdir p4a_pull_requests |
| 29 | + cd p4a_pull_requests |
| 30 | + |
| 31 | +- clone the pull request you wanna to test, let's imagine that you wanna to |
| 32 | + test a pull request whose branch is named `feature-fix-numpy` and the github |
| 33 | + nickname of the user who created the pull request is named `obiwankenoby`:: |
| 34 | + |
| 35 | + .. codeblock:: bash |
| 36 | + |
| 37 | + git clone -b feature-fix-numpy \ |
| 38 | + --single-branch \ |
| 39 | + https://github.com/obiwankenoby/python-for-android.git \ |
| 40 | + p4a-feature-fix-numpy |
| 41 | + |
| 42 | +For what it's worth it about the command above explained line by line: |
| 43 | + |
| 44 | + - `git clone -b feature-fix-numpy`: we tell git that we want to clone the |
| 45 | + branch named `feature-fix-numpy` |
| 46 | + - `--single-branch`: we tell git that we only want that branch |
| 47 | + - `https://github.com/obiwankenoby/python-for-android.git`: noticed the |
| 48 | + nickname of the user that created the pull request: `obiwankenoby` in the |
| 49 | + middle of the line? that should be changed as needed for each pull |
| 50 | + request that you wanna to test |
| 51 | + - `p4a-feature-fix-numpy`: the name of the cloned repository, so we can |
| 52 | + have multiple clones of different prs in the same folder |
| 53 | + |
| 54 | +.. note:: You can view the author/branch information looking at the |
| 55 | + subtitle of the pull request, near the pull request status (expected |
| 56 | + an `open` status) |
| 57 | + |
| 58 | +Using python-for-android commands directly from the pull request files |
| 59 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 60 | + |
| 61 | +- Enter inside the directory of the cloned repository in the above |
| 62 | + step and run p4a command with proper args, eg:: |
| 63 | + |
| 64 | + .. codeblock:: bash |
| 65 | + |
| 66 | + cd p4a-feature-fix-numpy |
| 67 | + PYTHONPATH=. python3 -m pythonforandroid.toolchain apk \ |
| 68 | + --private=testapps/testapp_sqlite_openssl \ |
| 69 | + --dist-name=dist_test_app_python3_libs \ |
| 70 | + --package=org.kivy \ |
| 71 | + --name=test_app_python3_sqlite_openssl \ |
| 72 | + --version=0.1 \ |
| 73 | + --requirements=requests,peewee,sdl2,pyjnius,kivy,python3 \ |
| 74 | + --ndk-dir=/media/DEVEL/Android/android-ndk-r20 \ |
| 75 | + --sdk-dir=/media/DEVEL/Android/android-sdk-linux \ |
| 76 | + --android-api=27 \ |
| 77 | + --arch=arm64-v8a \ |
| 78 | + --permission=INTERNET \ |
| 79 | + --debug |
| 80 | + |
| 81 | +Things that you should know: |
| 82 | + |
| 83 | + |
| 84 | + - The example above will build an testapp we will make use of the files of |
| 85 | + the testapp named `testapp_sqlite_openssl.py` but we don't use the setup |
| 86 | + file to build it so we must tell python-for-android what we want via |
| 87 | + arguments |
| 88 | + - be sure to at least edit the following arguments when running the above |
| 89 | + command, since the default set in there it's unlikely that match your |
| 90 | + installation: |
| 91 | + |
| 92 | + - `--ndk-dir`: An absolute path to your android's NDK dir |
| 93 | + - `--sdk-dir`: An absolute path to your android's SDK dir |
| 94 | + - `--debug`: this one enables the debug mode of python-for-android, |
| 95 | + which will show all log messages of the build. You can omit this one |
| 96 | + but it's worth it to be mentioned, since this it's useful to us when |
| 97 | + trying to find the source of the problem when things goes wrong |
| 98 | + - The apk generated by the above command should be located at the root of |
| 99 | + of the cloned repository, were you run the command to build the apk |
| 100 | + - The testapps distributed with python-for-android are located at |
| 101 | + `testapps` folder under the main folder project |
| 102 | + - All the builds of python-for-android are located at |
| 103 | + `~/.local/share/python-for-android` |
| 104 | + - You should have a downloaded copy of the android's NDK and SDK |
| 105 | + |
| 106 | +Installing python-for-android using the github's branch of the pull request |
| 107 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 108 | + |
| 109 | +- Enter inside the directory of the cloned repository mentioned in |
| 110 | + `Common steps` and install it via pip, eg.:: |
| 111 | + |
| 112 | + .. codeblock:: bash |
| 113 | + |
| 114 | + cd p4a-feature-fix-numpy |
| 115 | + pip3 install . --upgrade --user |
| 116 | + |
| 117 | +- Now, go inside the `testapps` directory (we assume that you still are inside |
| 118 | + the cloned repository):: |
| 119 | + |
| 120 | + .. codeblock:: bash |
| 121 | + |
| 122 | + cd testapps |
| 123 | + |
| 124 | +- Run the build of the apk via the freshly installed copy of python-for-android |
| 125 | + by running a similar command than below:: |
| 126 | + |
| 127 | + .. code-block:: bash |
| 128 | + |
| 129 | + python3 setup_testapp_python3_sqlite_openssl.py apk \ |
| 130 | + --ndk-dir=/media/DEVEL/Android/android-ndk-r20 \ |
| 131 | + --sdk-dir=/media/DEVEL/Android/android-sdk-linux \ |
| 132 | + --android-api=27 \ |
| 133 | + --arch=arm64-v8a \ |
| 134 | + --debug |
| 135 | + |
| 136 | + |
| 137 | +Things that you should know: |
| 138 | + |
| 139 | + - In the example above, we override some variables that are set in |
| 140 | + `setup_testapp_python3_sqlite_openssl.py`, you could also override them |
| 141 | + by editing this file |
| 142 | + - be sure to at least edit the following arguments when running the above |
| 143 | + command, since the default set in there it's unlikely that match your |
| 144 | + installation: |
| 145 | + |
| 146 | + - `--ndk-dir`: An absolute path to your android's NDK dir |
| 147 | + - `--sdk-dir`: An absolute path to your android's SDK dir |
| 148 | + |
| 149 | +.. warning:: Once you finish the pull request tests remember to go back to the |
| 150 | + master or develop versions of python-for-android, since you just |
| 151 | + installed the python-for-android files of the `pull request` |
| 152 | + |
| 153 | +Using buildozer with a custom app |
| 154 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 155 | + |
| 156 | +- Edit your `buildozer.spec` file. You should search for the key |
| 157 | + `p4a.source_dir` and set the right value so in the example posted in |
| 158 | + `Common steps` it would look like this:: |
| 159 | + |
| 160 | + p4a.source_dir = /home/user/p4a_pull_requests/p4a-feature-fix-numpy |
| 161 | + |
| 162 | +- Run you buildozer command as usual, eg.:: |
| 163 | + |
| 164 | + buildozer android debug p4a --dist-name=dist-test-feature-fix-numpy |
| 165 | + |
| 166 | +.. note:: this method has the advantage, can be run without installing the |
| 167 | + pull request version of python-for-android nor the android's |
| 168 | + dependencies but has one problem...when things goes wrong you must |
| 169 | + determine if it's a buildozer issue or a python-for-android one |
| 170 | + |
| 171 | +.. warning:: Once you finish the pull request tests remember to comment/edit |
| 172 | + the `p4a.source_dir` constant that you just edited to test the |
| 173 | + pull request |
| 174 | + |
| 175 | +.. tip:: this method it's useful for developing pull requests since you can |
| 176 | + edit `p4a.source_dir` to point to your python-for-android fork and you |
| 177 | + can test any branch you want only switching branches with: |
| 178 | + `git checkout <branch-name>` from inside your python-for-android fork |
0 commit comments