<div dir="ltr">Well, it really does look like checking for the presence of those ANDROID_* environment variables it the best way to recognize the Android platform. Anyone can do that without waiting for a ruling on whether Android is Linux or not (which would be necessary because the docs for sys.platform are quite clear about its value on Linux systems). Googling terms like "is Android Linux" suggests that there is considerable controversy about the issue, so I suggest you don't wait. :-)<br>

</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Aug 2, 2014 at 3:49 PM, Shiz <span dir="ltr"><<a href="mailto:hi@shiz.me" target="_blank">hi@shiz.me</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="">-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA512<br>
<br>
Guido van Rossum wrote:<br>
</div><div class="">> Can you give a few examples of where you'd need to differentiate<br>
> Android from other Linux platforms in otherwise portable code, and<br>
> where testing for the presence or absence of the specific function<br>
> that you'd like to call isn't possible? I know I pretty much never<br>
> test for the difference between OSX and other UNIX variants<br>
> (including Linux) -- the only platform distinction that regularly<br>
> comes up in my own code is Windows vs. the rest. And even there,<br>
> often the right thing to test for is something more specific like<br>
> os.sep.<br>
<br>
</div><div class="">> What's the specific change in stdlib behavior that you're proposing<br>
> for Android?<br>
<br>
</div>The most obvious change would be to subprocess.Popen(). The reason a<br>
generic approach there won't work is also the reason I expect more<br>
changes might be needed: the Android file system doesn't abide by any<br>
POSIX file system standards. Its shell isn't located at /bin/sh, but at<br>
/system/bin/sh. The only directories it provides that are POSIX-standard<br>
are /dev and /etc, to my knowledge. You could check to see if<br>
/system/bin/sh exists and use that first, but that would break the<br>
preferred shell on POSIX systems that happen to have /system for some<br>
reason or another. In short: the preferred shell on POSIX systems is<br>
/bin/sh, but on Android it's /system/bin/sh. Simple existence checking<br>
might break the preferred shell on either. For more specific stdlib<br>
examples I'd have to check the test suite again.<br>
<br>
I can see the point of a sys.platform change not necessarily being<br>
needed, but it would nice for user code too to have a sort-of trivial<br>
way to figure out if it's running on Android. While core CPython might<br>
in general care far less, for user applications it's a bigger deal since<br>
they have to draw GUIs and use system services in a way that *is*<br>
usually very different on Android. Again, platform.linux_distribution()<br>
seems more for display purposes than for applications to check their<br>
core logic against.<br>
In addition, apparently platform.linux_distribution() is getting<br>
deprecated in 3.5 and removed in 3.6[1].<br>
<br>
I agree that above issue should in fact be solved by the earlier-linked<br>
to os.get_preferred_shell() approach, however.<br>
<div class=""><br>
> However, since it's a stdlib module you could easily rely on a<br>
> private API to detect Android, so this doesn't really force the<br>
> sys.platform issue. (Or you could propose a fix that will work for<br>
> Kivi and SL4A as well, e.g. checking for some system file that is<br>
> documented as unique to Android.)<br>
<br>
</div>After checking most of the entire Android file system, I'm not sure if<br>
such a file exists. Sure, a lot of the Android file system hierarchy<br>
isn't really used anywhere else, but I'm not sure a check to see if e.g.<br>
/system exists is really enough to conclude Python is running on Android<br>
on its own. The thing that gets closest (which is the thing my<br>
platform.py patch checks for) is several Android-specific environment<br>
variables being defined (ANDROID_ROOT, ANDROID_DATA,<br>
ANDROID_PROPERTY_WORKSPACE...). Wouldn't it be better to put this in the<br>
standard Python library and expose it somehow, though? It *is* fragile<br>
code, it seems better if applications could 'just rely' on Python to<br>
figure it out, since it's not a trivial check.<br>
<br>
Kind regards,<br>
Shiz<br>
<br>
[1]: <a href="http://bugs.python.org/issue1322#msg207427" target="_blank">http://bugs.python.org/issue1322#msg207427</a><br>
<div class="">-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)<br>
Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org/" target="_blank">http://enigmail.mozdev.org/</a><br>
<br>
</div>iQQcBAEBCgAGBQJT3WrbAAoJEICfd9ZVuxW+CSEgAMgBE12MW1H+MjScIUI19cFi<br>
yCexTCEwu1rApjGYWSUw92Ihr9LnWn4aL7tEBqGXHN5pDctw0/FlGH9d0WhpMz/b<br>
DN0w5ukqx2YyY1EDK7hp1//6eU+tXTGQu890CWgboj5OQF8LXFyN6ReG0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oMHshlI8QloMRbcqDnT<br>
GnrxeiWmJXE/DkpyTbEXUPyCm95ggm+TUfUJ/yb/GhdL1yU9xCjVcxuFmAo5s0WH<br>
k4tra8/vU21V8OzxPmK0eGH9Sl4fUg7JsmAC/Igez+utO7lJLXwfPnUSz+Ls30ao<br>
Xd28IYMsoQ1LCltmfN/fDl3uWJi2e/kZM9v/KTkj9AncvUsDLIOV80AP+remM9E=<br>
=Z0j+<br>
-----END PGP SIGNATURE-----<br>
</blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div>