Skip to content

Commit 50c666f

Browse files
committed
Add support for visionOS.
1 parent 5b390b9 commit 50c666f

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
@@ -70,6 +70,7 @@ Lib/test/data/*
7070
/Makefile
7171
/Makefile.pre
7272
/iOSTestbed.*
73+
/visionOSTestbed.*
7374
iOS/Frameworks/
7475
iOS/Resources/Info.plist
7576
iOS/testbed/build
@@ -80,10 +81,19 @@ iOS/testbed/Python.xcframework/ios-*/Python.framework
8081
iOS/testbed/iOSTestbed.xcodeproj/project.xcworkspace
8182
iOS/testbed/iOSTestbed.xcodeproj/xcuserdata
8283
iOS/testbed/iOSTestbed.xcodeproj/xcshareddata
84+
visionOS/testbed/Python.xcframework/xr*-*/bin
85+
visionOS/testbed/Python.xcframework/xr*-*/include
86+
visionOS/testbed/Python.xcframework/xr*-*/lib
87+
visionOS/testbed/Python.xcframework/xr*-*/Python.framework
88+
visionOS/testbed/visionOSTestbed.xcodeproj/project.xcworkspace
89+
visionOS/testbed/visionOSTestbed.xcodeproj/xcuserdata
90+
visionOS/testbed/visionOSTestbed.xcodeproj/xcshareddata
8391
tvOS/Frameworks
8492
tvOS/Resources/Info.plist
8593
watchOS/Frameworks
8694
watchOS/Resources/Info.plist
95+
visionOS/Frameworks
96+
visionOS/Resources/Info.plist
8797
Mac/Makefile
8898
Mac/PythonLauncher/Info.plist
8999
Mac/PythonLauncher/Makefile

Lib/ctypes/__init__.py

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

362-
# If the filename that has been provided is an iOS/tvOS/watchOS
362+
# If the filename that has been provided is an iOS/tvOS/watchOS/visionOS
363363
# .fwork file, dereference the location to the true origin of the
364364
# binary.
365365
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
@@ -569,6 +569,30 @@ def watchos_ver(system="", release="", model="", is_simulator=False):
569569
return WatchOSVersionInfo(system, release, model, is_simulator)
570570

571571

572+
# A namedtuple for visionOS version information.
573+
VisionOSVersionInfo = collections.namedtuple(
574+
"VisionOSVersionInfo",
575+
["system", "release", "model", "is_simulator"]
576+
)
577+
578+
579+
def visionos_ver(system="", release="", model="", is_simulator=False):
580+
"""Get visionOS version information, and return it as a namedtuple:
581+
(system, release, model, is_simulator).
582+
583+
If values can't be determined, they are set to values provided as
584+
parameters.
585+
"""
586+
if sys.platform == "visionos":
587+
# TODO: Can the iOS implementation be used here?
588+
import _ios_support
589+
result = _ios_support.get_platform_ios()
590+
if result is not None:
591+
return VisionOSVersionInfo(*result)
592+
593+
return VisionOSVersionInfo(system, release, model, is_simulator)
594+
595+
572596
def _java_getprop(name, default):
573597
"""This private helper is deprecated in 3.13 and will be removed in 3.15"""
574598
from java.lang import System
@@ -768,7 +792,7 @@ def _syscmd_file(target, default=''):
768792
default in case the command should fail.
769793
770794
"""
771-
if sys.platform in {'dos', 'win32', 'win16', 'ios', 'tvos', 'watchos'}:
795+
if sys.platform in {'dos', 'win32', 'win16', 'ios', 'tvos', 'watchos', 'visionos'}:
772796
# XXX Others too ?
773797
return default
774798

@@ -932,7 +956,7 @@ def get_OpenVMS():
932956
csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
933957
return 'Alpha' if cpu_number >= 128 else 'VAX'
934958

935-
# On the iOS/tvOS/watchOS simulator, os.uname returns the architecture as
959+
# On the iOS/tvOS/watchOS/visionOS simulator, os.uname returns the architecture as
936960
# uname.machine. On device it returns the model name for some reason; but
937961
# there's only one CPU architecture for devices, so we know the right
938962
# answer.
@@ -951,6 +975,11 @@ def get_watchos():
951975
return os.uname().machine
952976
return 'arm64_32'
953977

978+
def get_visionos():
979+
if sys.implementation._multiarch.endswith("simulator"):
980+
return os.uname().machine
981+
return 'arm64'
982+
954983
def from_subprocess():
955984
"""
956985
Fall back to `uname -p`
@@ -1117,6 +1146,8 @@ def uname():
11171146
system, release, _, _ = tvos_ver()
11181147
if sys.platform == 'watchos':
11191148
system, release, _, _ = watchos_ver()
1149+
if sys.platform == 'visionos':
1150+
system, release, _, _ = visionos_ver()
11201151

11211152
vals = system, node, release, version, machine
11221153
# Replace 'unknown' values with the more portable ''
@@ -1410,6 +1441,8 @@ def platform(aliased=False, terse=False):
14101441
system, release, _, _ = tvos_ver()
14111442
elif sys.platform == "watchos":
14121443
system, release, _, _ = watchos_ver()
1444+
elif sys.platform == "visionos":
1445+
system, release, _, _ = visionos_ver()
14131446
else:
14141447
macos_release = mac_ver()[0]
14151448
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
@@ -7141,9 +7141,9 @@ def test_datetime_from_timestamp(self):
71417141
self.assertEqual(dt_orig, dt_rt)
71427142

71437143
def test_type_check_in_subinterp(self):
7144-
# iOS requires the use of the custom framework loader,
7144+
# Apple mobile platforms require the use of the custom framework loader,
71457145
# not the ExtensionFileLoader.
7146-
if sys.platform == "ios":
7146+
if support.is_apple_mobile:
71477147
extension_loader = "AppleFrameworkLoader"
71487148
else:
71497149
extension_loader = "ExtensionFileLoader"

Lib/test/support/__init__.py

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

547-
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos"}:
547+
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos", "visionos"}:
548548
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
549549
else:
550550
unix_shell = None
@@ -560,7 +560,7 @@ def skip_emscripten_stack_overflow():
560560
def skip_wasi_stack_overflow():
561561
return unittest.skipIf(is_wasi, "Exhausts stack on WASI")
562562

563-
is_apple_mobile = sys.platform in {"ios", "tvos", "watchos"}
563+
is_apple_mobile = sys.platform in {"ios", "tvos", "watchos", "visionos"}
564564
is_apple = is_apple_mobile or sys.platform == "darwin"
565565

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

0 commit comments

Comments
 (0)