Add support for Android and iOS platforms#12220
Add support for Android and iOS platforms#12220timrid wants to merge 5 commits intoaio-libs:masterfrom
Conversation
for more information, see https://pre-commit.ci
Have you tested a simple server app too? |
Not yet, but I can also do a simple test for this. But it will take a few days. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12220 +/- ##
==========================================
- Coverage 99.11% 99.08% -0.03%
==========================================
Files 130 130
Lines 45373 45420 +47
Branches 2397 2401 +4
==========================================
+ Hits 44970 45006 +36
- Misses 271 278 +7
- Partials 132 136 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
I now added the unittests for Android and iOS to the CI, to verify that everything is working. To run the unittests I use cibuildwheel, that automatically starts an Android Emulator / iOS Simulator and runs the whole pytests inside this Emulator/Simulator. The only issue is that the unit tests have some binary dependencies that aren't yet available for Android and iOS. Hopefully this will improve over time, but for now I had to add environment markers to quite a few dependencies and skip the tests that use these dependencies. Another problem was that pip-compile doesn’t use the environment markers for transitive dependencies as well. Therefore, I had to include some of the transitive dependencies in the |
There was a problem hiding this comment.
This seems a bit messy to maintain. Maybe @webknjaz has a better idea.
| cryptography; sys_platform != 'android' and sys_platform != 'ios' # used by trustme | ||
| forbiddenfruit; implementation_name == "cpython" and sys_platform != 'android' and sys_platform != 'ios' # used by blockbuster | ||
| freezegun | ||
| isal; python_version < "3.14" # no wheel for 3.14 |
There was a problem hiding this comment.
The 3.14 check is actually not needed anymore.
| try: | ||
| import trustme | ||
| except ImportError: # pragma: no cover | ||
| pass |
There was a problem hiding this comment.
Shouldn't need this and the importerskip, right?
| trustme = pytest.importorskip("trustme") | ||
| return trustme.CA() # type: ignore[no-any-return] |
There was a problem hiding this comment.
| trustme = pytest.importorskip("trustme") | |
| return trustme.CA() # type: ignore[no-any-return] | |
| if TYPE_CHECKING: | |
| import trustme | |
| else: | |
| trustme = pytest.importorskip("trustme") | |
| return trustme.CA() |
|
|
||
| try: | ||
| import trustme | ||
| except ImportError: # pragma: no cover |
There was a problem hiding this comment.
This should be covered if we need it. If we see the coverage disappear, then we no longer need the except.
| except ImportError: # pragma: no cover | |
| except ImportError: |
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| sys.platform in ("android", "ios"), reason="README.md not supported" |
There was a problem hiding this comment.
I'm unclear what this reason means?
| speedups = [ | ||
| "aiodns >= 3.3.0", | ||
| "Brotli >= 1.2; platform_python_implementation == 'CPython'", | ||
| "aiodns >= 3.3.0; sys_platform != 'android' and sys_platform != 'ios'", |
There was a problem hiding this comment.
If you could make a PR to pycares to support this, we could probably get this resolved pretty quick. Unless there's a technical difficulty in supporting these platforms?
| isal; python_version < "3.14" and sys_platform != 'android' and sys_platform != 'ios' # no wheel for 3.14 | ||
| librt; platform_python_implementation != 'PyPy' and sys_platform != 'android' and sys_platform != 'ios' # used by mypy | ||
| mypy; implementation_name == "cpython" and sys_platform != 'android' and sys_platform != 'ios' | ||
| mypy-extensions; sys_platform != 'android' and sys_platform != 'ios' # used by mypy |
There was a problem hiding this comment.
In fact, why would we even need these extra dependencies here? If this is pulled in by mypy and we've already excluded mypy, then surely it won't get pulled in..?
There was a problem hiding this comment.
Another problem was that pip-compile doesn’t use the environment markers for transitive dependencies as well. Therefore, I had to include some of the transitive dependencies in the *.in files so that I could explicitly set the environment markers there.
| CIBW_TEST_REQUIRES: -r requirements/test.txt | ||
| CIBW_TEST_SOURCES: setup.cfg tests | ||
| CIBW_TEST_COMMAND: >- | ||
| python -m pytest -o 'addopts='-v -ra --showlocals -m 'not dev_mode and not autobahn' |
There was a problem hiding this comment.
This workflow is missing the coverage steps, which is why codecov is complaining.
What do these changes do?
This PR adds support for Android and iOS platforms.
Since Python 3.13, Android (PEP738) and iOS (PEP730) are officially supported. In addition, Android and iOS have been supported since cibuildwheel v3.1. This makes it very easy to build wheels for Android and iOS.
PyPI now also supports uploading Android and iOS wheels (see pypi/warehouse#17559).
At https://beeware.org/mobile-wheels/, you can find an overview of all binary packages available for Android and iOS. Currently, there aren't that many, but I hope
aiohttpwill appear there soon :)Are there changes in behavior for the user?
No.
Is it a substantial burden for the maintainers to support this?
Most of the compiling work is taken care of by cibuildwheel. However, the pytests are currently not run on Android and iOS, so it is theoretically possible that there may be problems during runtime on Android/iOS.
In principle, cibuildwheel also offers the option of running the pytests on Android and iOS using
test-command, but this requires the Android emulator/iOS simulator to be started in the CI, which significantly slows down the building of the wheels. In addition,test-commandis not currently used, which would require more adjustments to the CI. Therefore, I have decided not to use it for now and have only manually performed a very simple “smoke test” in a briefcase application to check whether the wheel is importable and usable.Related issue number
Fixes #11750
Checklist
CONTRIBUTORS.txtCHANGES/folder