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

Glenn Linderman v+python at g.nevcal.com
Fri Aug 1 03:54:53 CEST 2014


On 7/31/2014 5:59 PM, Shiz wrote:
> 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.

I've no idea what you mean by "userland" in your suggestions above or 
below, but doesn't the Android environment qualify as a 
(multi-versioned) platform independently of its host OS? Seems I've read 
about an Android reimplementation for Windows, for example. As long as 
all the services expected by Android are faithfully produced, the host 
OS may be irrelevant to an Android application... in which case, I would 
think/propose/suggest the platform name should change from win32 or 
linux to Android (and the Android version be reflected in version parts).

> 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. :)

Is your P.S. suggestive that you would not be willing to support your 
port for use by others?  Of course, until it is somewhat complete, it is 
hard to know how complete and compatible it can be.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140731/02b1661e/attachment.html>


More information about the Python-Dev mailing list