Skip to content

gh-71042: Add platform.android_ver#116674

Merged
vstinner merged 9 commits into
python:mainfrom
mhsmith:platform-android-ver
Mar 27, 2024
Merged

gh-71042: Add platform.android_ver#116674
vstinner merged 9 commits into
python:mainfrom
mhsmith:platform-android-ver

Conversation

@mhsmith

@mhsmith mhsmith commented Mar 12, 2024

Copy link
Copy Markdown
Member

This PR implements the platform.android_ver function specified in PEP 738.

It also uses the new function to do the following:

  • Implement platform.system and platform.release as specified in the PEP
  • Skip tests of some socket functionality which is broken on older versions of Android

📚 Documentation preview 📚: https://cpython-previews--116674.org.readthedocs.build/

Comment thread Lib/test/test_platform.py

@willingc willingc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mhsmith I did a quick look over the docs and made a couple of comments.

Comment thread Doc/library/platform.rst Outdated
@mhsmith

mhsmith commented Mar 25, 2024

Copy link
Copy Markdown
Member Author

Consistent with iOS in #117052, I've removed the min_api_level field, which was always a bit out of place because it isn't a property of the current device. This information is still available from sys.getandroidapilevel, and will also be added to sysconfig.get_platform in a future PR.

@FFY00 FFY00 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 25, 2024
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @FFY00 for commit 646441b 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 25, 2024

@FFY00 FFY00 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me. Thank you @mhsmith!

Comment thread Lib/test/pythoninfo.py Outdated
Comment thread Lib/test/test_asyncio/test_base_events.py Outdated
Comment thread Lib/test/test_platform.py Outdated
Comment thread Lib/test/test_socket.py Outdated
Comment thread Lib/platform.py
Comment thread Lib/platform.py Outdated
mhsmith and others added 2 commits March 26, 2024 18:23
Co-authored-by: Victor Stinner <vstinner@python.org>
@mhsmith

mhsmith commented Mar 26, 2024

Copy link
Copy Markdown
Member Author

Sorry for the late change, but I've also added an is_emulator field, similar to the is_simulator field in platform.ios_ver (#117052). The names match the terminology used on each platform, which makes sense because both of them are platform-specific APIs.

Since Android emulators and physical devices use the same ABI, I didn't originally think there was any need for this flag. But I've now found two cases where small-scale timing issues prevent some emulators from running a test reliably:

  • One of these already had a workaround at setswitchinterval in test/support/__init__.py, so I've updated that to use the new API, and also limited the workaround to old versions of Android, based on my tests.
  • The other is in the timerfd tests, and will be added to #117223 after this PR is merged.

@mhsmith

mhsmith commented Mar 27, 2024

Copy link
Copy Markdown
Member Author

@vstinner: Are you able to merge this?

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The change mostly LGTM, but here is another round of review.

Comment thread Doc/library/platform.rst Outdated

* ``release`` - Android version, as a string (e.g. ``"14"``)

* ``api_level`` - API level, as an integer (e.g. ``34``)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would you mind to repeat here the difference with https://docs.python.org/dev/library/sys.html#sys.getandroidapilevel and so add a reference to the sys function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea; done.

Comment thread Doc/library/platform.rst Outdated
Comment thread Doc/library/platform.rst Outdated
Comment thread Doc/library/platform.rst Outdated
Comment thread Doc/library/platform.rst Outdated
Comment thread Lib/platform.py
# a missing one.
return default
else:
return buffer.value.decode("UTF-8", "backslashreplace")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you consider "surrogateescape" to not lose information? The caller can then decide how to handle surrogate characters. Did you see strings which cannot be decoded from UTF-8 in practice?

@mhsmith mhsmith Mar 27, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I haven't seen such strings, but this function is likely to be used when building error reports, so perfect round-tripping is less important than making sure it doesn't cause any errors itself.

For that reason, I'd prefer not to use surrogateescape, because surrogates can't be turned back into bytes unless the encode call uses surrogateescape as well, which is something we have no control over, and something the programmer is very unlikely to test.

Comment thread Lib/test/pythoninfo.py
Comment on lines +182 to +183
if sys.platform == 'android':
call_func(info_add, 'platform.android_ver', platform, 'android_ver')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FYI you can just call:

Suggested change
if sys.platform == 'android':
call_func(info_add, 'platform.android_ver', platform, 'android_ver')
call_func(info_add, 'platform.android_ver', platform, 'android_ver')

It does nothing if the function doesn't exist.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Like the other platform.*_ver functions, android_ver does exist on all platforms, but returns empty values when not running on Android. There's no point in cluttering the report in that case.

Comment thread Lib/test/support/__init__.py Outdated
Co-authored-by: Victor Stinner <vstinner@python.org>
@mhsmith mhsmith requested a review from vstinner March 27, 2024 16:14
@vstinner vstinner merged commit 74c8568 into python:main Mar 27, 2024
@vstinner

Copy link
Copy Markdown
Member

Merged, thanks. Welcome Android :-)

@mhsmith mhsmith mentioned this pull request Sep 20, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UDPLITE tests fail on android Add platform.android_ver() to test.pythoninfo for Android platforms android: add platform.android_ver()

5 participants