Skip to content

Commit

Permalink
[3.11] Add support for tvOS and watchOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Aug 5, 2024
1 parent 59e9bef commit 087749d
Show file tree
Hide file tree
Showing 32 changed files with 913 additions and 95 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ iOS/testbed/Python.xcframework/ios-*/Python.framework
iOS/testbed/iOSTestbed.xcodeproj/project.xcworkspace
iOS/testbed/iOSTestbed.xcodeproj/xcuserdata
iOS/testbed/iOSTestbed.xcodeproj/xcshareddata
tvOS/Frameworks
tvOS/Resources/Info.plist
watchOS/Frameworks
watchOS/Resources/Info.plist
Mac/Makefile
Mac/PythonLauncher/Info.plist
Mac/PythonLauncher/Makefile
Expand Down
75 changes: 71 additions & 4 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,54 @@ def ios_ver(system="", release="", model="", is_simulator=False):
return IOSVersionInfo(system, release, model, is_simulator)


# A namedtuple for tvOS version information.
TVOSVersionInfo = collections.namedtuple(
"TVOSVersionInfo",
["system", "release", "model", "is_simulator"]
)


def tvos_ver(system="", release="", model="", is_simulator=False):
"""Get tvOS version information, and return it as a namedtuple:
(system, release, model, is_simulator).
If values can't be determined, they are set to values provided as
parameters.
"""
if sys.platform == "tvos":
# TODO: Can the iOS implementation be used here?
import _ios_support
result = _ios_support.get_platform_ios()
if result is not None:
return TVOSVersionInfo(*result)

return TVOSVersionInfo(system, release, model, is_simulator)


# A namedtuple for watchOS version information.
WatchOSVersionInfo = collections.namedtuple(
"WatchOSVersionInfo",
["system", "release", "model", "is_simulator"]
)


def watchos_ver(system="", release="", model="", is_simulator=False):
"""Get watchOS version information, and return it as a namedtuple:
(system, release, model, is_simulator).
If values can't be determined, they are set to values provided as
parameters.
"""
if sys.platform == "watchos":
# TODO: Can the iOS implementation be used here?
import _ios_support
result = _ios_support.get_platform_ios()
if result is not None:
return WatchOSVersionInfo(*result)

return WatchOSVersionInfo(system, release, model, is_simulator)


def _java_getprop(name, default):

from java.lang import System
Expand Down Expand Up @@ -774,14 +822,25 @@ def get_OpenVMS():
csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
return 'Alpha' if cpu_number >= 128 else 'VAX'

# On the iOS simulator, os.uname returns the architecture as uname.machine.
# On device it returns the model name for some reason; but there's only one
# CPU architecture for iOS devices, so we know the right answer.
# On the iOS/tvOS/watchOS simulator, os.uname returns the architecture as
# uname.machine. On device it returns the model name for some reason; but
# there's only one CPU architecture for devices, so we know the right
# answer.
def get_ios():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64'

def get_tvos():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64'

def get_watchos():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64_32'

def from_subprocess():
"""
Fall back to `uname -p`
Expand Down Expand Up @@ -936,9 +995,13 @@ def uname():
system = 'Windows'
release = 'Vista'

# Normalize responses on iOS
# Normalize responses on Apple mobile platforms
if sys.platform == 'ios':
system, release, _, _ = ios_ver()
if sys.platform == 'tvos':
system, release, _, _ = tvos_ver()
if sys.platform == 'watchos':
system, release, _, _ = watchos_ver()

vals = system, node, release, version, machine
# Replace 'unknown' values with the more portable ''
Expand Down Expand Up @@ -1255,6 +1318,10 @@ def platform(aliased=0, terse=0):
# macOS and iOS both report as a "Darwin" kernel
if sys.platform == "ios":
system, release, _, _ = ios_ver()
elif sys.platform == "tvos":
system, release, _, _ = tvos_ver()
elif sys.platform == "watchos":
system, release, _, _ = watchos_ver()
else:
macos_release = mac_ver()[0]
if macos_release:
Expand Down
8 changes: 8 additions & 0 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,14 @@ def get_platform():
release = get_config_vars().get("IPHONEOS_DEPLOYMENT_TARGET", "13.0")
osname = sys.platform
machine = sys.implementation._multiarch
elif sys.platform == "tvos":
release = get_config_vars().get("TVOS_DEPLOYMENT_TARGET", "9.0")
osname = sys.platform
machine = sys.implementation._multiarch
elif sys.platform == "watchos":
release = get_config_vars().get("WATCHOS_DEPLOYMENT_TARGET", "4.0")
osname = sys.platform
machine = sys.implementation._multiarch
else:
import _osx_support
osname, release, machine = _osx_support.get_platform_osx(
Expand Down
Loading

0 comments on commit 087749d

Please sign in to comment.