-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-33671: Add support.MS_WINDOWS and support.MACOS #7800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4011a37
eae443a
dd57c47
3c1bc21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,8 +90,8 @@ | |
"anticipate_failure", "load_package_tests", "detect_api_mismatch", | ||
"check__all__", "skip_unless_bind_unix_socket", | ||
# sys | ||
"is_jython", "is_android", "check_impl_detail", "unix_shell", | ||
"setswitchinterval", | ||
"JYTHON", "ANDROID", "check_impl_detail", "unix_shell", | ||
"setswitchinterval", "MS_WINDOWS", "MACOS", | ||
# network | ||
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource", | ||
"bind_unix_socket", | ||
|
@@ -108,6 +108,21 @@ | |
"run_with_tz", "PGO", "missing_compiler_executable", "fd_count", | ||
] | ||
|
||
|
||
# True if Python is running on Microsoft Windows. | ||
MS_WINDOWS = (sys.platform == 'win32') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't be better to use Or rename the latter two? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replied here: #7800 (comment) If we do something, I would prefer to rename is_android and is_jython to ANDROID and JYTHON to be more consistent with PEP 8 and existing code (rather than adding support.is_windows and support.is_macos). |
||
|
||
# True if Python is running on Apple macOS. | ||
MACOS = (sys.platform == 'darwin') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise here: MACOS = sys.platform.startswith("darwin")
sys.platform == 'darwin' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't see the purpose of this test. sys.platform is always the "darwin" string on macOS, no? |
||
|
||
# True if Python runs on Jython | ||
# (Python implemented in Java running in a Java VM) | ||
JYTHON = sys.platform.startswith('java') | ||
|
||
# True if Python runs on Android | ||
ANDROID = hasattr(sys, 'getandroidapilevel') | ||
|
||
|
||
class Error(Exception): | ||
"""Base class for regression test exceptions.""" | ||
|
||
|
@@ -484,7 +499,7 @@ class USEROBJECTFLAGS(ctypes.Structure): | |
raise ctypes.WinError() | ||
if not bool(uof.dwFlags & WSF_VISIBLE): | ||
reason = "gui not available (WSF_VISIBLE flag not set)" | ||
elif sys.platform == 'darwin': | ||
elif MACOS: | ||
# The Aqua Tk implementations on OS X can abort the process if | ||
# being called in an environment where a window server connection | ||
# cannot be made, for instance when invoked by a buildbot or ssh | ||
|
@@ -600,7 +615,7 @@ def requires_mac_ver(*min_version): | |
def decorator(func): | ||
@functools.wraps(func) | ||
def wrapper(*args, **kw): | ||
if sys.platform == 'darwin': | ||
if MACOS: | ||
version_txt = platform.mac_ver()[0] | ||
try: | ||
version = tuple(map(int, version_txt.split('.'))) | ||
|
@@ -788,14 +803,12 @@ def dec(*args, **kwargs): | |
|
||
requires_lzma = unittest.skipUnless(lzma, 'requires lzma') | ||
|
||
is_jython = sys.platform.startswith('java') | ||
|
||
is_android = hasattr(sys, 'getandroidapilevel') | ||
|
||
if sys.platform != 'win32': | ||
unix_shell = '/system/bin/sh' if is_android else '/bin/sh' | ||
else: | ||
if MS_WINDOWS: | ||
unix_shell = None | ||
elif ANDROID: | ||
unix_shell = '/system/bin/sh' | ||
else: | ||
unix_shell = '/bin/sh' | ||
|
||
# Filename used for testing | ||
if os.name == 'java': | ||
|
@@ -854,7 +867,7 @@ def dec(*args, **kwargs): | |
|
||
# TESTFN_UNICODE is a non-ascii filename | ||
TESTFN_UNICODE = TESTFN + "-\xe0\xf2\u0258\u0141\u011f" | ||
if sys.platform == 'darwin': | ||
if MACOS: | ||
# In Mac OS X's VFS API file names are, by definition, canonically | ||
# decomposed Unicode, encoded using UTF-8. See QA1173: | ||
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html | ||
|
@@ -866,7 +879,7 @@ def dec(*args, **kwargs): | |
# encoded by the filesystem encoding (in strict mode). It can be None if we | ||
# cannot generate such filename. | ||
TESTFN_UNENCODABLE = None | ||
if os.name == 'nt': | ||
if MS_WINDOWS: | ||
# skip win32s (0) or Windows 9x/ME (1) | ||
if sys.getwindowsversion().platform >= 2: | ||
# Different kinds of characters from various languages to minimize the | ||
|
@@ -881,8 +894,8 @@ def dec(*args, **kwargs): | |
'Unicode filename tests may not be effective' | ||
% (TESTFN_UNENCODABLE, TESTFN_ENCODING)) | ||
TESTFN_UNENCODABLE = None | ||
# Mac OS X denies unencodable filenames (invalid utf-8) | ||
elif sys.platform != 'darwin': | ||
# macOS denies unencodable filenames (invalid utf-8) | ||
elif not MACOS: | ||
try: | ||
# ascii and utf-8 cannot encode the byte 0xff | ||
b'\xff'.decode(TESTFN_ENCODING) | ||
|
@@ -1523,7 +1536,7 @@ def gc_collect(): | |
objects to disappear. | ||
""" | ||
gc.collect() | ||
if is_jython: | ||
if JYTHON: | ||
time.sleep(0.1) | ||
gc.collect() | ||
gc.collect() | ||
|
@@ -1982,7 +1995,7 @@ def _check_docstrings(): | |
"""Just used to check if docstrings are enabled""" | ||
|
||
MISSING_C_DOCSTRINGS = (check_impl_detail() and | ||
sys.platform != 'win32' and | ||
not MS_WINDOWS and | ||
not sysconfig.get_config_var('WITH_DOC_STRINGS')) | ||
|
||
HAVE_DOCSTRINGS = (_check_docstrings.__doc__ is not None and | ||
|
@@ -2592,7 +2605,7 @@ def __enter__(self): | |
except (ValueError, OSError): | ||
pass | ||
|
||
if sys.platform == 'darwin': | ||
if MACOS: | ||
# Check if the 'Crash Reporter' on OSX was configured | ||
# in 'Developer' mode and warn that it will get triggered | ||
# when it is. | ||
|
@@ -2736,7 +2749,7 @@ def setswitchinterval(interval): | |
# Setting a very low gil interval on the Android emulator causes python | ||
# to hang (issue #26939). | ||
minimum_interval = 1e-5 | ||
if is_android and interval < minimum_interval: | ||
if ANDROID and interval < minimum_interval: | ||
global _is_android_emulator | ||
if _is_android_emulator is None: | ||
_is_android_emulator = (subprocess.check_output( | ||
|
@@ -2782,7 +2795,7 @@ def fd_count(): | |
pass | ||
|
||
old_modes = None | ||
if sys.platform == 'win32': | ||
if MS_WINDOWS: | ||
# bpo-25306, bpo-31009: Call CrtSetReportMode() to not kill the process | ||
# on invalid file descriptor if Python is compiled in debug mode | ||
try: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we happy this is suitable for replacing all of the following without changing behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On "win64", Python uses "win32" as well.
I'm not sure about Cygwin which is a strange beast.