@@ -497,6 +497,30 @@ def mac_ver(release='', versioninfo=('', '', ''), machine=''):
497
497
# If that also doesn't work return the default values
498
498
return release , versioninfo , machine
499
499
500
+
501
+ # A namedtuple for iOS version information.
502
+ IOSVersionInfo = collections .namedtuple (
503
+ "IOSVersionInfo" ,
504
+ ["system" , "release" , "model" , "is_simulator" ]
505
+ )
506
+
507
+
508
+ def ios_ver (system = "" , release = "" , model = "" , is_simulator = False ):
509
+ """Get iOS version information, and return it as a namedtuple:
510
+ (system, release, model, is_simulator).
511
+
512
+ If values can't be determined, they are set to values provided as
513
+ parameters.
514
+ """
515
+ if sys .platform == "ios" :
516
+ import _ios_support
517
+ result = _ios_support .get_platform_ios ()
518
+ if result is not None :
519
+ return IOSVersionInfo (* result )
520
+
521
+ return IOSVersionInfo (system , release , model , is_simulator )
522
+
523
+
500
524
def _java_getprop (name , default ):
501
525
502
526
from java .lang import System
@@ -612,7 +636,7 @@ def _platform(*args):
612
636
if cleaned == platform :
613
637
break
614
638
platform = cleaned
615
- while platform [- 1 ] == '-' :
639
+ while platform and platform [- 1 ] == '-' :
616
640
platform = platform [:- 1 ]
617
641
618
642
return platform
@@ -653,7 +677,7 @@ def _syscmd_file(target, default=''):
653
677
default in case the command should fail.
654
678
655
679
"""
656
- if sys .platform in ( 'dos' , 'win32' , 'win16' ) :
680
+ if sys .platform in { 'dos' , 'win32' , 'win16' , 'ios' , 'tvos' , 'watchos' } :
657
681
# XXX Others too ?
658
682
return default
659
683
@@ -815,6 +839,14 @@ def get_OpenVMS():
815
839
csid , cpu_number = vms_lib .getsyi ('SYI$_CPU' , 0 )
816
840
return 'Alpha' if cpu_number >= 128 else 'VAX'
817
841
842
+ # On the iOS simulator, os.uname returns the architecture as uname.machine.
843
+ # On device it returns the model name for some reason; but there's only one
844
+ # CPU architecture for iOS devices, so we know the right answer.
845
+ def get_ios ():
846
+ if sys .implementation ._multiarch .endswith ("simulator" ):
847
+ return os .uname ().machine
848
+ return 'arm64'
849
+
818
850
def from_subprocess ():
819
851
"""
820
852
Fall back to `uname -p`
@@ -969,6 +1001,10 @@ def uname():
969
1001
system = 'Windows'
970
1002
release = 'Vista'
971
1003
1004
+ # Normalize responses on iOS
1005
+ if sys .platform == 'ios' :
1006
+ system , release , _ , _ = ios_ver ()
1007
+
972
1008
vals = system , node , release , version , machine
973
1009
# Replace 'unknown' values with the more portable ''
974
1010
_uname_cache = uname_result (* map (_unknown_as_blank , vals ))
@@ -1248,11 +1284,14 @@ def platform(aliased=False, terse=False):
1248
1284
system , release , version = system_alias (system , release , version )
1249
1285
1250
1286
if system == 'Darwin' :
1251
- # macOS (darwin kernel)
1252
- macos_release = mac_ver ()[0 ]
1253
- if macos_release :
1254
- system = 'macOS'
1255
- release = macos_release
1287
+ # macOS and iOS both report as a "Darwin" kernel
1288
+ if sys .platform == "ios" :
1289
+ system , release , _ , _ = ios_ver ()
1290
+ else :
1291
+ macos_release = mac_ver ()[0 ]
1292
+ if macos_release :
1293
+ system = 'macOS'
1294
+ release = macos_release
1256
1295
1257
1296
if system == 'Windows' :
1258
1297
# MS platforms
0 commit comments