forked from flet-dev/python-ios-pre-3.13
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython.patch
More file actions
5730 lines (5488 loc) · 205 KB
/
Python.patch
File metadata and controls
5730 lines (5488 loc) · 205 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/Include/internal/pycore_faulthandler.h b/Include/internal/pycore_faulthandler.h
index 6dd7d8d7ca..836c8a3fcf 100644
--- a/Include/internal/pycore_faulthandler.h
+++ b/Include/internal/pycore_faulthandler.h
@@ -12,6 +12,14 @@
# include <signal.h> // sigaction
#endif
+#ifdef __APPLE__
+# include "TargetConditionals.h"
+#endif /* __APPLE__ */
+
+// tvOS and watchOS don't provide a number of important POSIX functions.
+#if TARGET_OS_TV || TARGET_OS_WATCH
+# undef HAVE_SIGALTSTACK
+#endif /* TVOS || WATCHOS */
#ifndef MS_WINDOWS
/* register() is useless on Windows, because only SIGSEGV, SIGABRT and
--- /dev/null
+++ b/Lib/_ios_support.py
@@ -0,0 +1,46 @@
+try:
+ from ctypes import cdll, c_void_p, c_char_p
+ from ctypes import util
+except ImportError:
+ # ctypes is an optional module. If it's not present, we're limited in what
+ # we can tell about the system, but we don't want to prevent the platform
+ # module from working.
+ cdll = None
+
+
+def get_platform_ios():
+ if cdll:
+ objc = cdll.LoadLibrary(util.find_library(b'objc'))
+
+ objc.objc_getClass.restype = c_void_p
+ objc.objc_getClass.argtypes = [c_char_p]
+ objc.objc_msgSend.restype = c_void_p
+ objc.objc_msgSend.argtypes = [c_void_p, c_void_p]
+ objc.sel_registerName.restype = c_void_p
+ objc.sel_registerName.argtypes = [c_char_p]
+
+ UIDevice = c_void_p(objc.objc_getClass(b'UIDevice'))
+ SEL_currentDevice = c_void_p(objc.sel_registerName(b'currentDevice'))
+ device = c_void_p(objc.objc_msgSend(UIDevice, SEL_currentDevice))
+
+ SEL_systemVersion = c_void_p(objc.sel_registerName(b'systemVersion'))
+ systemVersion = c_void_p(objc.objc_msgSend(device, SEL_systemVersion))
+
+ SEL_systemName = c_void_p(objc.sel_registerName(b'systemName'))
+ systemName = c_void_p(objc.objc_msgSend(device, SEL_systemName))
+
+ SEL_model = c_void_p(objc.sel_registerName(b'model'))
+ systemModel = c_void_p(objc.objc_msgSend(device, SEL_model))
+
+ # UTF8String returns a const char*;
+ SEL_UTF8String = c_void_p(objc.sel_registerName(b'UTF8String'))
+ objc.objc_msgSend.restype = c_char_p
+
+ system = objc.objc_msgSend(systemName, SEL_UTF8String).decode()
+ release = objc.objc_msgSend(systemVersion, SEL_UTF8String).decode()
+ model = objc.objc_msgSend(systemModel, SEL_UTF8String).decode()
+
+ return system, release, model
+ else:
+ # Return dummy values if we can't call system APIs.
+ return "iOS", "?", "iPhone"
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e161..5567080ba5 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -67,7 +67,7 @@
return fname
return None
-elif os.name == "posix" and sys.platform == "darwin":
+elif os.name == "posix" and sys.platform in {'darwin', 'ios', 'tvos', 'watchos'}:
from ctypes.macholib.dyld import dyld_find as _dyld_find
def find_library(name):
possible = ['lib%s.dylib' % name,
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 0019897c94..c11ead2b11 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -52,7 +52,7 @@
# Bootstrap-related code ######################################################
_CASE_INSENSITIVE_PLATFORMS_STR_KEY = 'win',
-_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY = 'cygwin', 'darwin'
+_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY = 'cygwin', 'darwin', 'ios', 'tvos', 'watchos'
_CASE_INSENSITIVE_PLATFORMS = (_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY
+ _CASE_INSENSITIVE_PLATFORMS_STR_KEY)
@@ -1704,6 +1704,65 @@
return f'FileFinder({self.path!r})'
+class AppleFrameworkLoader(ExtensionFileLoader):
+ """A loader for modules that have been packaged as Apple Frameworks for
+ compatibility with Apple's App Store policies.
+
+ For compatibility with the App Store, *all* binary modules must be .dylib
+ objects, contained in a Framework, stored in the ``Frameworks`` folder of
+ the packaged app. If you're trying to run "from foo import _bar", and _bar
+ is implemented with the binary module "foo/_bar.abi3.dylib" (or any other
+ .dylib extension), this loader will look for
+ "{sys.executable}/Frameworks/foo._bar.framework/_bar.abi3.dylib" (forming
+ the package name by taking the full path of the library, and replacing ``/``
+ with ``.``). The app packaging tool is responsible for putting the library
+ in this location.
+
+ However, the ``__file__`` attribute of the _bar module will report as the
+ original location inside the ``foo`` directory. This so that code that
+ depends on walking directory trees will continue to work as expected based
+ on the *original* file location.
+ """
+ def __init__(self, fullname, dylib_file, path):
+ super().__init__(fullname, dylib_file)
+ self.parent_paths = path
+
+ def create_module(self, spec):
+ mod = super().create_module(spec)
+ if self.parent_paths:
+ for parent_path in self.parent_paths:
+ if _path_isdir(parent_path):
+ mod.__file__ = _path_join(parent_path, _path_split(self.path)[-1])
+ continue
+ return mod
+
+
+class AppleFrameworkFinder:
+ """A finder for modules that have been packaged as Apple Frameworks
+ for compatibility with Apple's App Store policies.
+
+ See AppleFrameworkLoader for details.
+ """
+ def __init__(self, path):
+ self.frameworks_path = path
+
+ def find_spec(self, fullname, path, target=None):
+ name = fullname.split(".")[-1]
+
+ for extension in EXTENSION_SUFFIXES:
+ dylib_file = _path_join(self.frameworks_path, f"{fullname}.framework", f"{name}{extension}")
+ _bootstrap._verbose_message('Looking for Apple Framework dylib {}', dylib_file)
+ try:
+ dylib_exists = _path_isfile(dylib_file)
+ except ValueError:
+ pass
+ else:
+ if dylib_exists:
+ loader = AppleFrameworkLoader(fullname, dylib_file, path)
+ return _bootstrap.spec_from_loader(fullname, loader)
+
+ return None
+
# Import setup ###############################################################
def _fix_up_module(ns, name, pathname, cpathname=None):
@@ -1753,3 +1812,7 @@
supported_loaders = _get_supported_file_loaders()
sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)])
sys.meta_path.append(PathFinder)
+ if sys.platform in {"ios", "tvos", "watchos"}:
+ frameworks_folder = _path_join(_path_split(sys.executable)[0], "Frameworks")
+ _bootstrap._verbose_message('Adding Apple Framework dylib finder at {}', frameworks_folder)
+ sys.meta_path.append(AppleFrameworkFinder(frameworks_folder))
diff --git a/Lib/importlib/machinery.py b/Lib/importlib/machinery.py
index d9a19a13f7..fbd30b159f 100644
--- a/Lib/importlib/machinery.py
+++ b/Lib/importlib/machinery.py
@@ -12,6 +12,7 @@
from ._bootstrap_external import SourceFileLoader
from ._bootstrap_external import SourcelessFileLoader
from ._bootstrap_external import ExtensionFileLoader
+from ._bootstrap_external import AppleFrameworkLoader
from ._bootstrap_external import NamespaceLoader
diff --git a/Lib/platform.py b/Lib/platform.py
index 7bb222088d..b4db9749da 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -496,6 +496,26 @@
# If that also doesn't work return the default values
return release, versioninfo, machine
+def ios_ver():
+ """Get iOS/tvOS version information, and return it as a
+ tuple (system, release, model). All tuple entries are strings.
+ """
+ import _ios_support
+ return _ios_support.get_platform_ios()
+
+def is_simulator():
+ """Determine if the current platform is a device simulator.
+
+ Only useful when working with iOS, tvOS or watchOS, because
+ Apple provides simulator platforms for those devices.
+
+ If the platform is actual hardware, returns False. Will also
+ return False for device *emulators*, which are indistinguishable
+ from actual devices because they are reproducing actual device
+ properties.
+ """
+ return getattr(sys.implementation, "_simulator", False)
+
def _java_getprop(name, default):
from java.lang import System
@@ -652,7 +672,7 @@
default in case the command should fail.
"""
- if sys.platform in ('dos', 'win32', 'win16'):
+ if sys.platform in {'dos', 'win32', 'win16', 'ios', 'tvos', 'watchos'}:
# XXX Others too ?
return default
@@ -814,6 +834,24 @@
csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
return 'Alpha' if cpu_number >= 128 else 'VAX'
+ # On iOS, tvOS and watchOS, os.uname returns the architecture
+ # as uname.machine. On device it doesn't; but there's only
+ # on CPU architecture on device
+ def get_ios():
+ if getattr(sys.implementation, "_simulator", False):
+ return os.uname().machine
+ return 'arm64'
+
+ def get_tvos():
+ if getattr(sys.implementation, "_simulator", False):
+ return os.uname().machine
+ return 'arm64'
+
+ def get_watchos():
+ if getattr(sys.implementation, "_simulator", False):
+ return os.uname().machine
+ return 'arm64_32'
+
def from_subprocess():
"""
Fall back to `uname -p`
@@ -968,6 +1006,15 @@
system = 'Windows'
release = 'Vista'
+ # Normalize responses on Apple mobile platforms
+ if sys.platform in {'ios', 'tvos'}:
+ system, release, model = ios_ver()
+
+ # On iOS/tvOS simulators, os.uname() reports the machine as something
+ # like "arm64" or "x86_64".
+ if getattr(sys.implementation, "_simulator", False):
+ machine = f'{model}Simulator'
+
vals = system, node, release, version, machine
# Replace 'unknown' values with the more portable ''
_uname_cache = uname_result(*map(_unknown_as_blank, vals))
@@ -1247,11 +1294,13 @@
system, release, version = system_alias(system, release, version)
if system == 'Darwin':
- # macOS (darwin kernel)
- macos_release = mac_ver()[0]
- if macos_release:
- system = 'macOS'
- release = macos_release
+ if sys.platform in {'ios', 'tvos'}:
+ system, release, _ = ios_ver()
+ else:
+ macos_release = mac_ver()[0]
+ if macos_release:
+ system = 'macOS'
+ release = macos_release
if system == 'Windows':
# MS platforms
diff --git a/Lib/site.py b/Lib/site.py
index 672fa7b000..9fd399e990 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -294,6 +294,9 @@
if sys.platform == 'darwin' and sys._framework:
return f'{userbase}/lib/python/site-packages'
+ elif sys.platform in ('ios', 'tvos', 'watchos'):
+ from sysconfig import get_path
+ return get_path('purelib', sys.platform)
return f'{userbase}/lib/python{version[0]}.{version[1]}/site-packages'
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 6df5dd551e..597da09643 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -74,8 +74,8 @@
else:
_mswindows = True
-# wasm32-emscripten and wasm32-wasi do not support processes
-_can_fork_exec = sys.platform not in {"emscripten", "wasi"}
+# some platforms do not support processes
+_can_fork_exec = sys.platform not in {"emscripten", "wasi", "ios", "tvos", "watchos"}
if _mswindows:
import _winapi
@@ -103,18 +103,22 @@
if _can_fork_exec:
from _posixsubprocess import fork_exec as _fork_exec
# used in methods that are called by __del__
- _waitpid = os.waitpid
- _waitstatus_to_exitcode = os.waitstatus_to_exitcode
- _WIFSTOPPED = os.WIFSTOPPED
- _WSTOPSIG = os.WSTOPSIG
- _WNOHANG = os.WNOHANG
+ class _del_safe:
+ waitpid = os.waitpid
+ waitstatus_to_exitcode = os.waitstatus_to_exitcode
+ WIFSTOPPED = os.WIFSTOPPED
+ WSTOPSIG = os.WSTOPSIG
+ WNOHANG = os.WNOHANG
+ ECHILD = errno.ECHILD
else:
- _fork_exec = None
- _waitpid = None
- _waitstatus_to_exitcode = None
- _WIFSTOPPED = None
- _WSTOPSIG = None
- _WNOHANG = None
+ class _del_safe:
+ waitpid = None
+ waitstatus_to_exitcode = None
+ WIFSTOPPED = None
+ WSTOPSIG = None
+ WNOHANG = None
+ ECHILD = errno.ECHILD
+
import select
import selectors
@@ -1951,20 +1955,16 @@
raise child_exception_type(err_msg)
- def _handle_exitstatus(self, sts,
- _waitstatus_to_exitcode=_waitstatus_to_exitcode,
- _WIFSTOPPED=_WIFSTOPPED,
- _WSTOPSIG=_WSTOPSIG):
+ def _handle_exitstatus(self, sts, _del_safe=_del_safe):
"""All callers to this function MUST hold self._waitpid_lock."""
# This method is called (indirectly) by __del__, so it cannot
# refer to anything outside of its local scope.
- if _WIFSTOPPED(sts):
- self.returncode = -_WSTOPSIG(sts)
+ if _del_safe.WIFSTOPPED(sts):
+ self.returncode = -_del_safe.WSTOPSIG(sts)
else:
- self.returncode = _waitstatus_to_exitcode(sts)
+ self.returncode = _del_safe.waitstatus_to_exitcode(sts)
- def _internal_poll(self, _deadstate=None, _waitpid=_waitpid,
- _WNOHANG=_WNOHANG, _ECHILD=errno.ECHILD):
+ def _internal_poll(self, _deadstate=None, _del_safe=_del_safe):
"""Check if child process has terminated. Returns returncode
attribute.
@@ -1980,13 +1980,13 @@
try:
if self.returncode is not None:
return self.returncode # Another thread waited.
- pid, sts = _waitpid(self.pid, _WNOHANG)
+ pid, sts = _del_safe.waitpid(self.pid, _del_safe.WNOHANG)
if pid == self.pid:
self._handle_exitstatus(sts)
except OSError as e:
if _deadstate is not None:
self.returncode = _deadstate
- elif e.errno == _ECHILD:
+ elif e.errno == _del_safe.ECHILD:
# This happens if SIGCLD is set to be ignored or
# waiting for child processes has otherwise been
# disabled for our process. This child is dead, we
diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py
index 68d30c0f9e..4a8a27b6d0 100644
--- a/Lib/sysconfig/__init__.py
+++ b/Lib/sysconfig/__init__.py
@@ -96,6 +96,33 @@
'scripts': '{base}/Scripts',
'data': '{base}',
},
+ 'ios': {
+ 'stdlib': '{installed_base}/lib/python{py_version_short}',
+ 'platstdlib': '{installed_base}/lib/python{py_version_short}',
+ 'purelib': '{installed_base}/lib/python{py_version_short}/site-packages',
+ 'platlib': '{installed_base}/lib/python{py_version_short}/site-packages',
+ 'include': '{installed_base}/include',
+ 'scripts': '{installed_base}/bin',
+ 'data': '{installed_base}/Resources',
+ },
+ 'tvos': {
+ 'stdlib': '{installed_base}/lib/python{py_version_short}',
+ 'platstdlib': '{installed_base}/lib/python{py_version_short}',
+ 'purelib': '{installed_base}/lib/python{py_version_short}/site-packages',
+ 'platlib': '{installed_base}/lib/python{py_version_short}/site-packages',
+ 'include': '{installed_base}/include',
+ 'scripts': '{installed_base}/bin',
+ 'data': '{installed_base}/Resources',
+ },
+ 'watchos': {
+ 'stdlib': '{installed_base}/lib/python{py_version_short}',
+ 'platstdlib': '{installed_base}/lib/python{py_version_short}',
+ 'purelib': '{installed_base}/lib/python{py_version_short}/site-packages',
+ 'platlib': '{installed_base}/lib/python{py_version_short}/site-packages',
+ 'include': '{installed_base}/include',
+ 'scripts': '{installed_base}/bin',
+ 'data': '{installed_base}/Resources',
+ },
}
# For the OS-native venv scheme, we essentially provide an alias:
@@ -282,12 +309,19 @@
'home': 'posix_home',
'user': 'nt_user',
}
+ if sys.platform in ('ios', 'tvos', 'watchos'):
+ return {
+ 'prefix': sys.platform,
+ 'home': sys.platform,
+ 'user': sys.platform,
+ }
if sys.platform == 'darwin' and sys._framework:
return {
'prefix': 'posix_prefix',
'home': 'posix_home',
'user': 'osx_framework_user',
}
+
return {
'prefix': 'posix_prefix',
'home': 'posix_home',
@@ -619,10 +653,16 @@
if m:
release = m.group()
elif osname[:6] == "darwin":
- import _osx_support
- osname, release, machine = _osx_support.get_platform_osx(
- get_config_vars(),
- osname, release, machine)
+ if sys.platform in ("ios", "tvos", "watchos"):
+ import _ios_support
+ _, release, _ = _ios_support.get_platform_ios()
+ osname = sys.platform
+ machine = sys.implementation._multiarch
+ else:
+ import _osx_support
+ osname, release, machine = _osx_support.get_platform_osx(
+ get_config_vars(),
+ osname, release, machine)
return f"{osname}-{release}-{machine}"
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 21e8770ab3..67958d247c 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -46,7 +46,7 @@
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
"requires_limited_api", "requires_specialization",
# sys
- "MS_WINDOWS", "is_jython", "is_android", "is_emscripten", "is_wasi",
+ "MS_WINDOWS", "is_jython", "is_android", "is_emscripten", "is_wasi", "is_apple_mobile",
"check_impl_detail", "unix_shell", "setswitchinterval",
# os
"get_pagesize",
@@ -520,7 +520,7 @@
is_android = hasattr(sys, 'getandroidapilevel')
-if sys.platform not in ('win32', 'vxworks'):
+if sys.platform not in ('win32', 'vxworks', 'ios', 'tvos', 'watchos'):
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
else:
unix_shell = None
@@ -530,12 +530,25 @@
is_emscripten = sys.platform == "emscripten"
is_wasi = sys.platform == "wasi"
-has_fork_support = hasattr(os, "fork") and not is_emscripten and not is_wasi
+# Apple mobile platforms (iOS/tvOS/watchOS) are POSIX-like but do not
+# have subprocess or fork support.
+is_apple_mobile = sys.platform in ('ios', 'tvos', 'watchos')
+
+has_fork_support = (
+ hasattr(os, "fork")
+ and not is_emscripten
+ and not is_wasi
+ and not is_apple_mobile
+)
def requires_fork():
return unittest.skipUnless(has_fork_support, "requires working os.fork()")
-has_subprocess_support = not is_emscripten and not is_wasi
+has_subprocess_support = (
+ not is_emscripten
+ and not is_wasi
+ and not is_apple_mobile
+)
def requires_subprocess():
"""Used for subprocess, os.spawn calls, fd inheritance"""
diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py
index 821a4b1ffd..517f7b57f4 100644
--- a/Lib/test/support/os_helper.py
+++ b/Lib/test/support/os_helper.py
@@ -20,7 +20,7 @@
# TESTFN_UNICODE is a non-ascii filename
TESTFN_UNICODE = TESTFN_ASCII + "-\xe0\xf2\u0258\u0141\u011f"
-if sys.platform == 'darwin':
+if sys.platform in ('darwin', 'ios', 'tvos', 'watchos'):
# In Mac OS X's VFS API file names are, by definition, canonically
# decomposed Unicode, encoded using UTF-8. See QA1173:
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
@@ -46,8 +46,8 @@
'encoding (%s). Unicode filename tests may not be effective'
% (TESTFN_UNENCODABLE, sys.getfilesystemencoding()))
TESTFN_UNENCODABLE = None
-# macOS and Emscripten deny unencodable filenames (invalid utf-8)
-elif sys.platform not in {'darwin', 'emscripten', 'wasi'}:
+# Apple and Emscripten deny unencodable filenames (invalid utf-8)
+elif sys.platform not in {'darwin', 'ios', 'tvos', 'watchos', 'emscripten', 'wasi'}:
try:
# ascii and utf-8 cannot encode the byte 0xff
b'\xff'.decode(sys.getfilesystemencoding())
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index b25c097573..7491782c7f 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -33,6 +33,7 @@
from multiprocessing.util import _cleanup_tests as multiprocessing_cleanup_tests
from test.test_asyncio import utils as test_utils
from test import support
+from test.support import is_apple_mobile
from test.support import socket_helper
from test.support import threading_helper
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
@@ -1799,6 +1800,7 @@
next(it)
+@support.requires_subprocess()
class SubprocessTestsMixin:
def check_terminated(self, returncode):
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index 9c92e75886..65ee41dbd1 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -18,6 +18,7 @@
import asyncio
from test.test_asyncio import utils as test_utils
+from test.support import requires_subprocess
def tearDownModule():
@@ -771,6 +772,7 @@
self.assertEqual(msg2, b"hello world 2!\n")
@unittest.skipIf(sys.platform == 'win32', "Don't have pipes")
+ @requires_subprocess()
def test_read_all_from_pipe_reader(self):
# See asyncio issue 168. This test is derived from the example
# subprocess_attach_read_pipe.py, but we configure the
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index 179c8cb8cc..c8659f6ed6 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -11,6 +11,7 @@
from asyncio import subprocess
from test.test_asyncio import utils as test_utils
from test import support
+from test.support import is_apple_mobile
from test.support import os_helper
@@ -47,6 +48,8 @@
self._proc.pid = -1
+@unittest.skipIf(is_apple_mobile,
+ f"{sys.platform} doesn't support subprocesses.")
class SubprocessTransportTests(test_utils.TestCase):
def setUp(self):
super().setUp()
@@ -110,6 +113,8 @@
transport.close()
+@unittest.skipIf(is_apple_mobile,
+ f"{sys.platform} doesn't support subprocesses.")
class SubprocessMixin:
def test_stdin_stdout(self):
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index d2c8cba6ac..c3795dede9 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -1875,6 +1875,7 @@
@unittest.skipUnless(hasattr(os, 'fork'), 'requires os.fork()')
+@support.requires_subprocess()
class TestFork(unittest.IsolatedAsyncioTestCase):
async def test_fork_not_share_event_loop(self):
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index 1b58882601..7ae237e6c1 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -560,7 +560,9 @@
# Python cannot a undecodable bytes argument to a subprocess.
# WASI does not permit invalid UTF-8 names.
if (os_helper.TESTFN_UNDECODABLE
- and sys.platform not in ('win32', 'darwin', 'emscripten', 'wasi')):
+ and sys.platform not in (
+ 'win32', 'darwin', 'ios', 'tvos', 'watchos', 'emscripten', 'wasi'
+ )):
name = os.fsdecode(os_helper.TESTFN_UNDECODABLE)
elif os_helper.TESTFN_NONASCII:
name = os_helper.TESTFN_NONASCII
diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py
index 203dd6fe57..a4e7099da3 100644
--- a/Lib/test/test_fcntl.py
+++ b/Lib/test/test_fcntl.py
@@ -6,7 +6,7 @@
import struct
import sys
import unittest
-from test.support import verbose, cpython_only, get_pagesize
+from test.support import cpython_only, get_pagesize, is_apple_mobile, requires_subprocess, verbose
from test.support.import_helper import import_module
from test.support.os_helper import TESTFN, unlink
@@ -57,7 +57,9 @@
start_len = "qq"
if (sys.platform.startswith(('netbsd', 'freebsd', 'openbsd'))
- or sys.platform == 'darwin'):
+ or sys.platform == 'darwin'
+ or is_apple_mobile
+ ):
if struct.calcsize('l') == 8:
off_t = 'l'
pid_t = 'i'
@@ -157,6 +159,7 @@
self.assertRaises(TypeError, fcntl.flock, 'spam', fcntl.LOCK_SH)
@unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError")
+ @requires_subprocess()
def test_lockf_exclusive(self):
self.f = open(TESTFN, 'wb+')
cmd = fcntl.LOCK_EX | fcntl.LOCK_NB
@@ -169,6 +172,7 @@
self.assertEqual(p.exitcode, 0)
@unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError")
+ @requires_subprocess()
def test_lockf_share(self):
self.f = open(TESTFN, 'wb+')
cmd = fcntl.LOCK_SH | fcntl.LOCK_NB
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index 2f191ea7a4..81115e9db8 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -18,6 +18,7 @@
from unittest import TestCase, skipUnless
from test import support
+from test.support import requires_subprocess
from test.support import threading_helper
from test.support import socket_helper
from test.support import warnings_helper
@@ -900,6 +901,7 @@
@skipUnless(ssl, "SSL not available")
+@requires_subprocess()
class TestTLS_FTPClassMixin(TestFTPClass):
"""Repeat TestFTPClass tests starting the TLS layer for both control
and data connections first.
@@ -916,6 +918,7 @@
@skipUnless(ssl, "SSL not available")
+@requires_subprocess()
class TestTLS_FTPClass(TestCase):
"""Specific TLS_FTP class tests."""
diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py
index 4f311c2d49..c0a6a48dea 100644
--- a/Lib/test/test_genericpath.py
+++ b/Lib/test/test_genericpath.py
@@ -488,7 +488,9 @@
# invalid UTF-8 name. Windows allows creating a directory with an
# arbitrary bytes name, but fails to enter this directory
# (when the bytes name is used).
- and sys.platform not in ('win32', 'darwin', 'emscripten', 'wasi')):
+ and sys.platform not in (
+ 'win32', 'darwin', 'ios', 'tvos', 'watchos', 'emscripten', 'wasi'
+ )):
name = os_helper.TESTFN_UNDECODABLE
elif os_helper.TESTFN_NONASCII:
name = os_helper.TESTFN_NONASCII
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index 9fa6ecf9c0..01dc990b1e 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -30,7 +30,9 @@
import unittest
from test import support
+from test.support import is_apple_mobile
from test.support import os_helper
+from test.support import requires_subprocess
from test.support import threading_helper
support.requires_working_socket(module=True)
@@ -410,8 +412,8 @@
reader.close()
return body
- @unittest.skipIf(sys.platform == 'darwin',
- 'undecodable name cannot always be decoded on macOS')
+ @unittest.skipIf(sys.platform == 'darwin' or is_apple_mobile,
+ 'undecodable name cannot always be decoded on Apple platforms')
@unittest.skipIf(sys.platform == 'win32',
'undecodable name cannot be decoded on win32')
@unittest.skipUnless(os_helper.TESTFN_UNDECODABLE,
@@ -422,9 +424,9 @@
with open(os.path.join(self.tempdir, filename), 'wb') as f:
f.write(os_helper.TESTFN_UNDECODABLE)
response = self.request(self.base_url + '/')
- if sys.platform == 'darwin':
- # On Mac OS the HFS+ filesystem replaces bytes that aren't valid
- # UTF-8 into a percent-encoded value.
+ if sys.platform == 'darwin' or is_apple_mobile:
+ # On Apple platforms the HFS+ filesystem replaces bytes that
+ # aren't valid UTF-8 into a percent-encoded value.
for name in os.listdir(self.tempdir):
if name != 'test': # Ignore a filename created in setUp().
filename = name
@@ -697,6 +699,7 @@
@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
"This test can't be run reliably as root (issue #13308).")
+@requires_subprocess()
class CGIHTTPServerTestCase(BaseTestCase):
class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler):
_test_case_self = None # populated by each setUp() method call.
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index aa465c70df..16337bb12b 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -5,7 +5,7 @@
import importlib.util
from importlib._bootstrap_external import _get_sourcefile
from importlib.machinery import (
- BuiltinImporter, ExtensionFileLoader, FrozenImporter, SourceFileLoader,
+ AppleFrameworkLoader, BuiltinImporter, ExtensionFileLoader, FrozenImporter, SourceFileLoader,
)
import marshal
import os
@@ -25,7 +25,7 @@
from test.support import os_helper
from test.support import (
- STDLIB_DIR, swap_attr, swap_item, cpython_only, is_emscripten,
+ STDLIB_DIR, swap_attr, swap_item, cpython_only, is_apple_mobile, is_emscripten,
is_wasi, run_in_subinterp, run_in_subinterp_with_config, Py_TRACE_REFS)
from test.support.import_helper import (
forget, make_legacy_pyc, unlink, unload, ready_to_import,
@@ -66,6 +66,7 @@
MODULE_KINDS = {
BuiltinImporter: 'built-in',
ExtensionFileLoader: 'extension',
+ AppleFrameworkLoader: 'framework extension',
FrozenImporter: 'frozen',
SourceFileLoader: 'pure Python',
}
@@ -91,7 +92,10 @@
assert module.__spec__.origin == 'built-in', module.__spec__
def require_extension(module, *, skip=False):
- _require_loader(module, ExtensionFileLoader, skip)
+ if is_apple_mobile:
+ _require_loader(module, AppleFrameworkLoader, skip)
+ else:
+ _require_loader(module, ExtensionFileLoader, skip)
def require_frozen(module, *, skip=True):
module = _require_loader(module, FrozenImporter, skip)
@@ -360,7 +364,7 @@
self.assertEqual(cm.exception.path, _testcapi.__file__)
self.assertRegex(
str(cm.exception),
- r"cannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|pyd)\)"
+ r"cannot import name 'i_dont_exist' from '_testcapi' \(.*\.(so|dylib|pyd)\)"
)
else:
self.assertEqual(
@@ -1678,6 +1682,12 @@
os.set_blocking(r, False)
return (r, w)
+ def create_extension_loader(self, modname, filename):
+ if is_apple_mobile:
+ return AppleFrameworkLoader(modname, filename, None)
+ else:
+ return ExtensionFileLoader(modname, filename)
+
def import_script(self, name, fd, filename=None, check_override=None):
override_text = ''
if check_override is not None:
@@ -1872,7 +1882,7 @@
def test_multi_init_extension_non_isolated_compat(self):
modname = '_test_non_isolated'
filename = _testmultiphase.__file__
- loader = ExtensionFileLoader(modname, filename)
+ loader = self.create_extension_loader(modname, filename)
spec = importlib.util.spec_from_loader(modname, loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
@@ -1890,7 +1900,7 @@
def test_multi_init_extension_per_interpreter_gil_compat(self):
modname = '_test_shared_gil_only'
filename = _testmultiphase.__file__
- loader = ExtensionFileLoader(modname, filename)
+ loader = self.create_extension_loader(modname, filename)
spec = importlib.util.spec_from_loader(modname, loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
@@ -2020,10 +2030,13 @@
@classmethod
def setUpClass(cls):
spec = importlib.util.find_spec(cls.NAME)
- from importlib.machinery import ExtensionFileLoader
+ from importlib.machinery import AppleFrameworkLoader, ExtensionFileLoader
cls.FILE = spec.origin
cls.LOADER = type(spec.loader)
- assert cls.LOADER is ExtensionFileLoader
+ if is_apple_mobile:
+ assert cls.LOADER is AppleFrameworkLoader
+ else:
+ assert cls.LOADER is ExtensionFileLoader
# Start fresh.
cls.clean_up()
@@ -2063,7 +2076,10 @@
"""
# This is essentially copied from the old imp module.
from importlib._bootstrap import _load
- loader = self.LOADER(name, path)
+ if is_apple_mobile:
+ loader = self.LOADER(name, path, None)
+ else:
+ loader = self.LOADER(name, path)
# Issue bpo-24748: Skip the sys.modules check in _load_module_shim;
# always load new extension.
diff --git a/Lib/test/test_importlib/extension/test_finder.py b/Lib/test/test_importlib/extension/test_finder.py
index 1d5b6e7a5d..519a1c536b 100644
--- a/Lib/test/test_importlib/extension/test_finder.py
+++ b/Lib/test/test_importlib/extension/test_finder.py
@@ -1,3 +1,4 @@
+from test.support import is_apple_mobile
from test.test_importlib import abc, util
machinery = util.import_importlib('importlib.machinery')
@@ -11,6 +12,8 @@
"""Test the finder for extension modules."""
def setUp(self):
+ if is_apple_mobile:
+ raise unittest.SkipTest(f"{sys.platform} uses a custom finder")
if not self.machinery.EXTENSION_SUFFIXES:
raise unittest.SkipTest("Requires dynamic loading support.")
if util.EXTENSIONS.name in sys.builtin_module_names:
diff --git a/Lib/test/test_importlib/extension/test_loader.py b/Lib/test/test_importlib/extension/test_loader.py
index 64c8a54851..fe3219c885 100644
--- a/Lib/test/test_importlib/extension/test_loader.py
+++ b/Lib/test/test_importlib/extension/test_loader.py
@@ -1,3 +1,4 @@
+from test.support import is_apple_mobile
from test.test_importlib import abc, util
machinery = util.import_importlib('importlib.machinery')
@@ -16,6 +17,8 @@
"""Test ExtensionFileLoader."""
def setUp(self):
+ if is_apple_mobile:
+ raise unittest.SkipTest(f"{sys.platform} uses a custom loader")
if not self.machinery.EXTENSION_SUFFIXES:
raise unittest.SkipTest("Requires dynamic loading support.")
if util.EXTENSIONS.name in sys.builtin_module_names:
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 022cf21a47..67f484d40e 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -40,6 +40,7 @@
from test.support.script_helper import (
assert_python_ok, assert_python_failure, run_python_until_end)
from test.support import import_helper
+from test.support import is_apple_mobile
from test.support import os_helper
from test.support import threading_helper
from test.support import warnings_helper
@@ -605,7 +606,7 @@
# On Windows and Mac OSX this test consumes large resources; It takes
# a long time to build the >2 GiB file and takes >2 GiB of disk space
# therefore the resource must be enabled to run this test.
- if sys.platform[:3] == 'win' or sys.platform == 'darwin':
+ if sys.platform[:3] == 'win' or sys.platform == 'darwin' or is_apple_mobile:
support.requires(
'largefile',
'test requires %s bytes and a long time to run' % self.LARGE)
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index ab969ce26a..e6aee6c7de 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -43,6 +43,7 @@
import tempfile
from test.support.script_helper import assert_python_ok, assert_python_failure
from test import support
+from test.support import is_apple_mobile
from test.support import os_helper
from test.support import socket_helper
from test.support import threading_helper
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index 3d9d6d5d0a..dfb1d6f84d 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -1,5 +1,5 @@
from test import support
-from test.support import os_helper, requires_debug_ranges
+from test.support import os_helper, requires_debug_ranges, is_apple_mobile
from test.support.script_helper import assert_python_ok
import array
import io
@@ -263,7 +263,10 @@
elif sys.platform == 'wasi':
MAX_MARSHAL_STACK_DEPTH = 1500
else:
- MAX_MARSHAL_STACK_DEPTH = 2000
+ if is_apple_mobile:
+ MAX_MARSHAL_STACK_DEPTH = 1500
+ else:
+ MAX_MARSHAL_STACK_DEPTH = 2000
for i in range(MAX_MARSHAL_STACK_DEPTH - 2):
last.append([0])
last = last[-1]
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index dfcf303942..5aabfac885 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -1,5 +1,5 @@
from test.support import (
- requires, _2G, _4G, gc_collect, cpython_only, is_emscripten
+ requires, _2G, _4G, gc_collect, cpython_only, is_emscripten, is_apple_mobile
)
from test.support.import_helper import import_module
from test.support.os_helper import TESTFN, unlink
@@ -245,7 +245,7 @@
with open(TESTFN, "r+b") as f:
self.assertRaises(ValueError, mmap.mmap, f.fileno(), mapsize, access=4)
- if os.name == "posix":
+ if os.name == "posix" and not is_apple_mobile:
# Try incompatible flags, prot and access parameters.
with open(TESTFN, "r+b") as f:
self.assertRaises(ValueError, mmap.mmap, f.fileno(), mapsize,
@@ -1007,7 +1007,7 @@
unlink(TESTFN)
def _make_test_file(self, num_zeroes, tail):
- if sys.platform[:3] == 'win' or sys.platform == 'darwin':
+ if sys.platform[:3] == 'win' or sys.platform == 'darwin' or is_apple_mobile:
requires('largefile',
'test requires %s bytes and a long time to run' % str(0x180000000))
f = open(TESTFN, 'w+b')
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 398393b233..52b0a2ac23 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -3785,6 +3785,7 @@