1+ diff --git a/Doc/using/ios.rst b/Doc/using/ios.rst
2+ index dff694941d0..685d8e81add 100644
3+ --- a/Doc/using/ios.rst
4+ +++ b/Doc/using/ios.rst
5+ @@ -296,9 +296,9 @@
6+ * Buffered stdio (:c:member:`PyConfig.buffered_stdio`) is *disabled*;
7+ * Writing bytecode (:c:member:`PyConfig.write_bytecode`) is *disabled*;
8+ * Signal handlers (:c:member:`PyConfig.install_signal_handlers`) are *enabled*;
9+ - * ``PYTHONHOME`` for the interpreter is configured to point at the
10+ + * :envvar:`PYTHONHOME` for the interpreter is configured to point at the
11+ ``python`` subfolder of your app's bundle; and
12+ - * The ``PYTHONPATH`` for the interpreter includes:
13+ + * The :envvar:`PYTHONPATH` for the interpreter includes:
14+
15+ - the ``python/lib/python3.X`` subfolder of your app's bundle,
16+ - the ``python/lib/python3.X/lib-dynload`` subfolder of your app's bundle, and
17+ @@ -322,7 +322,12 @@
18+ the ``lib-dynload`` folder can be copied and adapted for this purpose.
19+
20+ * If you're using a separate folder for third-party packages, ensure that folder
21+ - is included as part of the ``PYTHONPATH`` configuration in step 10.
22+ + is included as part of the :envvar:`PYTHONPATH` configuration in step 10.
23+ +
24+ + * If any of the folders that contain third-party packages will contain ``.pth``
25+ + files, you should add that folder as a *site directory* (using
26+ + :meth:`site.addsitedir`), rather than adding to :envvar:`PYTHONPATH` or
27+ + :attr:`sys.path` directly.
28+
29+ Testing a Python package
30+ ------------------------
131diff --git a/Lib/platform.py b/Lib/platform.py
232index 8895177e326..eab586011ed 100755
333--- a/Lib/platform.py
@@ -163,7 +193,7 @@ index f5cd73bdea8..50f2f8988b7 100644
163193 # elif !defined(TARGET_OS_OSX) || TARGET_OS_OSX
164194 PLATFORM_TRIPLET=darwin
165195diff --git a/configure b/configure
166- index 1cd1f690f7b..34922ae651e 100755
196+ index 519caa8ca74..5ae6de9bb44 100755
167197--- a/configure
168198+++ b/configure
169199@@ -979,6 +979,8 @@
@@ -563,7 +593,7 @@ index 1cd1f690f7b..34922ae651e 100755
563593 fi
564594 ac_fn_c_check_func "$LINENO" "fpathconf" "ac_cv_func_fpathconf"
565595 if test "x$ac_cv_func_fpathconf" = xyes
566- @@ -18486 ,24 +18617 ,6 @@
596+ @@ -18492 ,24 +18623 ,6 @@
567597 then :
568598 printf "%s\n" "#define HAVE_POSIX_OPENPT 1" >>confdefs.h
569599
@@ -588,7 +618,7 @@ index 1cd1f690f7b..34922ae651e 100755
588618 fi
589619 ac_fn_c_check_func "$LINENO" "pread" "ac_cv_func_pread"
590620 if test "x$ac_cv_func_pread" = xyes
591- @@ -18792 ,12 +18905 ,6 @@
621+ @@ -18798 ,12 +18911 ,6 @@
592622 then :
593623 printf "%s\n" "#define HAVE_SIGACTION 1" >>confdefs.h
594624
@@ -601,7 +631,7 @@ index 1cd1f690f7b..34922ae651e 100755
601631 fi
602632 ac_fn_c_check_func "$LINENO" "sigfillset" "ac_cv_func_sigfillset"
603633 if test "x$ac_cv_func_sigfillset" = xyes
604- @@ -19066 ,11 +19173 ,11 @@
634+ @@ -19072 ,11 +19179 ,11 @@
605635
606636 fi
607637
@@ -615,7 +645,7 @@ index 1cd1f690f7b..34922ae651e 100755
615645 ac_fn_c_check_func "$LINENO" "getentropy" "ac_cv_func_getentropy"
616646 if test "x$ac_cv_func_getentropy" = xyes
617647 then :
618- @@ -19092 ,6 +19199 ,53 @@
648+ @@ -19098 ,6 +19205 ,53 @@
619649
620650 fi
621651
@@ -669,7 +699,7 @@ index 1cd1f690f7b..34922ae651e 100755
669699 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC options needed to detect all undeclared functions" >&5
670700 printf %s "checking for $CC options needed to detect all undeclared functions... " >&6; }
671701 if test ${ac_cv_c_undeclared_builtin_options+y}
672- @@ -21888 ,7 +22042 ,8 @@
702+ @@ -21920 ,7 +22074 ,8 @@
673703
674704
675705 # check for openpty, login_tty, and forkpty
@@ -679,7 +709,7 @@ index 1cd1f690f7b..34922ae651e 100755
679709
680710 for ac_func in openpty
681711 do :
682- @@ -21984 ,7 +22139 ,7 @@
712+ @@ -22016 ,7 +22171 ,7 @@
683713 fi
684714
685715 done
@@ -688,15 +718,15 @@ index 1cd1f690f7b..34922ae651e 100755
688718 printf %s "checking for library containing login_tty... " >&6; }
689719 if test ${ac_cv_search_login_tty+y}
690720 then :
691- @@ -22141 ,6 +22296 ,7 @@
721+ @@ -22173 ,6 +22328 ,7 @@
692722 fi
693723
694724 done
695725+ fi
696726
697727 # check for long file support functions
698728 ac_fn_c_check_func "$LINENO" "fseek64" "ac_cv_func_fseek64"
699- @@ -22387 ,10 +22543 ,10 @@
729+ @@ -22419 ,10 +22575 ,10 @@
700730
701731 done
702732
@@ -709,7 +739,7 @@ index 1cd1f690f7b..34922ae651e 100755
709739 then
710740
711741 for ac_func in clock_settime
712- @@ -24622 ,8 +24778 ,8 @@
742+ @@ -24654 ,8 +24810 ,8 @@
713743 LIBPYTHON="\$(BLDLIBRARY)"
714744 fi
715745
@@ -720,7 +750,7 @@ index 1cd1f690f7b..34922ae651e 100755
720750 MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(PYTHONFRAMEWORKDIR)/\$(PYTHONFRAMEWORK)"
721751 fi
722752
723- @@ -27271 ,7 +27427 ,7 @@
753+ @@ -27303 ,7 +27459 ,7 @@
724754 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for device files" >&5
725755 printf "%s\n" "$as_me: checking for device files" >&6;}
726756
@@ -729,7 +759,7 @@ index 1cd1f690f7b..34922ae651e 100755
729759 ac_cv_file__dev_ptmx=no
730760 ac_cv_file__dev_ptc=no
731761 else
732- @@ -27704 ,7 +27860 ,7 @@
762+ @@ -27736 ,7 +27892 ,7 @@
733763 with_ensurepip=no ;; #(
734764 WASI) :
735765 with_ensurepip=no ;; #(
@@ -738,7 +768,7 @@ index 1cd1f690f7b..34922ae651e 100755
738768 with_ensurepip=no ;; #(
739769 *) :
740770 with_ensurepip=upgrade
741- @@ -28723 ,7 +28879 ,7 @@
771+ @@ -28755 ,7 +28911 ,7 @@
742772 ;; #(
743773 Darwin) :
744774 ;; #(
@@ -747,7 +777,7 @@ index 1cd1f690f7b..34922ae651e 100755
747777
748778
749779
750- @@ -32488 ,6 +32644 ,8 @@
780+ @@ -32520 ,6 +32676 ,8 @@
751781 "Mac/Resources/framework/Info.plist") CONFIG_FILES="$CONFIG_FILES Mac/Resources/framework/Info.plist" ;;
752782 "Mac/Resources/app/Info.plist") CONFIG_FILES="$CONFIG_FILES Mac/Resources/app/Info.plist" ;;
753783 "iOS/Resources/Info.plist") CONFIG_FILES="$CONFIG_FILES iOS/Resources/Info.plist" ;;
@@ -757,7 +787,7 @@ index 1cd1f690f7b..34922ae651e 100755
757787 "Misc/python.pc") CONFIG_FILES="$CONFIG_FILES Misc/python.pc" ;;
758788 "Misc/python-embed.pc") CONFIG_FILES="$CONFIG_FILES Misc/python-embed.pc" ;;
759789diff --git a/configure.ac b/configure.ac
760- index 3fcb18922c5..3a4167c96ee 100644
790+ index 2a037569e49..39f84269378 100644
761791--- a/configure.ac
762792+++ b/configure.ac
763793@@ -330,6 +330,12 @@
@@ -1117,7 +1147,7 @@ index 3fcb18922c5..3a4167c96ee 100644
11171147- fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
11181148+ fpathconf fstatat ftime ftruncate futimens futimes futimesat \
11191149 gai_strerror getegid geteuid getgid getgrent getgrgid getgrgid_r \
1120- getgrnam_r getgrouplist gethostname getitimer getloadavg getlogin \
1150+ getgrnam_r getgrouplist gethostname getitimer getloadavg getlogin getlogin_r \
11211151 getpeername getpgid getpid getppid getpriority _getpty \
11221152@@ -5122,15 +5253,14 @@
11231153 getspnam getuid getwd grantpt if_nameindex initgroups kill killpg lchown linkat \
@@ -1161,8 +1191,8 @@ index 3fcb18922c5..3a4167c96ee 100644
11611191 fi
11621192
11631193 AC_CHECK_DECL([dirfd],
1164- @@ -5401 ,20 +5539 ,22 @@
1165- ])
1194+ @@ -5413 ,20 +5551 ,22 @@
1195+ [@%:@include <utmp.h> ])
11661196
11671197 # check for openpty, login_tty, and forkpty
11681198-
@@ -1198,7 +1228,7 @@ index 3fcb18922c5..3a4167c96ee 100644
11981228
11991229 # check for long file support functions
12001230 AC_CHECK_FUNCS([fseek64 fseeko fstatvfs ftell64 ftello statvfs])
1201- @@ -5453 ,10 +5593 ,10 @@
1231+ @@ -5465 ,10 +5605 ,10 @@
12021232 ])
12031233 ])
12041234
@@ -1211,7 +1241,7 @@ index 3fcb18922c5..3a4167c96ee 100644
12111241 then
12121242 AC_CHECK_FUNCS([clock_settime], [], [
12131243 AC_CHECK_LIB([rt], [clock_settime], [
1214- @@ -6205 ,8 +6345 ,8 @@
1244+ @@ -6217 ,8 +6357 ,8 @@
12151245 LIBPYTHON="\$(BLDLIBRARY)"
12161246 fi
12171247
@@ -1222,7 +1252,7 @@ index 3fcb18922c5..3a4167c96ee 100644
12221252 MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(PYTHONFRAMEWORKDIR)/\$(PYTHONFRAMEWORK)"
12231253 fi
12241254
1225- @@ -6814 ,7 +6954 ,7 @@
1255+ @@ -6826 ,7 +6966 ,7 @@
12261256 dnl NOTE: Inform user how to proceed with files when cross compiling.
12271257 dnl Some cross-compile builds are predictable; they won't ever
12281258 dnl have /dev/ptmx or /dev/ptc, so we can set them explicitly.
@@ -1231,7 +1261,7 @@ index 3fcb18922c5..3a4167c96ee 100644
12311261 ac_cv_file__dev_ptmx=no
12321262 ac_cv_file__dev_ptc=no
12331263 else
1234- @@ -7071 ,7 +7211 ,7 @@
1264+ @@ -7083 ,7 +7223 ,7 @@
12351265 AS_CASE([$ac_sys_system],
12361266 [Emscripten], [with_ensurepip=no],
12371267 [WASI], [with_ensurepip=no],
@@ -1240,7 +1270,7 @@ index 3fcb18922c5..3a4167c96ee 100644
12401270 [with_ensurepip=upgrade]
12411271 )
12421272 ])
1243- @@ -7479 ,7 +7619 ,7 @@
1273+ @@ -7491 ,7 +7631 ,7 @@
12441274 [VxWorks*], [PY_STDLIB_MOD_SET_NA([_scproxy], [termios], [grp])],
12451275 dnl The _scproxy module is available on macOS
12461276 [Darwin], [],
@@ -1269,19 +1299,103 @@ index c3e261ecd9e..26ef7a95de4 100644
12691299 <key>CFBundleSupportedPlatforms</key>
12701300 <array>
12711301 <string>iPhoneOS</string>
1272- diff --git a/iOS/testbed/__main__.py b/iOS/testbed/__main__.py
1273- index c05497ede3a..1146bf3b988 100644
1274- --- a/iOS/testbed/__main__.py
1275- +++ b/iOS/testbed/__main__.py
1276- @@ -127,7 +127,7 @@
1277- async def select_simulator_device():
1278- # List the testing simulators, in JSON format
1279- raw_json = await async_check_output(
1280- - "xcrun", "simctl", "--set", "testing", "list", "-j"
1281- + "xcrun", "simctl", "list", "-j"
1282- )
1283- json_data = json.loads(raw_json)
1302+ --- /dev/null
1303+ +++ b/iOS/Resources/bin/arm64-apple-ios-simulator-strip
1304+ @@ -0,0 +1,2 @@
1305+ + #!/bin/sh
1306+ + xcrun --sdk iphonesimulator${IOS_SDK_VERSION} strip -arch arm64 "$@"
1307+ --- /dev/null
1308+ +++ b/iOS/Resources/bin/arm64-apple-ios-strip
1309+ @@ -0,0 +1,2 @@
1310+ + #!/bin/sh
1311+ + xcrun --sdk iphoneos${IOS_SDK_VERSION} strip -arch arm64 "$@"
1312+ --- /dev/null
1313+ +++ b/iOS/Resources/bin/x86_64-apple-ios-simulator-strip
1314+ @@ -0,0 +1,2 @@
1315+ + #!/bin/sh
1316+ + xcrun --sdk iphonesimulator${IOS_SDK_VERSION} strip -arch x86_64 "$@"
1317+ diff --git a/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m b/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m
1318+ index d417b4cd63e..294a06f5305 100644
1319+ --- a/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m
1320+ +++ b/iOS/testbed/iOSTestbedTests/iOSTestbedTests.m
1321+ @@ -15,6 +15,11 @@
1322+ PyStatus status;
1323+ PyPreConfig preconfig;
1324+ PyConfig config;
1325+ + PyObject *app_packages_path;
1326+ + PyObject *method_args;
1327+ + PyObject *result;
1328+ + PyObject *site_module;
1329+ + PyObject *site_addsitedir_attr;
1330+ PyObject *sys_module;
1331+ PyObject *sys_path_attr;
1332+ NSArray *test_args;
1333+ @@ -109,29 +114,55 @@
1334+ return;
1335+ }
1336+
1337+ - sys_module = PyImport_ImportModule("sys");
1338+ - if (sys_module == NULL) {
1339+ - XCTFail(@"Could not import sys module");
1340+ + // Add app_packages as a site directory. This both adds to sys.path,
1341+ + // and ensures that any .pth files in that directory will be executed.
1342+ + site_module = PyImport_ImportModule("site");
1343+ + if (site_module == NULL) {
1344+ + XCTFail(@"Could not import site module");
1345+ return;
1346+ }
1347+
1348+ - sys_path_attr = PyObject_GetAttrString(sys_module, "path");
1349+ - if (sys_path_attr == NULL) {
1350+ - XCTFail(@"Could not access sys.path");
1351+ + site_addsitedir_attr = PyObject_GetAttrString(site_module, "addsitedir");
1352+ + if (site_addsitedir_attr == NULL || !PyCallable_Check(site_addsitedir_attr)) {
1353+ + XCTFail(@"Could not access site.addsitedir");
1354+ return;
1355+ }
1356+
1357+ - // Add the app packages path
1358+ path = [NSString stringWithFormat:@"%@/app_packages", resourcePath, nil];
1359+ NSLog(@"App packages path: %@", path);
1360+ wtmp_str = Py_DecodeLocale([path UTF8String], NULL);
1361+ - failed = PyList_Insert(sys_path_attr, 0, PyUnicode_FromString([path UTF8String]));
1362+ - if (failed) {
1363+ - XCTFail(@"Unable to add app packages to sys.path");
1364+ + app_packages_path = PyUnicode_FromWideChar(wtmp_str, wcslen(wtmp_str));
1365+ + if (app_packages_path == NULL) {
1366+ + XCTFail(@"Could not convert app_packages path to unicode");
1367+ return;
1368+ }
1369+ PyMem_RawFree(wtmp_str);
12841370
1371+ + method_args = Py_BuildValue("(O)", app_packages_path);
1372+ + if (method_args == NULL) {
1373+ + XCTFail(@"Could not create arguments for site.addsitedir");
1374+ + return;
1375+ + }
1376+ +
1377+ + result = PyObject_CallObject(site_addsitedir_attr, method_args);
1378+ + if (result == NULL) {
1379+ + XCTFail(@"Could not add app_packages directory using site.addsitedir");
1380+ + return;
1381+ + }
1382+ +
1383+ + // Add test code to sys.path
1384+ + sys_module = PyImport_ImportModule("sys");
1385+ + if (sys_module == NULL) {
1386+ + XCTFail(@"Could not import sys module");
1387+ + return;
1388+ + }
1389+ +
1390+ + sys_path_attr = PyObject_GetAttrString(sys_module, "path");
1391+ + if (sys_path_attr == NULL) {
1392+ + XCTFail(@"Could not access sys.path");
1393+ + return;
1394+ + }
1395+ +
1396+ path = [NSString stringWithFormat:@"%@/app", resourcePath, nil];
1397+ NSLog(@"App path: %@", path);
1398+ wtmp_str = Py_DecodeLocale([path UTF8String], NULL);
12851399--- /dev/null
12861400+++ b/tvOS/README.rst
12871401@@ -0,0 +1,108 @@
0 commit comments