Skip to content

Commit 0dbdbcd

Browse files
committed
Add support for visionOS.
1 parent eff9d4a commit 0dbdbcd

Some content is hidden

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

44 files changed

+1881
-79
lines changed

.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/xr*-*/bin
86+
visionOS/testbed/Python.xcframework/xr*-*/include
87+
visionOS/testbed/Python.xcframework/xr*-*/lib
88+
visionOS/testbed/Python.xcframework/xr*-*/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
@@ -361,7 +361,7 @@ def __init__(self, name, mode=DEFAULT_MODE, handle=None,
361361
if name:
362362
name = _os.fspath(name)
363363

364-
# If the filename that has been provided is an iOS/tvOS/watchOS
364+
# If the filename that has been provided is an iOS/tvOS/watchOS/visionOS
365365
# .fwork file, dereference the location to the true origin of the
366366
# binary.
367367
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
@@ -297,8 +297,8 @@ def _getuserbase():
297297
if env_base:
298298
return env_base
299299

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

304304
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):
@@ -727,6 +730,10 @@ def get_platform():
727730
release = get_config_vars().get("WATCHOS_DEPLOYMENT_TARGET", "4.0")
728731
osname = sys.platform
729732
machine = sys.implementation._multiarch
733+
elif sys.platform == "visionos":
734+
release = get_config_vars().get("XROS_DEPLOYMENT_TARGET", "2.0")
735+
osname = sys.platform
736+
machine = sys.implementation._multiarch
730737
else:
731738
import _osx_support
732739
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
@@ -7155,9 +7155,9 @@ def test_datetime_from_timestamp(self):
71557155
self.assertEqual(dt_orig, dt_rt)
71567156

71577157
def test_type_check_in_subinterp(self):
7158-
# iOS requires the use of the custom framework loader,
7158+
# Apple mobile platforms require the use of the custom framework loader,
71597159
# not the ExtensionFileLoader.
7160-
if sys.platform == "ios":
7160+
if support.is_apple_mobile:
71617161
extension_loader = "AppleFrameworkLoader"
71627162
else:
71637163
extension_loader = "ExtensionFileLoader"

Lib/test/support/__init__.py

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

554-
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos"}:
554+
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos", "visionos"}:
555555
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
556556
else:
557557
unix_shell = None
@@ -567,7 +567,7 @@ def skip_emscripten_stack_overflow():
567567
def skip_wasi_stack_overflow():
568568
return unittest.skipIf(is_wasi, "Exhausts stack on WASI")
569569

570-
is_apple_mobile = sys.platform in {"ios", "tvos", "watchos"}
570+
is_apple_mobile = sys.platform in {"ios", "tvos", "watchos", "visionos"}
571571
is_apple = is_apple_mobile or sys.platform == "darwin"
572572

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

0 commit comments

Comments
 (0)