@@ -449,6 +449,30 @@ def mac_ver(release='', versioninfo=('', '', ''), machine=''):
449
449
# If that also doesn't work return the default values
450
450
return release , versioninfo , machine
451
451
452
+
453
+ # A namedtuple for iOS version information.
454
+ IOSVersionInfo = collections .namedtuple (
455
+ "IOSVersionInfo" ,
456
+ ["system" , "release" , "model" , "is_simulator" ]
457
+ )
458
+
459
+
460
+ def ios_ver (system = "" , release = "" , model = "" , is_simulator = False ):
461
+ """Get iOS version information, and return it as a namedtuple:
462
+ (system, release, model, is_simulator).
463
+
464
+ If values can't be determined, they are set to values provided as
465
+ parameters.
466
+ """
467
+ if sys .platform == "ios" :
468
+ import _ios_support
469
+ result = _ios_support .get_platform_ios ()
470
+ if result is not None :
471
+ return IOSVersionInfo (* result )
472
+
473
+ return IOSVersionInfo (system , release , model , is_simulator )
474
+
475
+
452
476
def _java_getprop (name , default ):
453
477
454
478
from java .lang import System
@@ -574,7 +598,7 @@ def _platform(*args):
574
598
if cleaned == platform :
575
599
break
576
600
platform = cleaned
577
- while platform [- 1 ] == '-' :
601
+ while platform and platform [- 1 ] == '-' :
578
602
platform = platform [:- 1 ]
579
603
580
604
return platform
@@ -615,7 +639,7 @@ def _syscmd_file(target, default=''):
615
639
default in case the command should fail.
616
640
617
641
"""
618
- if sys .platform in ( 'dos' , 'win32' , 'win16' ) :
642
+ if sys .platform in { 'dos' , 'win32' , 'win16' , 'ios' , 'tvos' , 'watchos' } :
619
643
# XXX Others too ?
620
644
return default
621
645
@@ -757,6 +781,14 @@ def get_OpenVMS():
757
781
csid , cpu_number = vms_lib .getsyi ('SYI$_CPU' , 0 )
758
782
return 'Alpha' if cpu_number >= 128 else 'VAX'
759
783
784
+ # On the iOS simulator, os.uname returns the architecture as uname.machine.
785
+ # On device it returns the model name for some reason; but there's only one
786
+ # CPU architecture for iOS devices, so we know the right answer.
787
+ def get_ios ():
788
+ if sys .implementation ._multiarch .endswith ("simulator" ):
789
+ return os .uname ().machine
790
+ return 'arm64'
791
+
760
792
def from_subprocess ():
761
793
"""
762
794
Fall back to `uname -p`
@@ -904,6 +936,10 @@ def uname():
904
936
system = 'Windows'
905
937
release = 'Vista'
906
938
939
+ # Normalize responses on iOS
940
+ if sys .platform == 'ios' :
941
+ system , release , _ , _ = ios_ver ()
942
+
907
943
vals = system , node , release , version , machine
908
944
# Replace 'unknown' values with the more portable ''
909
945
_uname_cache = uname_result (* map (_unknown_as_blank , vals ))
@@ -1216,11 +1252,14 @@ def platform(aliased=0, terse=0):
1216
1252
system , release , version = system_alias (system , release , version )
1217
1253
1218
1254
if system == 'Darwin' :
1219
- # macOS (darwin kernel)
1220
- macos_release = mac_ver ()[0 ]
1221
- if macos_release :
1222
- system = 'macOS'
1223
- release = macos_release
1255
+ # macOS and iOS both report as a "Darwin" kernel
1256
+ if sys .platform == "ios" :
1257
+ system , release , _ , _ = ios_ver ()
1258
+ else :
1259
+ macos_release = mac_ver ()[0 ]
1260
+ if macos_release :
1261
+ system = 'macOS'
1262
+ release = macos_release
1224
1263
1225
1264
if system == 'Windows' :
1226
1265
# MS platforms
0 commit comments