@@ -528,6 +528,54 @@ def ios_ver(system="", release="", model="", is_simulator=False):
528528 return IOSVersionInfo (system , release , model , is_simulator )
529529
530530
531+ # A namedtuple for tvOS version information.
532+ TVOSVersionInfo = collections .namedtuple (
533+ "TVOSVersionInfo" ,
534+ ["system" , "release" , "model" , "is_simulator" ]
535+ )
536+
537+
538+ def tvos_ver (system = "" , release = "" , model = "" , is_simulator = False ):
539+ """Get tvOS version information, and return it as a namedtuple:
540+ (system, release, model, is_simulator).
541+
542+ If values can't be determined, they are set to values provided as
543+ parameters.
544+ """
545+ if sys .platform == "tvos" :
546+ # TODO: Can the iOS implementation be used here?
547+ import _ios_support
548+ result = _ios_support .get_platform_ios ()
549+ if result is not None :
550+ return TVOSVersionInfo (* result )
551+
552+ return TVOSVersionInfo (system , release , model , is_simulator )
553+
554+
555+ # A namedtuple for watchOS version information.
556+ WatchOSVersionInfo = collections .namedtuple (
557+ "WatchOSVersionInfo" ,
558+ ["system" , "release" , "model" , "is_simulator" ]
559+ )
560+
561+
562+ def watchos_ver (system = "" , release = "" , model = "" , is_simulator = False ):
563+ """Get watchOS version information, and return it as a namedtuple:
564+ (system, release, model, is_simulator).
565+
566+ If values can't be determined, they are set to values provided as
567+ parameters.
568+ """
569+ if sys .platform == "watchos" :
570+ # TODO: Can the iOS implementation be used here?
571+ import _ios_support
572+ result = _ios_support .get_platform_ios ()
573+ if result is not None :
574+ return WatchOSVersionInfo (* result )
575+
576+ return WatchOSVersionInfo (system , release , model , is_simulator )
577+
578+
531579def _java_getprop (name , default ):
532580 """This private helper is deprecated in 3.13 and will be removed in 3.15"""
533581 from java .lang import System
@@ -891,14 +939,25 @@ def get_OpenVMS():
891939 csid , cpu_number = vms_lib .getsyi ('SYI$_CPU' , 0 )
892940 return 'Alpha' if cpu_number >= 128 else 'VAX'
893941
894- # On the iOS simulator, os.uname returns the architecture as uname.machine.
895- # On device it returns the model name for some reason; but there's only one
896- # CPU architecture for iOS devices, so we know the right answer.
942+ # On the iOS/tvOS/watchOS simulator, os.uname returns the architecture as
943+ # uname.machine. On device it returns the model name for some reason; but
944+ # there's only one CPU architecture for devices, so we know the right
945+ # answer.
897946 def get_ios ():
898947 if sys .implementation ._multiarch .endswith ("simulator" ):
899948 return os .uname ().machine
900949 return 'arm64'
901950
951+ def get_tvos ():
952+ if sys .implementation ._multiarch .endswith ("simulator" ):
953+ return os .uname ().machine
954+ return 'arm64'
955+
956+ def get_watchos ():
957+ if sys .implementation ._multiarch .endswith ("simulator" ):
958+ return os .uname ().machine
959+ return 'arm64_32'
960+
902961 def from_subprocess ():
903962 """
904963 Fall back to `uname -p`
@@ -1058,9 +1117,13 @@ def uname():
10581117 system = 'Android'
10591118 release = android_ver ().release
10601119
1061- # Normalize responses on iOS
1120+ # Normalize responses on Apple mobile platforms
10621121 if sys .platform == 'ios' :
10631122 system , release , _ , _ = ios_ver ()
1123+ if sys .platform == 'tvos' :
1124+ system , release , _ , _ = tvos_ver ()
1125+ if sys .platform == 'watchos' :
1126+ system , release , _ , _ = watchos_ver ()
10641127
10651128 vals = system , node , release , version , machine
10661129 # Replace 'unknown' values with the more portable ''
@@ -1350,6 +1413,10 @@ def platform(aliased=False, terse=False):
13501413 # macOS and iOS both report as a "Darwin" kernel
13511414 if sys .platform == "ios" :
13521415 system , release , _ , _ = ios_ver ()
1416+ elif sys .platform == "tvos" :
1417+ system , release , _ , _ = tvos_ver ()
1418+ elif sys .platform == "watchos" :
1419+ system , release , _ , _ = watchos_ver ()
13531420 else :
13541421 macos_release = mac_ver ()[0 ]
13551422 if macos_release :
0 commit comments