|
| 1 | +""" |
| 2 | +This is the `setup.py` file for the `on device unit test app`. |
| 3 | +
|
| 4 | +In this module we can control how will be built our test app. Depending on |
| 5 | +our requirements we can build an kivy, flask or a non-gui app. We default to an |
| 6 | +kivy app, since the python-for-android project its a sister project of kivy. |
| 7 | +
|
| 8 | +The parameter `requirements` is crucial to determine the unit tests we will |
| 9 | +perform with our app, so we must explicitly name the recipe we want to test |
| 10 | +and, of course, we should have the proper test for the given recipe at |
| 11 | +`tests.test_requirements.py` or nothing will be tested. We control our default |
| 12 | +app requirements via the dictionary `options`. Here you have some examples |
| 13 | +to build the supported app modes:: |
| 14 | +
|
| 15 | + - kivy *basic*: `sqlite3,libffi,openssl,pyjnius,kivy,python3,requests` |
| 16 | + - kivy *images/graphs*: `kivy,python3,numpy,matplotlib,Pillow` |
| 17 | + - kivy *encryption*: `kivy,python3,cryptography,pycryptodome,scrypt, |
| 18 | + m2crypto,pysha3` |
| 19 | + - flask (with webview bootstrap): `sqlite3,libffi,openssl,pyjnius,flask, |
| 20 | + python3,genericndkbuild` |
| 21 | +
|
| 22 | +
|
| 23 | +.. note:: just noting that, for the `kivy basic` app, we add the requirements: |
| 24 | + `sqlite3,libffi,openssl` so this way we will trigger the unit tests |
| 25 | + that we have for such recipes. |
| 26 | +
|
| 27 | +.. tip:: to force `python-for-android` generate an `flask` app without using |
| 28 | + the kwarg `bootstrap`, we add the recipe `genericndkbuild`, which will |
| 29 | + trigger the `webview bootstrap` at build time. |
| 30 | +""" |
| 31 | + |
| 32 | +import os |
| 33 | +import sys |
| 34 | +from distutils.core import setup |
| 35 | +from setuptools import find_packages |
| 36 | + |
| 37 | +# define a basic test app, which can be override passing the proper args to cli |
| 38 | +options = { |
| 39 | + 'apk': |
| 40 | + { |
| 41 | + 'requirements': |
| 42 | + 'sqlite3,libffi,openssl,pyjnius,kivy,python3,requests', |
| 43 | + 'android-api': 27, |
| 44 | + 'ndk-api': 21, |
| 45 | + 'dist-name': 'bdist_unit_tests_app', |
| 46 | + 'arch': 'armeabi-v7a', |
| 47 | + 'permissions': ['INTERNET', 'VIBRATE'], |
| 48 | + 'orientation': 'sensor', |
| 49 | + 'service': 'P4a_test_service:app_service.py', |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +# check if we overwrote the default test_app requirements via `cli` |
| 54 | +requirements = options['apk']['requirements'].rsplit(',') |
| 55 | +for n, arg in enumerate(sys.argv): |
| 56 | + if arg == '--requirements': |
| 57 | + print('found requirements') |
| 58 | + requirements = sys.argv[n + 1].rsplit(',') |
| 59 | + break |
| 60 | + |
| 61 | +# remove `orientation` in case that we don't detect a kivy or flask app, |
| 62 | +# since the `service_only` bootstrap does not support such argument |
| 63 | +if not ({'kivy', 'flask'} & set(requirements)): |
| 64 | + options['apk'].pop('orientation') |
| 65 | + |
| 66 | +# write a file to let the test_app know which requirements we want to test |
| 67 | +# Note: later, when running the app, we will guess if we have the right test. |
| 68 | +app_requirements_txt = os.path.join( |
| 69 | + os.path.split(__file__)[0], |
| 70 | + 'test_app', |
| 71 | + 'app_requirements.txt', |
| 72 | +) |
| 73 | +with open(app_requirements_txt, 'w') as requirements_file: |
| 74 | + for req in requirements: |
| 75 | + requirements_file.write(f'{req.split("==")[0]}\n') |
| 76 | + |
| 77 | +# run the install |
| 78 | +setup( |
| 79 | + name='unit_tests_app', |
| 80 | + version='1.1', |
| 81 | + description='p4a on device unit test app', |
| 82 | + author='Alexander Taylor, Pol Canelles', |
| 83 | + author_email='alexanderjohntaylor@gmail.com, canellestudi@gmail.com', |
| 84 | + packages=find_packages(), |
| 85 | + options=options, |
| 86 | + package_data={ |
| 87 | + 'test_app': ['*.py', '*.kv', '*.txt'], |
| 88 | + 'test_app/static': ['*.png', '*.css', '*.otf'], |
| 89 | + 'test_app/templates': ['*.html'], |
| 90 | + 'test_app/tests': ['*.py'], |
| 91 | + } |
| 92 | +) |
0 commit comments