Skip to content

Commit 60b9a41

Browse files
authored
Merge branch 'main' into pythongh-157176
2 parents ad2aa7b + 024b6bc commit 60b9a41

20 files changed

Lines changed: 628 additions & 127 deletions

‎Doc/library/os.rst‎

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,13 @@ process and user.
574574
the groups of which the specified username is a member, plus the specified
575575
group id.
576576

577-
.. availability:: Unix, not WASI, not Android.
577+
.. availability:: Unix, not WASI.
578578

579579
.. versionadded:: 3.2
580580

581+
.. versionchanged:: 3.16
582+
Support for Android now exists.
583+
581584

582585
.. function:: putenv(key, value, /)
583586

@@ -610,21 +613,30 @@ process and user.
610613

611614
Set the current process's effective group id.
612615

613-
.. availability:: Unix, not WASI, not Android.
616+
.. availability:: Unix, not WASI.
617+
618+
.. versionchanged:: 3.16
619+
Support for Android now exists.
614620

615621

616622
.. function:: seteuid(euid, /)
617623

618624
Set the current process's effective user id.
619625

620-
.. availability:: Unix, not WASI, not Android.
626+
.. availability:: Unix, not WASI.
627+
628+
.. versionchanged:: 3.16
629+
Support for Android now exists.
621630

622631

623632
.. function:: setgid(gid, /)
624633

625634
Set the current process' group id.
626635

627-
.. availability:: Unix, not WASI, not Android.
636+
.. availability:: Unix, not WASI.
637+
638+
.. versionchanged:: 3.16
639+
Support for Android now exists.
628640

629641

630642
.. function:: setgroups(groups, /)
@@ -718,32 +730,44 @@ process and user.
718730

719731
Set the current process's real and effective group ids.
720732

721-
.. availability:: Unix, not WASI, not Android.
733+
.. availability:: Unix, not WASI.
734+
735+
.. versionchanged:: 3.16
736+
Support for Android now exists.
722737

723738

724739
.. function:: setresgid(rgid, egid, sgid, /)
725740

726741
Set the current process's real, effective, and saved group ids.
727742

728-
.. availability:: Unix, not WASI, not Android, not macOS, not iOS.
743+
.. availability:: Unix, not WASI, not macOS, not iOS.
729744

730745
.. versionadded:: 3.2
731746

747+
.. versionchanged:: 3.16
748+
Support for Android now exists.
749+
732750

733751
.. function:: setresuid(ruid, euid, suid, /)
734752

735753
Set the current process's real, effective, and saved user ids.
736754

737-
.. availability:: Unix, not WASI, not Android, not macOS, not iOS.
755+
.. availability:: Unix, not WASI, not macOS, not iOS.
738756

739757
.. versionadded:: 3.2
740758

759+
.. versionchanged:: 3.16
760+
Support for Android now exists.
761+
741762

742763
.. function:: setreuid(ruid, euid, /)
743764

744765
Set the current process's real and effective user ids.
745766

746-
.. availability:: Unix, not WASI, not Android.
767+
.. availability:: Unix, not WASI.
768+
769+
.. versionchanged:: 3.16
770+
Support for Android now exists.
747771

748772

749773
.. function:: getsid(pid, /)
@@ -766,7 +790,10 @@ process and user.
766790

767791
Set the current process's user id.
768792

769-
.. availability:: Unix, not WASI, not Android.
793+
.. availability:: Unix, not WASI.
794+
795+
.. versionchanged:: 3.16
796+
Support for Android now exists.
770797

771798

772799
.. placed in this section since it relates to errno.... a little weak
@@ -2324,11 +2351,14 @@ features:
23242351

23252352
Change the root directory of the current process to *path*.
23262353

2327-
.. availability:: Unix, not WASI, not Android.
2354+
.. availability:: Unix, not WASI.
23282355

23292356
.. versionchanged:: 3.6
23302357
Accepts a :term:`path-like object`.
23312358

2359+
.. versionchanged:: 3.16
2360+
Support for Android now exists.
2361+
23322362

23332363
.. function:: fchdir(fd)
23342364

‎Doc/library/socket.rst‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,10 +1372,13 @@ The :mod:`!socket` module also offers various network-related services:
13721372

13731373
.. audit-event:: socket.sethostname name socket.sethostname
13741374

1375-
.. availability:: Unix, not Android.
1375+
.. availability:: Unix.
13761376

13771377
.. versionadded:: 3.3
13781378

1379+
.. versionchanged:: 3.16
1380+
Support for Android now exists.
1381+
13791382

13801383
.. function:: if_nameindex()
13811384

‎Doc/using/configure.rst‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,16 @@ See :source:`Platforms/Apple/iOS/README.md`.
13421342

13431343
Specify the name for the framework (default: ``Python``).
13441344

1345+
An iOS build configured without ``--enable-framework`` produces a static
1346+
``libpython``, for embedding directly in an app binary. Such a build cannot
1347+
load extension modules at runtime, and so does not support binary wheels; it
1348+
requires ``MODULE_BUILDTYPE=static`` and :option:`--disable-test-modules`, and
1349+
rejects :option:`--enable-shared`. See
1350+
:source:`Platforms/Apple/iOS/README.md` for the full list of limitations.
1351+
1352+
.. versionadded:: 3.16
1353+
iOS builds may be configured without a framework.
1354+
13451355

13461356
Cross Compiling Options
13471357
-----------------------

‎Doc/using/ios.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ should ensure these stub binaries are on your path.
142142
Installing Python on iOS
143143
========================
144144

145+
The official iOS release artefact is a framework build, distributed as an
146+
``XCFramework``; this is the configuration described in the rest of this
147+
document, and the only one that supports binary extension modules. Static
148+
builds, where ``libpython`` and every extension module are linked directly into
149+
the app binary, are also possible, with limitations; see
150+
:source:`Platforms/Apple/iOS/README.md` for details.
151+
145152
Tools for building iOS apps
146153
---------------------------
147154

‎Doc/whatsnew/3.16.rst‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ os
474474
process via a pidfd. Available on Linux 5.6+.
475475
(Contributed by Maurycy Pawłowski-Wieroński in :gh:`149464`.)
476476

477+
* The following functions are now available on Android:
478+
:func:`os.chroot`, :func:`os.initgroups`, :func:`os.setegid`,
479+
:func:`os.seteuid`, :func:`os.setgid`, :func:`os.setregid`,
480+
:func:`os.setresgid`, :func:`os.setresuid`, :func:`os.setreuid`,
481+
and :func:`os.setuid`. Calling them without sufficient privileges
482+
now raises :exc:`PermissionError` instead of the functions being unavailable.
483+
(Contributed by Md Arif in :gh:`152936`.)
484+
477485

478486
pydoc
479487
-----
@@ -513,6 +521,15 @@ shlex
513521
(Contributed by Jay Berry in :gh:`148846`.)
514522

515523

524+
socket
525+
------
526+
527+
* The :func:`socket.sethostname` function is now available on Android.
528+
Calling it without sufficient privileges now raises :exc:`PermissionError`
529+
instead of the function being unavailable.
530+
(Contributed by Md Arif in :gh:`152936`.)
531+
532+
516533
sqlite3
517534
-------
518535

‎Lib/pdb.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
import signal
8585
import socket
8686
import typing
87-
import asyncio
8887
import inspect
8988
import weakref
9089
import builtins
@@ -102,6 +101,8 @@
102101
from types import CodeType
103102
from warnings import deprecated
104103

104+
lazy import asyncio
105+
105106
try:
106107
import _pyrepl.utils
107108
except ModuleNotFoundError:
@@ -902,6 +903,10 @@ def _hold_exceptions(self, exceptions):
902903
self._chained_exception_index = 0
903904

904905
def _get_asyncio_task(self):
906+
# If asyncio has never been imported there cannot be a running task,
907+
# so skip the import rather than pay for it on every interaction.
908+
if 'asyncio' not in sys.modules:
909+
return None
905910
try:
906911
task = asyncio.current_task()
907912
except RuntimeError:

‎Lib/test/test_os/test_posix.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def test_getresgid(self):
107107
@unittest.skipUnless(hasattr(posix, 'setresuid'),
108108
'test needs posix.setresuid()')
109109
def test_setresuid(self):
110+
# Android blocks this function for non-root users regardless of the arguments.
111+
if support.is_android and os.getuid() != 0:
112+
self.assertRaises(PermissionError, posix.setresuid, -1, -1, -1)
113+
return
110114
current_user_ids = posix.getresuid()
111115
self.assertIsNone(posix.setresuid(*current_user_ids))
112116
# -1 means don't change that value.
@@ -124,6 +128,10 @@ def test_setresuid_exception(self):
124128
@unittest.skipUnless(hasattr(posix, 'setresgid'),
125129
'test needs posix.setresgid()')
126130
def test_setresgid(self):
131+
# Android blocks this function for non-root users regardless of the arguments.
132+
if support.is_android and os.getuid() != 0:
133+
self.assertRaises(PermissionError, posix.setresgid, -1, -1, -1)
134+
return
127135
current_group_ids = posix.getresgid()
128136
self.assertIsNone(posix.setresgid(*current_group_ids))
129137
# -1 means don't change that value.

‎Lib/test/test_readline.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,44 @@ def test_write_read_limited_history(self):
169169
# Readline seems to report an additional history element.
170170
self.assertIn(readline.get_current_history_length(), (2, 3))
171171

172+
def test_write_read_zero_length_history(self):
173+
previous_length = readline.get_history_length()
174+
self.addCleanup(readline.set_history_length, previous_length)
175+
176+
readline.clear_history()
177+
readline.add_history("first line")
178+
readline.set_history_length(0)
179+
readline.write_history_file(TESTFN)
180+
self.addCleanup(os.remove, TESTFN)
181+
182+
readline.clear_history()
183+
# libedit cannot read an empty history file, only one that still
184+
# has its header line. How many items remain is not checked:
185+
# libedit's own history_truncate_file() ignores a length of 0.
186+
readline.read_history_file(TESTFN)
187+
188+
@unittest.skipUnless(hasattr(readline, "append_history_file"),
189+
"append_history not available")
190+
def test_append_limited_history(self):
191+
previous_length = readline.get_history_length()
192+
self.addCleanup(readline.set_history_length, previous_length)
193+
194+
readline.clear_history()
195+
readline.add_history("first line")
196+
readline.add_history("second line")
197+
readline.write_history_file(TESTFN)
198+
self.addCleanup(os.remove, TESTFN)
199+
200+
readline.add_history("third line")
201+
readline.set_history_length(2)
202+
readline.append_history_file(1, TESTFN)
203+
204+
readline.clear_history()
205+
readline.read_history_file(TESTFN)
206+
self.assertEqual(readline.get_history_item(1), "second line")
207+
self.assertEqual(readline.get_history_item(2), "third line")
208+
self.assertEqual(readline.get_history_item(3), None)
209+
172210

173211
class TestReadline(unittest.TestCase):
174212

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
iOS builds may now be configured without a framework, producing a static
2+
``libpython`` for embedding in an app binary. Such a build cannot load extension
3+
modules at runtime, and requires ``MODULE_BUILDTYPE=static`` and
4+
``--disable-test-modules`` to be requested explicitly. A shared iOS build must
5+
still be a framework build.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:func:`os.chroot`, :func:`os.initgroups`, :func:`os.setegid`,
2+
:func:`os.seteuid`, :func:`os.setgid`, :func:`os.setregid`,
3+
:func:`os.setresgid`, :func:`os.setresuid`, :func:`os.setreuid`,
4+
:func:`os.setuid`, and :func:`socket.sethostname` are now available on
5+
Android. Calling them without sufficient privileges now raises
6+
:exc:`PermissionError` instead of the functions being unavailable.

0 commit comments

Comments
 (0)