changeset: 72011:b5ccdf7c032a user: Victor Stinner date: Sun Aug 21 00:39:18 2011 +0200 files: Lib/ctypes/util.py Lib/distutils/command/build_ext.py Lib/packaging/command/build_ext.py Lib/test/support.py Lib/test/test_fcntl.py Lib/test/test_logging.py Lib/test/test_socket.py setup.py description: Issue #12326: refactor usage of sys.platform * Use str.startswith(tuple): I didn't know this Python feature, Python rocks! * Replace sometimes sys.platform.startswith('linux') with sys.platform == 'linux' * sys.platform doesn't contain the major version on Cygwin on Mac OS X (it's just 'cygwin' and 'darwin') diff -r 95b230772469 -r b5ccdf7c032a Lib/ctypes/util.py --- a/Lib/ctypes/util.py Sun Aug 21 00:16:49 2011 +0200 +++ b/Lib/ctypes/util.py Sun Aug 21 00:39:18 2011 +0200 @@ -142,9 +142,7 @@ return None return res.group(1) - if (sys.platform.startswith("freebsd") - or sys.platform.startswith("openbsd") - or sys.platform.startswith("dragonfly")): + if sys.platform.startswith(("freebsd", "openbsd", "dragonfly")): def _num_version(libname): # "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ] diff -r 95b230772469 -r b5ccdf7c032a Lib/distutils/command/build_ext.py --- a/Lib/distutils/command/build_ext.py Sun Aug 21 00:16:49 2011 +0200 +++ b/Lib/distutils/command/build_ext.py Sun Aug 21 00:39:18 2011 +0200 @@ -240,8 +240,7 @@ # for extensions under Linux or Solaris with a shared Python library, # Python's library directory must be appended to library_dirs sysconfig.get_config_var('Py_ENABLE_SHARED') - if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu') - or sys.platform.startswith('sunos')) + if (sys.platform.startswith(('linux', 'gnu', 'sunos')) and sysconfig.get_config_var('Py_ENABLE_SHARED')): if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): # building third party extensions diff -r 95b230772469 -r b5ccdf7c032a Lib/packaging/command/build_ext.py --- a/Lib/packaging/command/build_ext.py Sun Aug 21 00:16:49 2011 +0200 +++ b/Lib/packaging/command/build_ext.py Sun Aug 21 00:39:18 2011 +0200 @@ -244,8 +244,7 @@ # for extensions under Linux or Solaris with a shared Python library, # Python's library directory must be appended to library_dirs sysconfig.get_config_var('Py_ENABLE_SHARED') - if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu') - or sys.platform.startswith('sunos')) + if (sys.platform.startswith(('linux', 'gnu', 'sunos')) and sysconfig.get_config_var('Py_ENABLE_SHARED')): if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): # building third party extensions diff -r 95b230772469 -r b5ccdf7c032a Lib/test/support.py --- a/Lib/test/support.py Sun Aug 21 00:16:49 2011 +0200 +++ b/Lib/test/support.py Sun Aug 21 00:39:18 2011 +0200 @@ -311,7 +311,7 @@ def decorator(func): @functools.wraps(func) def wrapper(*args, **kw): - if sys.platform.startswith('linux'): + if sys.platform == 'linux': version_txt = platform.release().split('-', 1)[0] try: version = tuple(map(int, version_txt.split('.'))) diff -r 95b230772469 -r b5ccdf7c032a Lib/test/test_fcntl.py --- a/Lib/test/test_fcntl.py Sun Aug 21 00:16:49 2011 +0200 +++ b/Lib/test/test_fcntl.py Sun Aug 21 00:39:18 2011 +0200 @@ -23,9 +23,8 @@ else: start_len = "qq" - if (any(sys.platform.startswith(prefix) - for prefix in ('netbsd', 'freebsd', 'openbsd', 'bsdos')) - or sys.platform in ('Darwin1.2', 'darwin')): + if (sys.platform.startswith(('netbsd', 'freebsd', 'openbsd', 'bsdos')) + or sys.platform == 'darwin'): if struct.calcsize('l') == 8: off_t = 'l' pid_t = 'i' diff -r 95b230772469 -r b5ccdf7c032a Lib/test/test_logging.py --- a/Lib/test/test_logging.py Sun Aug 21 00:16:49 2011 +0200 +++ b/Lib/test/test_logging.py Sun Aug 21 00:39:18 2011 +0200 @@ -527,7 +527,7 @@ def test_builtin_handlers(self): # We can't actually *use* too many handlers in the tests, # but we can try instantiating them with various options - if sys.platform.startswith('linux') or sys.platform == 'darwin': + if sys.platform in ('linux', 'darwin'): for existing in (True, False): fd, fn = tempfile.mkstemp() os.close(fd) diff -r 95b230772469 -r b5ccdf7c032a Lib/test/test_socket.py --- a/Lib/test/test_socket.py Sun Aug 21 00:16:49 2011 +0200 +++ b/Lib/test/test_socket.py Sun Aug 21 00:39:18 2011 +0200 @@ -442,10 +442,8 @@ # Find one service that exists, then check all the related interfaces. # I've ordered this by protocols that have both a tcp and udp # protocol, at least for modern Linuxes. - if (sys.platform.startswith('linux') or - sys.platform.startswith('freebsd') or - sys.platform.startswith('netbsd') or - sys.platform == 'darwin'): + if (sys.platform.startswith(('freebsd', 'netbsd')) + or sys.platform in ('linux', 'darwin')): # avoid the 'echo' service on this platform, as there is an # assumption breaking non-standard port/protocol entry services = ('daytime', 'qotd', 'domain') @@ -2074,7 +2072,7 @@ ]) if hasattr(socket, "socketpair"): tests.append(BasicSocketPairTest) - if sys.platform.startswith('linux'): + if sys.platform == 'linux': tests.append(TestLinuxAbstractNamespace) if isTipcAvailable(): tests.append(TIPCTest) diff -r 95b230772469 -r b5ccdf7c032a setup.py --- a/setup.py Sun Aug 21 00:16:49 2011 +0200 +++ b/setup.py Sun Aug 21 00:39:18 2011 +0200 @@ -363,9 +363,8 @@ def get_platform(self): # Get value of sys.platform - for platform in ['cygwin', 'darwin', 'osf1']: - if sys.platform.startswith(platform): - return platform + if sys.platform.startswith('osf1'): + return 'osf1' return sys.platform def add_multiarch_paths(self):