@@ -521,6 +521,54 @@ def ios_ver(system="", release="", model="", is_simulator=False):
521521 return IOSVersionInfo (system , release , model , is_simulator )
522522
523523
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+
524572def _java_getprop (name , default ):
525573 """This private helper is deprecated in 3.13 and will be removed in 3.15"""
526574 from java .lang import System
@@ -884,14 +932,25 @@ def get_OpenVMS():
884932 csid , cpu_number = vms_lib .getsyi ('SYI$_CPU' , 0 )
885933 return 'Alpha' if cpu_number >= 128 else 'VAX'
886934
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.
890939 def get_ios ():
891940 if sys .implementation ._multiarch .endswith ("simulator" ):
892941 return os .uname ().machine
893942 return 'arm64'
894943
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+
895954 def from_subprocess ():
896955 """
897956 Fall back to `uname -p`
@@ -1051,9 +1110,13 @@ def uname():
10511110 system = 'Android'
10521111 release = android_ver ().release
10531112
1054- # Normalize responses on iOS
1113+ # Normalize responses on Apple mobile platforms
10551114 if sys .platform == 'ios' :
10561115 system , release , _ , _ = ios_ver ()
1116+ if sys .platform == 'tvos' :
1117+ system , release , _ , _ = tvos_ver ()
1118+ if sys .platform == 'watchos' :
1119+ system , release , _ , _ = watchos_ver ()
10571120
10581121 vals = system , node , release , version , machine
10591122 # Replace 'unknown' values with the more portable ''
@@ -1343,6 +1406,10 @@ def platform(aliased=False, terse=False):
13431406 # macOS and iOS both report as a "Darwin" kernel
13441407 if sys .platform == "ios" :
13451408 system , release , _ , _ = ios_ver ()
1409+ elif sys .platform == "tvos" :
1410+ system , release , _ , _ = tvos_ver ()
1411+ elif sys .platform == "watchos" :
1412+ system , release , _ , _ = watchos_ver ()
13461413 else :
13471414 macos_release = mac_ver ()[0 ]
13481415 if macos_release :
0 commit comments