Skip to content

Commit 8b177ca

Browse files
authored
Merge branch 'main' into improve-codeop-test-coverage
2 parents ef71726 + f4b1d3e commit 8b177ca

8 files changed

Lines changed: 23 additions & 20 deletions

File tree

Doc/library/os.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,9 @@ process and user.
802802
Returns information identifying the current operating system.
803803
The return value is a :class:`uname_result`.
804804

805-
On macOS, iOS and Android, this returns the *kernel* name and version (i.e.,
805+
On macOS, iOS and Android, this returns the *kernel* name and release (i.e.,
806806
``'Darwin'`` on macOS and iOS; ``'Linux'`` on Android). :func:`platform.uname`
807-
can be used to get the user-facing operating system name and version on iOS and
807+
can be used to get the user-facing operating system name and release on iOS and
808808
Android.
809809

810810
.. seealso::

Doc/library/platform.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ Cross platform
141141
Returns the system's release, e.g. ``'2.2.0'`` or ``'NT'``. An empty string is
142142
returned if the value cannot be determined.
143143

144+
On iOS and Android, this is the user-facing OS release. To obtain the
145+
Darwin or Linux kernel release, use :func:`os.uname`.
144146

145147
.. function:: system()
146148

@@ -163,9 +165,6 @@ Cross platform
163165
Returns the system's release version, e.g. ``'#3 on degas'``. An empty string is
164166
returned if the value cannot be determined.
165167

166-
On iOS and Android, this is the user-facing OS version. To obtain the
167-
Darwin or Linux kernel version, use :func:`os.uname`.
168-
169168
.. function:: uname()
170169

171170
Fairly portable uname interface. Returns a :func:`~collections.namedtuple`

Lib/test/test_os/test_os.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,12 +3970,7 @@ def test_does_not_crash(self):
39703970
try:
39713971
size = os.get_terminal_size()
39723972
except OSError as e:
3973-
known_errnos = [errno.EINVAL, errno.ENOTTY]
3974-
if sys.platform == "android":
3975-
# The Android testbed redirects the native stdout to a pipe,
3976-
# which returns a different error code.
3977-
known_errnos.append(errno.EACCES)
3978-
if sys.platform == "win32" or e.errno in known_errnos:
3973+
if sys.platform == "win32" or e.errno in (errno.EINVAL, errno.ENOTTY):
39793974
# Under win32 a generic OSError can be thrown if the
39803975
# handle cannot be retrieved
39813976
self.skipTest("failed to query terminal size")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:func:`os.get_terminal_size` now checks ``isatty`` before calling ``ioctl``,
2+
which reduces log noise on Android.

Modules/posixmodule.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15971,6 +15971,13 @@ os_get_terminal_size_impl(PyObject *module, int fd)
1597115971

1597215972
#ifdef TERMSIZE_USE_IOCTL
1597315973
{
15974+
// On Android, stdout is probably not connected, and calling TIOCGWINSZ
15975+
// on an invalid file descriptor causes a log message "avc: denied {
15976+
// ioctl }". Some common tools such as pytest call get_terminal_size
15977+
// very often, so check it's a TTY first to avoid cluttering the log.
15978+
if (!isatty(fd))
15979+
return PyErr_SetFromErrno(PyExc_OSError);
15980+
1597415981
struct winsize w;
1597515982
if (ioctl(fd, TIOCGWINSZ, &w))
1597615983
return PyErr_SetFromErrno(PyExc_OSError);

Platforms/Android/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def android_env(host):
158158
f"PREFIX={prefix}; "
159159
f". {ENV_SCRIPT}; "
160160
f"export",
161-
check=True, shell=True, capture_output=True, encoding='utf-8',
161+
check=True, shell=True, stdout=subprocess.PIPE, encoding='utf-8',
162162
).stdout
163163

164164
env = {}
@@ -625,7 +625,8 @@ async def read_int(size):
625625
except ValueError:
626626
priority = LogPriority.UNKNOWN
627627

628-
payload_fields = (await read_bytes(payload_len - 1)).split(b"\0")
628+
payload = await read_bytes(payload_len - 1)
629+
payload_fields = payload.split(b"\0")
629630
if len(payload_fields) < 2:
630631
raise ValueError(
631632
f"payload {payload!r} does not contain at least 2 "

Platforms/Android/android-env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
: "${PREFIX:-}" # Path in which to find required libraries
88

99

10-
# Print all messages on stderr so they're visible when running within build-wheel.
10+
# Print all messages on stderr so they're visible when stdout is captured.
1111
log() {
1212
echo "$1" >&2
1313
}
@@ -27,7 +27,7 @@ fail() {
2727
ndk_version=27.3.13750724
2828

2929
ndk=$ANDROID_HOME/ndk/$ndk_version
30-
if ! [ -e "$ndk" ]; then
30+
if ! [ -e "$ndk/package.xml" ]; then
3131
log "Installing NDK - this may take several minutes"
3232
yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" "ndk;$ndk_version"
3333
fi

Platforms/Android/testbed/app/src/main/java/org/python/testbed/MainActivity.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ class PythonTestRunner(val context: Context) {
2828
* @param args Python command-line, encoded as JSON.
2929
* @return The Python exit status: zero on success, nonzero on failure. */
3030
fun run(args: String) : Int {
31-
// We leave argument 0 as an empty string, which is a placeholder for the
32-
// executable name in embedded mode.
31+
// Argument 0 is a placeholder for the executable name in embedded mode.
3332
val argsJsonArray = JSONArray(args)
34-
val argsStringArray = Array<String>(argsJsonArray.length() + 1) { it -> ""}
35-
for (i in 0..<argsJsonArray.length()) {
36-
argsStringArray[i + 1] = argsJsonArray.getString(i)
33+
val argsStringArray = Array<String>(argsJsonArray.length() + 1) { i ->
34+
if (i == 0) ""
35+
else argsJsonArray.getString(i - 1)
3736
}
3837

3938
// Python needs this variable to help it find the temporary directory,

0 commit comments

Comments
 (0)