GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-71052: Change Android's `sys.platform` from "linux" to "android" by mhsmith · Pull Request #116215 · python/cpython

Conversation

@mhsmith

@mhsmith mhsmith commented Mar 1, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

As discussed in PEP 738, although Android is based on Linux, it differs in enough significant ways that a separate name is justified.

Related changes:

  • I've replaced all instances of hasattr(sys, "getandroidapilevel") with a sys.platform check. This is generally easier to read, and more consistent with how the other platforms are handled.

  • I've checked all the places I could find that compare sys.platform to "linux", and added "android" where appropriate. These are mostly in the tests, but there are also a few in the stdlib.

  • Issue: Meta-issue: support of the android platform #71052

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mhsmith
Change Android's sys.platform from "linux" to "android"
20a20c0
@mhsmith
mhsmith requested review from 1st1, FFY00, abalkin, asvetlov, corona10, erlend-aasland, ethanfurman, gpshead, gvanrossum, kumaraditya303, pganssle, vsajip and willingc as code owners March 1, 2024 16:53
@bedevere-app bedevere-app Bot mentioned this pull request Mar 1, 2024
Meta-issue: support of the android platform #71052
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Mar 1, 2024
@erlend-aasland
erlend-aasland removed request for 1st1, FFY00, abalkin, asvetlov, corona10, ethanfurman, gpshead, gvanrossum, kumaraditya303, pganssle, vsajip and willingc March 1, 2024 17:50
FFY00
FFY00 reviewed Mar 1, 2024
View reviewed changes

@FFY00 FFY00 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I think this is a backwards incompatible change, which could result in downstream code breaking. While I think we should probably have a better way to identify Android platforms, I don't know exactly how I feel about this approach. I think at least we should get the input from people shipping and packaging Python on Android.

cc @freakboy3742 @misl6

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland reacted with eyes emoji
All reactions
  • 👀 1 reaction
@erlend-aasland

This comment was marked as outdated.

Sign in to view
@mhsmith

mhsmith commented Mar 1, 2024

Copy link
Copy Markdown
Member Author

@freakboy3742 was actually the one who convinced me to go this way – his reasoning is on the PEP's Discourse thread here.

FFY00 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@freakboy3742

freakboy3742 commented Mar 2, 2024

Copy link
Copy Markdown
Contributor

Hum, I think this is a backwards incompatible change, which could result in downstream code breaking. While I think we should probably have a better way to identify Android platforms, I don't know exactly how I feel about this approach. I think at least we should get the input from people shipping and packaging Python on Android.

As I said in the discussion thread on PEP 738 - I'm a hard +1 on sys.platform == "android".

Yes, this is technically backwards incompatible with the current state of Android support in the CPython source tree. However, I'd counter that:

  1. CPython doesn't currently have official support for Android. It has defacto support by way of "not breaking the build", one additional API entry point (sys.getandroidapilevel()), and a handful of other conditional branches in code; but it's not a Tier 3 platform. To the extent that the ecosystem supports Android currently, that support is very ad hoc, and almost entirely performed by the people tagged in this thread (or at most one degree of separation from those people). There are no Android packages on PyPI.

  2. The current state of detecting Android is the source of so many headaches in the rest of the ecosystem. Yes there is code that will "just run" because Android reports as Linux - but that code is almost always so trivial that it would likely also work on iOS - it's really testing for POSIX, not Linux. Any package that does anything even remotely complicated requires patching to run on Android - at the very least in the build system, and often in user-space code as well. The fact that sys.platform reports as Linux means we need to use workarounds like this one everywhere that we do platform detection, because we can't just use a dictionary lookup. The only other platforms that cause this much headache are the ones that include the OS version in sys.platform - which is a pattern that (thankfully) appears to be slowly undergoing deprecation.

Repeating what I said in the discuss thread: Yes, technically, Android is a Linux. However, that is a distinction that isn't helpful in practice, because “Linux” isn’t just a kernel - it’s lots of other device expectations, filesystem expectations, userspace expectations, and more.

The most practical manifestation of this: If Android is indeed "a Linux", why are any patches needed to CPython at all? Shouldn't Android "just work" as a Linux, or fall out of trivial configuration checks? Unless I'm mistaken, that there are less conditional branches in the test suite for FreeBSD support than are required for Android. If that isn't an indication that Android isn't "a Linux" in practice, I don't know what is.

willingc, erlend-aasland, misl6, FFY00, and johnzhou721 reacted with thumbs up emoji
All reactions
  • 👍 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland
erlend-aasland approved these changes Mar 2, 2024
View reviewed changes

@erlend-aasland erlend-aasland left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for chiming in @freakboy3742.

Looks good to me. I had to look twice at the test_sysconfig change, though 😄

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_os.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Build/2024-03-01-16-44-19.gh-issue-71052.Hs-9EP.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Mar 2, 2024
@mhsmith @erlend-aasland
Apply suggestions from code review
1a97f87
Co-authored-by: Erlend E. Aasland <[email protected]>
@mhsmith

mhsmith commented Mar 4, 2024

Copy link
Copy Markdown
Member Author

@erlend-aasland: I've applied your suggestions, so I think this should be ready to merge now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

FFY00
FFY00 requested changes Mar 4, 2024
View reviewed changes

@FFY00 FFY00 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good to me, the only thing missing is updating the documentation.

We should add Android to the "For other systems (...)" list in the sys.platform documentation (Doc/library/sys.rst), and add a versionchanged field noting this change.

After that, I think we are good to merge, thanks @mhsmith!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting merge labels Mar 4, 2024
@bedevere-app

bedevere-app Bot commented Mar 4, 2024

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhsmith
Update sys.platform documentation
d49bd1a
@mhsmith
mhsmith force-pushed the android-sys-platform branch from 4431efc to d49bd1a Compare March 5, 2024 13:46
@mhsmith

mhsmith commented Mar 5, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again.

I've also cleaned up the sys.platform documentation as follows:

  • Removed the reference to "append platform-specific components to sys.path". This has not been true since Python 3.7 (https://bugs.python.org/issue28046).
  • Added iOS as specified in PEP 730.
  • Sorted the table in alphabetical order.
  • Moved the table to the top, since it now contains all supported platforms [EDIT – except FreeBSD].
  • Removed recommendation to use startswith on Linux and AIX. The last Python version to require this for Linux was 3.2, and the last for AIX was 3.7, both of which are now obsolete.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting change review and removed awaiting changes labels Mar 5, 2024
@bedevere-app

bedevere-app Bot commented Mar 5, 2024

Copy link
Copy Markdown

Thanks for making the requested changes!

@erlend-aasland, @FFY00: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app
bedevere-app Bot requested review from FFY00 and erlend-aasland March 5, 2024 13:55
FFY00
FFY00 approved these changes Mar 11, 2024
View reviewed changes

@FFY00 FFY00 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhsmith, sorry for the delay, the documentation changes look good to me, thank you!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting change review labels Mar 11, 2024
@FFY00
FFY00 merged commit 872c071 into python:main Mar 11, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 11, 2024
@mhsmith mhsmith mentioned this pull request Mar 11, 2024
Add support for Android as a target platform #116622
Closed
@mhsmith mhsmith mentioned this pull request Apr 5, 2024
gh-116622: Test updates for Android #117299
Merged
thunder-coding added a commit to thunder-coding/maturin that referenced this pull request Feb 13, 2026
@thunder-coding
fix: platform.system() on Android for Python 3.13+
71b9f83
Python from 3.13 onwards supports Android as an official platform. As a
part of this official support, there were a bunch of changes including
`platform.system()` returning "Android" and `sys.platform` being
"android" instead of "Linux" and "linux" on earlier versions. This is a
breaking change.

Also try to be backwards compatible while running on Android for older
python versions in environments like Termux

This maturin bug was found as a part of testing of builds of python
packages for Termux as part of Python 3.13 migration. Downstream Python
distribution update PR: termux/termux-packages#27739

Ideally we would like to ensure that get_python_os() returns "linux" for
Python versions <= 3.12, but that'd require additional work in supplying
python version to get_python_os(), but that'd complicate some things.
This works well enough, and shouldn't be necessary in future when Python
>= 3.13 becomes the standard target by most (which should ideally happen
soon since upstream Python is supporting Android from this version).

My analysis of maturin reveal that get_python_os() returning "android"
shouldn't cause any effects on Android targets that do need to be
patched.

Issue also reported to maturin in PyO3#2945

Partially based of off work by @robertkirkman in the linked issue.
Further fixup was done to ensure suitability for upstream acceptance.

Ref: python/cpython#116215
@thunder-coding thunder-coding mentioned this pull request Feb 13, 2026
fix: platform.system() on Android for Python 3.13+ PyO3/maturin#2992
Merged
messense pushed a commit to PyO3/maturin that referenced this pull request Feb 13, 2026
@thunder-coding
fix: platform.system() on Android for Python 3.13+ (#2992)
a23a6b5
Python from 3.13 onwards supports Android as an official platform. As a
part of this official support, there were a bunch of changes including
`platform.system()` returning "Android" and `sys.platform` being
"android" instead of "Linux" and "linux" on earlier versions. This is a
breaking change.

Also try to be backwards compatible while running on Android for older
python versions in environments like Termux

This maturin bug was found as a part of testing of builds of python
packages for Termux as part of Python 3.13 migration. Downstream Python
distribution update PR:
termux/termux-packages#27739

Ideally we would like to ensure that get_python_os() returns "linux" for
Python versions <= 3.12, but that'd require additional work in supplying
python version to get_python_os(), but that'd complicate some things.
This works well enough, and shouldn't be necessary in future when Python
>= 3.13 becomes the standard target by most (which should ideally happen
soon since upstream Python is supporting Android from this version).

My analysis of maturin reveal that get_python_os() returning "android"
shouldn't cause any side effects for Python <= 3.12 on Android.

Issue also reported to maturin in
#2945

Partially based of off work by @robertkirkman in the linked issue.
Further fixup was done to ensure suitability for upstream acceptance.

Ref: python/cpython#116215

CC @mhsmith Android support for Python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@FFY00 FFY00 FFY00 approved these changes
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@mhsmith @erlend-aasland @freakboy3742 @FFY00
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.