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
9640 lines (9275 loc) · 445 KB
/
Python.patch
File metadata and controls
9640 lines (9275 loc) · 445 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
--- /dev/null
+++ b/Lib/_ios_support.py
@@ -0,0 +1,36 @@
+from ctypes import cdll, c_void_p, c_char_p
+from ctypes import util
+
+
+def get_platform_ios():
+ 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
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 0c2510e161..6c3c43f11d 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/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py
index 8e7364d2a2..eec325fecc 100644
--- a/Lib/distutils/tests/test_build_ext.py
+++ b/Lib/distutils/tests/test_build_ext.py
@@ -15,7 +15,7 @@
import unittest
from test import support
-from test.support import os_helper
+from test.support import os_helper, has_subprocess_support
from test.support.script_helper import assert_python_ok
# http://bugs.python.org/issue4373
@@ -56,6 +56,7 @@
def build_ext(self, *args, **kwargs):
return build_ext(*args, **kwargs)
+ @unittest.skipUnless(has_subprocess_support, "distutils cannot spawn child processes")
def test_build_ext(self):
cmd = support.missing_compiler_executable()
if cmd is not None:
@@ -332,6 +333,7 @@
cmd.run()
self.assertEqual(cmd.compiler, 'unix')
+ @unittest.skipUnless(has_subprocess_support, "distutils cannot spawn child processes")
def test_get_outputs(self):
cmd = support.missing_compiler_executable()
if cmd is not None:
diff --git a/Lib/distutils/tests/test_build_py.py b/Lib/distutils/tests/test_build_py.py
index 0712e92c6a..4c05e8d968 100644
--- a/Lib/distutils/tests/test_build_py.py
+++ b/Lib/distutils/tests/test_build_py.py
@@ -9,7 +9,7 @@
from distutils.errors import DistutilsFileError
from distutils.tests import support
-from test.support import run_unittest
+from test.support import run_unittest, has_subprocess_support
class BuildPyTestCase(support.TempdirManager,
@@ -106,6 +106,7 @@
['boiledeggs.%s.pyc' % sys.implementation.cache_tag])
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
+ @unittest.skipUnless(has_subprocess_support, "distutils cannot spawn child processes")
def test_byte_compile_optimized(self):
project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
os.chdir(project_dir)
diff --git a/Lib/distutils/tests/test_config_cmd.py b/Lib/distutils/tests/test_config_cmd.py
index 0127ba71fc..d03356af1b 100644
--- a/Lib/distutils/tests/test_config_cmd.py
+++ b/Lib/distutils/tests/test_config_cmd.py
@@ -3,7 +3,7 @@
import os
import sys
import sysconfig
-from test.support import run_unittest, missing_compiler_executable
+from test.support import run_unittest, missing_compiler_executable, has_subprocess_support
from distutils.command.config import dump_file, config
from distutils.tests import support
@@ -42,6 +42,7 @@
self.assertEqual(len(self._logs), numlines+1)
@unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def test_search_cpp(self):
cmd = missing_compiler_executable(['preprocessor'])
if cmd is not None:
diff --git a/Lib/distutils/tests/test_cygwinccompiler.py b/Lib/distutils/tests/test_cygwinccompiler.py
index 9dc869de4c..9a1b18aba9 100644
--- a/Lib/distutils/tests/test_cygwinccompiler.py
+++ b/Lib/distutils/tests/test_cygwinccompiler.py
@@ -5,11 +5,14 @@
from io import BytesIO
from test.support import run_unittest
-from distutils import cygwinccompiler
-from distutils.cygwinccompiler import (check_config_h,
- CONFIG_H_OK, CONFIG_H_NOTOK,
- CONFIG_H_UNCERTAIN, get_versions,
- get_msvcr)
+# Importing cygwinccompiler attempts to import other tools
+# that may not exist unless you're on win32.
+if sys.platform == 'win32':
+ from distutils import cygwinccompiler
+ from distutils.cygwinccompiler import (check_config_h,
+ CONFIG_H_OK, CONFIG_H_NOTOK,
+ CONFIG_H_UNCERTAIN, get_versions,
+ get_msvcr)
from distutils.tests import support
class FakePopen(object):
@@ -25,6 +28,7 @@
self.stdout = os.popen(cmd, 'r')
+@unittest.skipUnless(sys.platform == "win32", "These tests are only for win32")
class CygwinCCompilerTestCase(support.TempdirManager,
unittest.TestCase):
diff --git a/Lib/distutils/tests/test_install.py b/Lib/distutils/tests/test_install.py
index 0632024b35..a21962792b 100644
--- a/Lib/distutils/tests/test_install.py
+++ b/Lib/distutils/tests/test_install.py
@@ -5,7 +5,7 @@
import unittest
import site
-from test.support import captured_stdout, run_unittest
+from test.support import captured_stdout, run_unittest, has_subprocess_support
from distutils import sysconfig
from distutils.command.install import install, HAS_USER_SITE
@@ -208,6 +208,7 @@
'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
self.assertEqual(found, expected)
+ @unittest.skipUnless(has_subprocess_support, "distutils cannot spawn child processes")
def test_record_extensions(self):
cmd = test_support.missing_compiler_executable()
if cmd is not None:
diff --git a/Lib/distutils/tests/test_install_lib.py b/Lib/distutils/tests/test_install_lib.py
index fda6315bbc..121664b722 100644
--- a/Lib/distutils/tests/test_install_lib.py
+++ b/Lib/distutils/tests/test_install_lib.py
@@ -8,7 +8,7 @@
from distutils.extension import Extension
from distutils.tests import support
from distutils.errors import DistutilsOptionError
-from test.support import run_unittest
+from test.support import run_unittest, has_subprocess_support
class InstallLibTestCase(support.TempdirManager,
@@ -35,6 +35,7 @@
self.assertEqual(cmd.optimize, 2)
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
+ @unittest.skipUnless(has_subprocess_support, "distutils cannot spawn child processes")
def test_byte_compile(self):
project_dir, dist = self.create_dist()
os.chdir(project_dir)
diff --git a/Lib/distutils/tests/test_spawn.py b/Lib/distutils/tests/test_spawn.py
index 4ec767b120..10003aa99e 100644
--- a/Lib/distutils/tests/test_spawn.py
+++ b/Lib/distutils/tests/test_spawn.py
@@ -3,7 +3,7 @@
import stat
import sys
import unittest.mock
-from test.support import run_unittest, unix_shell
+from test.support import run_unittest, unix_shell, has_subprocess_support
from test.support import os_helper
from distutils.spawn import find_executable
@@ -15,8 +15,7 @@
support.LoggingSilencer,
unittest.TestCase):
- @unittest.skipUnless(os.name in ('nt', 'posix'),
- 'Runs only under posix or nt')
+ @unittest.skipUnless(has_subprocess_support, "distutils cannot spawn child processes")
def test_spawn(self):
tmpdir = self.mkdtemp()
diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py
index 59676b0e0b..6bbeea0df7 100644
--- a/Lib/distutils/tests/test_sysconfig.py
+++ b/Lib/distutils/tests/test_sysconfig.py
@@ -10,7 +10,7 @@
from distutils import sysconfig
from distutils.ccompiler import get_default_compiler
from distutils.tests import support
-from test.support import run_unittest, swap_item
+from test.support import run_unittest, swap_item, has_subprocess_support
from test.support.os_helper import TESTFN
from test.support.warnings_helper import check_warnings
@@ -247,6 +247,7 @@
self.assertIsNotNone(vars['SO'])
self.assertEqual(vars['SO'], vars['EXT_SUFFIX'])
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def test_customize_compiler_before_get_config_vars(self):
# Issue #21923: test that a Distribution compiler
# instance can be called without an explicit call to
diff --git a/Lib/distutils/tests/test_util.py b/Lib/distutils/tests/test_util.py
index d4a01c6e91..f3fc4607e1 100644
--- a/Lib/distutils/tests/test_util.py
+++ b/Lib/distutils/tests/test_util.py
@@ -3,7 +3,7 @@
import sys
import unittest
from copy import copy
-from test.support import run_unittest
+from test.support import run_unittest, has_subprocess_support
from unittest import mock
from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
@@ -234,6 +234,7 @@
# XXX platforms to be covered: mac
+ @unittest.skipUnless(has_subprocess_support, "distutils cannot spawn child processes")
def test_check_environ(self):
util._environ_checked = 0
os.environ.pop('HOME', None)
diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py
index d00c48981e..5d12b4779d 100644
--- a/Lib/distutils/unixccompiler.py
+++ b/Lib/distutils/unixccompiler.py
@@ -270,9 +270,9 @@
static_f = self.library_filename(lib, lib_type='static')
if sys.platform == 'darwin':
- # On OSX users can specify an alternate SDK using
- # '-isysroot', calculate the SDK root if it is specified
- # (and use it further on)
+ # On macOS users can specify an alternate SDK using
+ # '-isysroot <path>' or --sysroot=<path>, calculate the SDK root
+ # if it is specified (and use it further on)
#
# Note that, as of Xcode 7, Apple SDKs may contain textual stub
# libraries with .tbd extensions rather than the normal .dylib
@@ -291,12 +291,14 @@
cflags = sysconfig.get_config_var('CFLAGS')
m = re.search(r'-isysroot\s*(\S+)', cflags)
if m is None:
- sysroot = _osx_support._default_sysroot(sysconfig.get_config_var('CC'))
+ m = re.search(r'--sysroot=(\S+)', cflags)
+ if m is None:
+ sysroot = _osx_support._default_sysroot(sysconfig.get_config_var('CC'))
+ else:
+ sysroot = m.group(1)
else:
sysroot = m.group(1)
-
-
for dir in dirs:
shared = os.path.join(dir, shared_f)
dylib = os.path.join(dir, dylib_f)
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 49bcaea78d..cccdbc708b 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)
@@ -1637,6 +1637,59 @@
return 'FileFinder({!r})'.format(self.path)
+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 in .dylibs,
+ contained in a Framework, 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)
+ if _path_isfile(dylib_file):
+ 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):
@@ -1684,3 +1737,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/platform.py b/Lib/platform.py
index 6a820c90a1..f16a540118 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -449,6 +449,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
@@ -605,7 +625,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
@@ -744,6 +764,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`
@@ -893,6 +931,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))
@@ -1205,11 +1252,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 939893eb5e..8c550ed95a 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 f1e3d64dfe..9a7c6f8e7f 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -96,6 +96,8 @@
"CREATE_NO_WINDOW", "DETACHED_PROCESS",
"CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"])
+# Some platforms do not support processes
+_can_fork_exec = sys.platform not in {"ios", "tvos", "watchos"}
# Exception classes used by this module.
class SubprocessError(Exception): pass
@@ -764,6 +766,9 @@
pass_fds=(), *, user=None, group=None, extra_groups=None,
encoding=None, errors=None, text=None, umask=-1, pipesize=-1):
"""Create new Popen instance."""
+ if not _can_fork_exec:
+ raise RuntimeError(f"Subprocesses are not supported on {sys.platform}")
+
_cleanup()
# Held while anything is calling waitpid before returncode has been
# updated to prevent clobbering returncode if wait() or poll() are
@@ -1876,7 +1881,7 @@
else:
self.returncode = waitstatus_to_exitcode(sts)
- def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
+ def _internal_poll(self, _deadstate=None, _waitpid=None,
_WNOHANG=os.WNOHANG, _ECHILD=errno.ECHILD):
"""Check if child process has terminated. Returns returncode
attribute.
@@ -1885,6 +1890,8 @@
outside of the local scope (nor can any methods it calls).
"""
+ if _waitpid is None:
+ _waitpid = os.waitpid
if self.returncode is None:
if not self._waitpid_lock.acquire(False):
# Something else is busy calling waitpid. Don't allow two
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index daf9f00006..8d32223243 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -56,6 +56,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',
+ },
}
@@ -231,12 +258,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',
@@ -740,10 +774,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 b7cf1e2858..36e6bbf84f 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -43,7 +43,7 @@
"check__all__", "skip_if_buggy_ucrt_strfptime",
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
# sys
- "is_jython", "is_android", "check_impl_detail", "unix_shell",
+ "is_jython", "is_android", "is_apple_mobile", "check_impl_detail", "unix_shell",
"setswitchinterval",
# network
"open_urlresource",
@@ -469,11 +469,24 @@
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
+# 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_apple_mobile
+)
+
+has_subprocess_support = (
+ not is_apple_mobile
+)
+
# Define the URL of a dedicated HTTP server for the network tests.
# The URL must use clear-text HTTP: no redirection to encrypted HTTPS.
TEST_HTTP_URL = "http://www.pythontest.net"
diff --git a/Lib/test/support/script_helper.py b/Lib/test/support/script_helper.py
index 6d699c8486..8e7341bd21 100644
--- a/Lib/test/support/script_helper.py
+++ b/Lib/test/support/script_helper.py
@@ -8,10 +8,12 @@
import os.path
import subprocess
import py_compile
+import unittest
import zipfile
from importlib.util import source_from_cache
from test import support
+from test.support import has_subprocess_support
from test.support.import_helper import make_legacy_pyc
@@ -19,6 +21,7 @@
__cached_interp_requires_environment = None
+@unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def interpreter_requires_environment():
"""
Returns True if our sys.executable interpreter requires environment
@@ -139,6 +142,7 @@
return _PythonRunResult(rc, out, err), cmd_line
+@unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def _assert_python(expected_success, /, *args, **env_vars):
res, cmd_line = run_python_until_end(*args, **env_vars)
if (res.rc and expected_success) or (not res.rc and not expected_success):
@@ -171,6 +175,7 @@
return _assert_python(False, *args, **env_vars)
+@unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
"""Run a Python subprocess with the given arguments.
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 253a6c119c..b6c386d83c 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -32,6 +32,7 @@
from asyncio import selector_events
from test.test_asyncio import utils as test_utils
from test import support
+from test.support import is_apple_mobile, has_subprocess_support
from test.support import socket_helper
from test.support import threading_helper
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
@@ -541,6 +542,7 @@
self._basetest_create_connection(conn_fut)
@socket_helper.skip_unless_bind_unix_socket
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_create_unix_connection(self):
# Issue #20682: On Mac OS X Tiger, getsockname() returns a
# zero-length address for UNIX socket.
@@ -633,6 +635,7 @@
self.assertEqual(cm.exception.reason, 'CERTIFICATE_VERIFY_FAILED')
@unittest.skipIf(ssl is None, 'No ssl module')
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_create_ssl_connection(self):
with test_utils.run_test_server(use_ssl=True) as httpd:
create_connection = functools.partial(
@@ -644,6 +647,7 @@
@socket_helper.skip_unless_bind_unix_socket
@unittest.skipIf(ssl is None, 'No ssl module')
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_create_ssl_unix_connection(self):
# Issue #20682: On Mac OS X Tiger, getsockname() returns a
# zero-length address for UNIX socket.
@@ -908,6 +912,7 @@
return server, path
@socket_helper.skip_unless_bind_unix_socket
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_create_unix_server(self):
proto = MyProto(loop=self.loop)
server, path = self._make_unix_server(lambda: proto)
@@ -936,6 +941,7 @@
server.close()
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'No UNIX Sockets')
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_create_unix_server_path_socket_error(self):
proto = MyProto(loop=self.loop)
sock = socket.socket()
@@ -1001,6 +1007,7 @@
@socket_helper.skip_unless_bind_unix_socket
@unittest.skipIf(ssl is None, 'No ssl module')
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_create_unix_server_ssl(self):
proto = MyProto(loop=self.loop)
server, path = self._make_ssl_unix_server(
@@ -1031,6 +1038,7 @@
server.close()
@unittest.skipIf(ssl is None, 'No ssl module')
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_create_server_ssl_verify_failed(self):
proto = MyProto(loop=self.loop)
server, host, port = self._make_ssl_server(
@@ -1061,6 +1069,7 @@
@socket_helper.skip_unless_bind_unix_socket
@unittest.skipIf(ssl is None, 'No ssl module')
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_create_unix_server_ssl_verify_failed(self):
proto = MyProto(loop=self.loop)
server, path = self._make_ssl_unix_server(
@@ -1121,6 +1130,7 @@
@socket_helper.skip_unless_bind_unix_socket
@unittest.skipIf(ssl is None, 'No ssl module')
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_create_unix_server_ssl_verified(self):
proto = MyProto(loop=self.loop)
server, path = self._make_ssl_unix_server(
@@ -1783,6 +1793,7 @@
next(it)
+@unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
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 994041c10f..378767ebbc 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -17,6 +17,7 @@
import asyncio
from test.test_asyncio import utils as test_utils
+from test.support import is_apple_mobile, has_subprocess_support
def tearDownModule():
@@ -60,6 +61,7 @@
self._basetest_open_connection(conn_fut)
@socket_helper.skip_unless_bind_unix_socket
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_open_unix_connection(self):
with test_utils.run_test_unix_server() as httpd:
conn_fut = asyncio.open_unix_connection(httpd.address)
@@ -91,6 +93,7 @@
@socket_helper.skip_unless_bind_unix_socket
@unittest.skipIf(ssl is None, 'No ssl module')
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_open_unix_connection_no_loop_ssl(self):
with test_utils.run_test_unix_server(use_ssl=True) as httpd:
conn_fut = asyncio.open_unix_connection(
@@ -119,6 +122,7 @@
self._basetest_open_connection_error(conn_fut)
@socket_helper.skip_unless_bind_unix_socket
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_open_unix_connection_error(self):
with test_utils.run_test_unix_server() as httpd:
conn_fut = asyncio.open_unix_connection(httpd.address)
@@ -637,6 +641,7 @@
self.assertEqual(messages, [])
@socket_helper.skip_unless_bind_unix_socket
+ @unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
def test_start_unix_server(self):
class MyServer:
@@ -707,6 +712,7 @@
self.assertEqual(messages, [])
@unittest.skipIf(sys.platform == 'win32', "Don't have pipes")
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
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 7cd80fd68e..ccb0faa025 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -10,7 +10,7 @@
from asyncio import subprocess
from test.test_asyncio import utils as test_utils
from test import support
-from test.support import os_helper
+from test.support import os_helper, has_subprocess_support
if sys.platform != 'win32':
from asyncio import unix_events
@@ -104,6 +104,7 @@
transport.close()
+@unittest.skipUnless(has_subprocess_support, 'Test requires support for 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 01c1214c7f..3944874ec3 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -13,6 +13,7 @@
import threading
import unittest
from unittest import mock
+from test.support import is_apple_mobile, has_subprocess_support
from test.support import os_helper
from test.support import socket_helper
@@ -276,6 +277,7 @@
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'),
'UNIX Sockets are not supported')
+@unittest.skipIf(is_apple_mobile, "%s doesn't fully support UNIX sockets." % sys.platform)
class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
def setUp(self):
@@ -1134,6 +1136,7 @@
NotImplementedError, watcher._do_waitpid, f)
+@unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
class ChildWatcherTestsMixin:
ignore_warnings = mock.patch.object(log.logger, "warning")
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
index 418492432a..88a302f13f 100644
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -3,6 +3,7 @@
import binascii
import os
from array import array
+from test.support import has_subprocess_support
from test.support import os_helper
from test.support import script_helper
@@ -754,6 +755,7 @@
self.assertEqual(b16encode(b"foobar"), b"666F6F626172")
+@unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
class TestMain(unittest.TestCase):
def tearDown(self):
if os.path.exists(os_helper.TESTFN):
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py
index 404a13a0bc..233eed288e 100644
--- a/Lib/test/test_capi/test_misc.py
+++ b/Lib/test/test_capi/test_misc.py
@@ -17,6 +17,7 @@
import weakref
from test import support
from test.support import MISSING_C_DOCSTRINGS
+from test.support import has_subprocess_support
from test.support import import_helper
from test.support import threading_helper
from test.support import warnings_helper
@@ -61,6 +62,7 @@
self.assertEqual(testfunction.attribute, "test")
self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute", "test")
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def test_no_FatalError_infinite_loop(self):
with support.SuppressCrashReport():
p = subprocess.Popen([sys.executable, "-c",
@@ -814,6 +816,7 @@
self.assertEqual(main_attr_id, subinterp_attr_id)
+@unittest.skipUnless(threading, 'Threading required for this test.')
class TestThreadState(unittest.TestCase):
@threading_helper.reap_threads
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 14de3d40b9..0a39b0cdbe 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -9,7 +9,7 @@
import textwrap
import unittest
from test import support
-from test.support import os_helper
+from test.support import os_helper, has_subprocess_support
from test.support.script_helper import (
spawn_python, kill_python, assert_python_ok, assert_python_failure,
interpreter_requires_environment
@@ -68,6 +68,7 @@
rc, out, err = assert_python_ok('-vv')
self.assertNotIn(b'stack overflow', err)
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
@unittest.skipIf(interpreter_requires_environment(),
'Cannot run -E tests when PYTHON env vars are required.')
def test_xoptions(self):
@@ -86,6 +87,7 @@
opts = get_xoptions('-Xa', '-Xb=c,d=e')
self.assertEqual(opts, {'a': True, 'b': 'c,d=e'})
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def test_showrefcount(self):
def run_python(*args):
# this is similar to assert_python_ok but doesn't strip
@@ -178,6 +180,7 @@
# arguments as unicode (using wmain() instead of main()).
@unittest.skipIf(sys.platform == 'win32',
'Windows has a native unicode API')
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def test_undecodable_code(self):
undecodable = b"\xff"
env = os.environ.copy()
@@ -293,6 +296,7 @@
'False False False\n'
'False False True\n')
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def test_unbuffered_output(self):
# Test expected operation of the '-u' switch
for stream in ('stdout', 'stderr'):
@@ -351,6 +355,7 @@
# for empty and unset PYTHONPATH
self.assertEqual(out1, out2)
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def test_displayhook_unencodable(self):
for encoding in ('ascii', 'latin-1', 'utf-8'):
env = os.environ.copy()
@@ -369,6 +374,7 @@
escaped = repr(text).encode(encoding, 'backslashreplace')
self.assertIn(escaped, data)
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def check_input(self, code, expected):
with tempfile.NamedTemporaryFile("wb+") as stdin:
sep = os.linesep.encode('ASCII')
@@ -444,6 +450,7 @@
@unittest.skipIf(os.name != 'posix', "test needs POSIX semantics")
@unittest.skipIf(sys.platform == "vxworks",
"test needs preexec support in subprocess.Popen")
+ @unittest.skipUnless(has_subprocess_support, 'Test requires support for subprocesses.')
def _test_no_stdio(self, streams):