[Python-Dev] Exposing the Android platform existence to Python modules

Shiz hi at shiz.me
Fri Aug 1 02:59:41 CEST 2014


Hi folks,

I’m working on porting CPython to the Android platform, and while making decent progress, I’m currently stuck at a higher-level issue than adding #ifdefs for __ANDROID__ to C extension modules.

The idea is, not only CPython extension modules have some assumptions that don’t seem to fit Android’s mold, some default Python-written modules do as well. However, whereas CPython extensions can trivially check if we’re building for Android by checking the __ANDROID__ compiler macro, Python modules can do no such check, and are left wondering how to figure out if the platform they are currently running on is an Android one. To my knowledge there is no reliable way to detect if one is using Android as a vehicle for their journey using any other way.

Now, the main question is: what would be the best way to ‘expose’ the indication that Android is being ran on to Python-living modules? My own thought was to add sys.getlinuxuserland(), or platform.linux_userland(), in similar vein to sys.getwindowsversion() and platform.linux_distribution(), which could return information about the userland of running CPython instance, instead of knowing merely the kernel and the distribution.

This way, code could trivially check if it ran on the GNU(+associates) userland, or under a BSD-ish userland, or Android… and adjust its behaviour accordingly.

I would be delighted to hear comments on this proposal, or better yet, alternative solutions. :)

Kind regards,
Shiz

P.S.: I am well aware that Android might as well never be officially supported in CPython. In that case, consider this a thought experiment of how it /would/ be handled. :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 1495 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140801/7ba4c972/attachment.sig>


More information about the Python-Dev mailing list