]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Minor fixes for Android (#154895)
authorMalcolm Smith <smith@chaquo.com>
Thu, 30 Jul 2026 02:31:40 +0000 (03:31 +0100)
committerGitHub <noreply@github.com>
Thu, 30 Jul 2026 02:31:40 +0000 (10:31 +0800)
A collection of small cleanups for Android support:

* Clarifies the documentation around version number handling for iOS and
  Android in os.uname and platform.release
* Ensures that automated NDK installs surface messages written to stderr
* Makes the Android NDK check more robust for incomplete downloads
* Corrects some linting errors in Android build scripts

Doc/library/os.rst
Doc/library/platform.rst
Platforms/Android/__main__.py
Platforms/Android/android-env.sh
Platforms/Android/testbed/app/src/main/java/org/python/testbed/MainActivity.kt

index be7ea26356bebe34f3b0ebb4d29a3595fa495fc0..7bdf415db655f329c53e9bea8878174b07599bb8 100644 (file)
@@ -802,9 +802,9 @@ process and user.
    Returns information identifying the current operating system.
    The return value is a :class:`uname_result`.
 
-   On macOS, iOS and Android, this returns the *kernel* name and version (i.e.,
+   On macOS, iOS and Android, this returns the *kernel* name and release (i.e.,
    ``'Darwin'`` on macOS and iOS; ``'Linux'`` on Android). :func:`platform.uname`
-   can be used to get the user-facing operating system name and version on iOS and
+   can be used to get the user-facing operating system name and release on iOS and
    Android.
 
    .. seealso::
index 1d30966794fd1bfdd35477bc6be42c95ee68f360..f728a7b32e789f482c93f4d0cdde452f6dedf140 100644 (file)
@@ -141,6 +141,8 @@ Cross platform
    Returns the system's release, e.g. ``'2.2.0'`` or ``'NT'``. An empty string is
    returned if the value cannot be determined.
 
+   On iOS and Android, this is the user-facing OS release. To obtain the
+   Darwin or Linux kernel release, use :func:`os.uname`.
 
 .. function:: system()
 
@@ -163,9 +165,6 @@ Cross platform
    Returns the system's release version, e.g. ``'#3 on degas'``. An empty string is
    returned if the value cannot be determined.
 
-   On iOS and Android, this is the user-facing OS version. To obtain the
-   Darwin or Linux kernel version, use :func:`os.uname`.
-
 .. function:: uname()
 
    Fairly portable uname interface. Returns a :func:`~collections.namedtuple`
index 78f94b317ab04781606114a29a65da58531f0629..705ca6f26221fdad730ead01fc3b7c32ce6a09c2 100755 (executable)
@@ -158,7 +158,7 @@ def android_env(host):
         f"PREFIX={prefix}; "
         f". {ENV_SCRIPT}; "
         f"export",
-        check=True, shell=True, capture_output=True, encoding='utf-8',
+        check=True, shell=True, stdout=subprocess.PIPE, encoding='utf-8',
     ).stdout
 
     env = {}
@@ -625,7 +625,8 @@ async def read_logcat(stream):
     except ValueError:
         priority = LogPriority.UNKNOWN
 
-    payload_fields = (await read_bytes(payload_len - 1)).split(b"\0")
+    payload = await read_bytes(payload_len - 1)
+    payload_fields = payload.split(b"\0")
     if len(payload_fields) < 2:
         raise ValueError(
             f"payload {payload!r} does not contain at least 2 "
index 5859c0eac4a88fb552c495d46b77422ac5cdc2f0..59ce2eeb7d622448451588f8cbf05587dbd79efe 100644 (file)
@@ -7,7 +7,7 @@
 : "${PREFIX:-}"  # Path in which to find required libraries
 
 
-# Print all messages on stderr so they're visible when running within build-wheel.
+# Print all messages on stderr so they're visible when stdout is captured.
 log() {
     echo "$1" >&2
 }
@@ -27,7 +27,7 @@ fail() {
 ndk_version=27.3.13750724
 
 ndk=$ANDROID_HOME/ndk/$ndk_version
-if ! [ -e "$ndk" ]; then
+if ! [ -e "$ndk/package.xml" ]; then
     log "Installing NDK - this may take several minutes"
     yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" "ndk;$ndk_version"
 fi
index dc49cdb9a9f73952cbf7752502a793ba02b4aeae..c8fe3acd849ac7a876fabc228931d61eb7d249a9 100644 (file)
@@ -28,12 +28,11 @@ class PythonTestRunner(val context: Context) {
      * @param args Python command-line, encoded as JSON.
      * @return The Python exit status: zero on success, nonzero on failure. */
     fun run(args: String) : Int {
-        // We leave argument 0 as an empty string, which is a placeholder for the
-        // executable name in embedded mode.
+        // Argument 0 is a placeholder for the executable name in embedded mode.
         val argsJsonArray = JSONArray(args)
-        val argsStringArray = Array<String>(argsJsonArray.length() + 1) { it -> ""}
-        for (i in 0..<argsJsonArray.length()) {
-            argsStringArray[i + 1] = argsJsonArray.getString(i)
+        val argsStringArray = Array<String>(argsJsonArray.length() + 1) { i ->
+            if (i == 0) ""
+            else argsJsonArray.getString(i - 1)
         }
 
         // Python needs this variable to help it find the temporary directory,