@@ -521,6 +521,54 @@ def ios_ver(system="", release="", model="", is_simulator=False):
521
521
return IOSVersionInfo (system , release , model , is_simulator )
522
522
523
523
524
+ # A namedtuple for tvOS version information.
525
+ TVOSVersionInfo = collections .namedtuple (
526
+ "TVOSVersionInfo" ,
527
+ ["system" , "release" , "model" , "is_simulator" ]
528
+ )
529
+
530
+
531
+ def tvos_ver (system = "" , release = "" , model = "" , is_simulator = False ):
532
+ """Get tvOS version information, and return it as a namedtuple:
533
+ (system, release, model, is_simulator).
534
+
535
+ If values can't be determined, they are set to values provided as
536
+ parameters.
537
+ """
538
+ if sys .platform == "tvos" :
539
+ # TODO: Can the iOS implementation be used here?
540
+ import _ios_support
541
+ result = _ios_support .get_platform_ios ()
542
+ if result is not None :
543
+ return TVOSVersionInfo (* result )
544
+
545
+ return TVOSVersionInfo (system , release , model , is_simulator )
546
+
547
+
548
+ # A namedtuple for watchOS version information.
549
+ WatchOSVersionInfo = collections .namedtuple (
550
+ "WatchOSVersionInfo" ,
551
+ ["system" , "release" , "model" , "is_simulator" ]
552
+ )
553
+
554
+
555
+ def watchos_ver (system = "" , release = "" , model = "" , is_simulator = False ):
556
+ """Get watchOS version information, and return it as a namedtuple:
557
+ (system, release, model, is_simulator).
558
+
559
+ If values can't be determined, they are set to values provided as
560
+ parameters.
561
+ """
562
+ if sys .platform == "watchos" :
563
+ # TODO: Can the iOS implementation be used here?
564
+ import _ios_support
565
+ result = _ios_support .get_platform_ios ()
566
+ if result is not None :
567
+ return WatchOSVersionInfo (* result )
568
+
569
+ return WatchOSVersionInfo (system , release , model , is_simulator )
570
+
571
+
524
572
def _java_getprop (name , default ):
525
573
"""This private helper is deprecated in 3.13 and will be removed in 3.15"""
526
574
from java .lang import System
@@ -884,14 +932,25 @@ def get_OpenVMS():
884
932
csid , cpu_number = vms_lib .getsyi ('SYI$_CPU' , 0 )
885
933
return 'Alpha' if cpu_number >= 128 else 'VAX'
886
934
887
- # On the iOS simulator, os.uname returns the architecture as uname.machine.
888
- # On device it returns the model name for some reason; but there's only one
889
- # CPU architecture for iOS devices, so we know the right answer.
935
+ # On the iOS/tvOS/watchOS simulator, os.uname returns the architecture as
936
+ # uname.machine. On device it returns the model name for some reason; but
937
+ # there's only one CPU architecture for devices, so we know the right
938
+ # answer.
890
939
def get_ios ():
891
940
if sys .implementation ._multiarch .endswith ("simulator" ):
892
941
return os .uname ().machine
893
942
return 'arm64'
894
943
944
+ def get_tvos ():
945
+ if sys .implementation ._multiarch .endswith ("simulator" ):
946
+ return os .uname ().machine
947
+ return 'arm64'
948
+
949
+ def get_watchos ():
950
+ if sys .implementation ._multiarch .endswith ("simulator" ):
951
+ return os .uname ().machine
952
+ return 'arm64_32'
953
+
895
954
def from_subprocess ():
896
955
"""
897
956
Fall back to `uname -p`
@@ -1051,9 +1110,13 @@ def uname():
1051
1110
system = 'Android'
1052
1111
release = android_ver ().release
1053
1112
1054
- # Normalize responses on iOS
1113
+ # Normalize responses on Apple mobile platforms
1055
1114
if sys .platform == 'ios' :
1056
1115
system , release , _ , _ = ios_ver ()
1116
+ if sys .platform == 'tvos' :
1117
+ system , release , _ , _ = tvos_ver ()
1118
+ if sys .platform == 'watchos' :
1119
+ system , release , _ , _ = watchos_ver ()
1057
1120
1058
1121
vals = system , node , release , version , machine
1059
1122
# Replace 'unknown' values with the more portable ''
@@ -1343,6 +1406,10 @@ def platform(aliased=False, terse=False):
1343
1406
# macOS and iOS both report as a "Darwin" kernel
1344
1407
if sys .platform == "ios" :
1345
1408
system , release , _ , _ = ios_ver ()
1409
+ elif sys .platform == "tvos" :
1410
+ system , release , _ , _ = tvos_ver ()
1411
+ elif sys .platform == "watchos" :
1412
+ system , release , _ , _ = watchos_ver ()
1346
1413
else :
1347
1414
macos_release = mac_ver ()[0 ]
1348
1415
if macos_release :
0 commit comments