Skip to content

Commit 68b83a6

Browse files
committed
Add support for visionOS.
1 parent 6a5d3e9 commit 68b83a6

45 files changed

Lines changed: 1888 additions & 78 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Lib/test/data/*
7171
/Makefile
7272
/Makefile.pre
7373
/iOSTestbed.*
74+
/visionOSTestbed.*
7475
iOS/Frameworks/
7576
iOS/Resources/Info.plist
7677
iOS/testbed/build
@@ -81,10 +82,19 @@ iOS/testbed/Python.xcframework/ios-*/Python.framework
8182
iOS/testbed/iOSTestbed.xcodeproj/project.xcworkspace
8283
iOS/testbed/iOSTestbed.xcodeproj/xcuserdata
8384
iOS/testbed/iOSTestbed.xcodeproj/xcshareddata
85+
visionOS/testbed/Python.xcframework/xros-*/bin
86+
visionOS/testbed/Python.xcframework/xros-*/include
87+
visionOS/testbed/Python.xcframework/xros-*/lib
88+
visionOS/testbed/Python.xcframework/xros-*/Python.framework
89+
visionOS/testbed/visionOSTestbed.xcodeproj/project.xcworkspace
90+
visionOS/testbed/visionOSTestbed.xcodeproj/xcuserdata
91+
visionOS/testbed/visionOSTestbed.xcodeproj/xcshareddata
8492
tvOS/Frameworks
8593
tvOS/Resources/Info.plist
8694
watchOS/Frameworks
8795
watchOS/Resources/Info.plist
96+
visionOS/Frameworks
97+
visionOS/Resources/Info.plist
8898
Mac/Makefile
8999
Mac/PythonLauncher/Info.plist
90100
Mac/PythonLauncher/Makefile

Lib/ctypes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def __init__(self, name, mode=DEFAULT_MODE, handle=None,
419419
if name:
420420
name = _os.fspath(name)
421421

422-
# If the filename that has been provided is an iOS/tvOS/watchOS
422+
# If the filename that has been provided is an iOS/tvOS/watchOS/visionOS
423423
# .fwork file, dereference the location to the true origin of the
424424
# binary.
425425
if name.endswith(".fwork"):

Lib/ctypes/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def dllist():
126126
if (name := _get_module_filename(h)) is not None]
127127
return libraries
128128

129-
elif os.name == "posix" and sys.platform in {"darwin", "ios", "tvos", "watchos"}:
129+
elif os.name == "posix" and sys.platform in {"darwin", "ios", "tvos", "watchos", "visionos"}:
130130
from ctypes.macholib.dyld import dyld_find as _dyld_find
131131
def find_library(name):
132132
possible = ['lib%s.dylib' % name,
@@ -425,7 +425,7 @@ def find_library(name):
425425
# https://man.openbsd.org/dl_iterate_phdr
426426
# https://docs.oracle.com/cd/E88353_01/html/E37843/dl-iterate-phdr-3c.html
427427
if (os.name == "posix" and
428-
sys.platform not in {"darwin", "ios", "tvos", "watchos"}):
428+
sys.platform not in {"darwin", "ios", "tvos", "watchos", "visionos"}):
429429
import ctypes
430430
if hasattr((_libc := ctypes.CDLL(None)), "dl_iterate_phdr"):
431431

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
# Bootstrap-related code ######################################################
5454
_CASE_INSENSITIVE_PLATFORMS_STR_KEY = 'win',
55-
_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY = 'cygwin', 'darwin', 'ios', 'tvos', 'watchos'
55+
_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY = 'cygwin', 'darwin', 'ios', 'tvos', 'watchos', 'visionos'
5656
_CASE_INSENSITIVE_PLATFORMS = (_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY
5757
+ _CASE_INSENSITIVE_PLATFORMS_STR_KEY)
5858

@@ -1535,7 +1535,7 @@ def _get_supported_file_loaders():
15351535
"""
15361536
extension_loaders = []
15371537
if hasattr(_imp, 'create_dynamic'):
1538-
if sys.platform in {"ios", "tvos", "watchos"}:
1538+
if sys.platform in {"ios", "tvos", "watchos", "visionos"}:
15391539
extension_loaders = [(AppleFrameworkLoader, [
15401540
suffix.replace(".so", ".fwork")
15411541
for suffix in _imp.extension_suffixes()

Lib/platform.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,30 @@ def watchos_ver(system="", release="", model="", is_simulator=False):
576576
return WatchOSVersionInfo(system, release, model, is_simulator)
577577

578578

579+
# A namedtuple for visionOS version information.
580+
VisionOSVersionInfo = collections.namedtuple(
581+
"VisionOSVersionInfo",
582+
["system", "release", "model", "is_simulator"]
583+
)
584+
585+
586+
def visionos_ver(system="", release="", model="", is_simulator=False):
587+
"""Get visionOS version information, and return it as a namedtuple:
588+
(system, release, model, is_simulator).
589+
590+
If values can't be determined, they are set to values provided as
591+
parameters.
592+
"""
593+
if sys.platform == "visionos":
594+
# TODO: Can the iOS implementation be used here?
595+
import _ios_support
596+
result = _ios_support.get_platform_ios()
597+
if result is not None:
598+
return VisionOSVersionInfo(*result)
599+
600+
return VisionOSVersionInfo(system, release, model, is_simulator)
601+
602+
579603
def _java_getprop(name, default):
580604
"""This private helper is deprecated in 3.13 and will be removed in 3.15"""
581605
from java.lang import System
@@ -775,7 +799,7 @@ def _syscmd_file(target, default=''):
775799
default in case the command should fail.
776800
777801
"""
778-
if sys.platform in {'dos', 'win32', 'win16', 'ios', 'tvos', 'watchos'}:
802+
if sys.platform in {'dos', 'win32', 'win16', 'ios', 'tvos', 'watchos', 'visionos'}:
779803
# XXX Others too ?
780804
return default
781805

@@ -939,7 +963,7 @@ def get_OpenVMS():
939963
csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
940964
return 'Alpha' if cpu_number >= 128 else 'VAX'
941965

942-
# On the iOS/tvOS/watchOS simulator, os.uname returns the architecture as
966+
# On the iOS/tvOS/watchOS/visionOS simulator, os.uname returns the architecture as
943967
# uname.machine. On device it returns the model name for some reason; but
944968
# there's only one CPU architecture for devices, so we know the right
945969
# answer.
@@ -958,6 +982,11 @@ def get_watchos():
958982
return os.uname().machine
959983
return 'arm64_32'
960984

985+
def get_visionos():
986+
if sys.implementation._multiarch.endswith("simulator"):
987+
return os.uname().machine
988+
return 'arm64'
989+
961990
def from_subprocess():
962991
"""
963992
Fall back to `uname -p`
@@ -1124,6 +1153,8 @@ def uname():
11241153
system, release, _, _ = tvos_ver()
11251154
if sys.platform == 'watchos':
11261155
system, release, _, _ = watchos_ver()
1156+
if sys.platform == 'visionos':
1157+
system, release, _, _ = visionos_ver()
11271158

11281159
vals = system, node, release, version, machine
11291160
# Replace 'unknown' values with the more portable ''
@@ -1417,6 +1448,8 @@ def platform(aliased=False, terse=False):
14171448
system, release, _, _ = tvos_ver()
14181449
elif sys.platform == "watchos":
14191450
system, release, _, _ = watchos_ver()
1451+
elif sys.platform == "visionos":
1452+
system, release, _, _ = visionos_ver()
14201453
else:
14211454
macos_release = mac_ver()[0]
14221455
if macos_release:

Lib/site.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ def _getuserbase():
298298
if env_base:
299299
return env_base
300300

301-
# Emscripten, iOS, tvOS, VxWorks, WASI, and watchOS have no home directories
302-
if sys.platform in {"emscripten", "ios", "tvos", "vxworks", "wasi", "watchos"}:
301+
# Emscripten, iOS, tvOS, visionOS, VxWorks, WASI, and watchOS have no home directories
302+
if sys.platform in {"emscripten", "ios", "tvos", "vxworks", "visionos", "wasi", "watchos"}:
303303
return None
304304

305305
def joinuser(*args):

Lib/subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
_mswindows = True
7676

7777
# some platforms do not support subprocesses
78-
_can_fork_exec = sys.platform not in {"emscripten", "wasi", "ios", "tvos", "watchos"}
78+
_can_fork_exec = sys.platform not in {"emscripten", "wasi", "ios", "tvos", "watchos", "visionos"}
7979

8080
if _mswindows:
8181
import _winapi

Lib/sysconfig/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
_ALWAYS_STR = {
2424
'IPHONEOS_DEPLOYMENT_TARGET',
2525
'MACOSX_DEPLOYMENT_TARGET',
26+
'TVOS_DEPLOYMENT_TARGET',
27+
'WATCHOS_DEPLOYMENT_TARGET',
28+
'XROS_DEPLOYMENT_TARGET',
2629
}
2730

2831
_INSTALL_SCHEMES = {
@@ -119,7 +122,7 @@ def _getuserbase():
119122
# Emscripten, iOS, tvOS, VxWorks, WASI, and watchOS have no home directories.
120123
# Use _PYTHON_HOST_PLATFORM to get the correct platform when cross-compiling.
121124
system_name = os.environ.get('_PYTHON_HOST_PLATFORM', sys.platform).split('-')[0]
122-
if system_name in {"emscripten", "ios", "tvos", "vxworks", "wasi", "watchos"}:
125+
if system_name in {"emscripten", "ios", "tvos", "visionos", "vxworks", "wasi", "watchos"}:
123126
return None
124127

125128
def joinuser(*args):
@@ -738,6 +741,10 @@ def get_platform():
738741
release = get_config_vars().get("WATCHOS_DEPLOYMENT_TARGET", "4.0")
739742
osname = sys.platform
740743
machine = sys.implementation._multiarch
744+
elif sys.platform == "visionos":
745+
release = get_config_vars().get("XROS_DEPLOYMENT_TARGET", "2.0")
746+
osname = sys.platform
747+
machine = sys.implementation._multiarch
741748
else:
742749
import _osx_support
743750
osname, release, machine = _osx_support.get_platform_osx(

Lib/test/datetimetester.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7159,9 +7159,9 @@ def test_datetime_from_timestamp(self):
71597159
self.assertEqual(dt_orig, dt_rt)
71607160

71617161
def test_type_check_in_subinterp(self):
7162-
# iOS requires the use of the custom framework loader,
7162+
# Apple mobile platforms require the use of the custom framework loader,
71637163
# not the ExtensionFileLoader.
7164-
if sys.platform == "ios":
7164+
if support.is_apple_mobile:
71657165
extension_loader = "AppleFrameworkLoader"
71667166
else:
71677167
extension_loader = "ExtensionFileLoader"

Lib/test/support/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def skip_android_selinux(name):
558558
sys.platform == "android", f"Android blocks {name} with SELinux"
559559
)
560560

561-
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos"}:
561+
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos", "visionos"}:
562562
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
563563
else:
564564
unix_shell = None
@@ -574,7 +574,7 @@ def skip_emscripten_stack_overflow():
574574
def skip_wasi_stack_overflow():
575575
return unittest.skipIf(is_wasi, "Exhausts stack on WASI")
576576

577-
is_apple_mobile = sys.platform in {"ios", "tvos", "watchos"}
577+
is_apple_mobile = sys.platform in {"ios", "tvos", "watchos", "visionos"}
578578
is_apple = is_apple_mobile or sys.platform == "darwin"
579579

580580
has_fork_support = hasattr(os, "fork") and not (

0 commit comments

Comments
 (0)