[Python-checkins] cpython: - Issue #3754, refactor sys.platform / get_platform bits, use a

matthias.klose python-checkins at python.org
Sat Jun 30 14:33:35 CEST 2012


http://hg.python.org/cpython/rev/56c574a1819a
changeset:   77867:56c574a1819a
user:        doko at ubuntu.com
date:        Sat Jun 30 14:32:08 2012 +0200
summary:
  - Issue #3754, refactor sys.platform / get_platform bits, use a
  global host_platform instead.

files:
  setup.py |  123 ++++++++++++++++++++----------------------
  1 files changed, 59 insertions(+), 64 deletions(-)


diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -15,6 +15,13 @@
 from distutils.command.build_scripts import build_scripts
 from distutils.spawn import find_executable
 
+def get_platform():
+    # Get value of sys.platform
+    if sys.platform.startswith('osf1'):
+        return 'osf1'
+    return sys.platform
+host_platform = get_platform()
+
 # Were we compiled --with-pydebug or with #define Py_DEBUG?
 COMPILED_WITH_PYDEBUG = hasattr(sys, 'gettotalrefcount')
 
@@ -70,7 +77,7 @@
     'paths' is a list of additional locations to check; if the file is
         found in one of them, the resulting list will contain the directory.
     """
-    if sys.platform == 'darwin':
+    if host_platform == 'darwin':
         # Honor the MacOSX SDK setting when one was specified.
         # An SDK is a directory with the same structure as a real
         # system, but with only header files and libraries.
@@ -80,7 +87,7 @@
     for dir in std_dirs:
         f = os.path.join(dir, filename)
 
-        if sys.platform == 'darwin' and is_macosx_sdk_path(dir):
+        if host_platform == 'darwin' and is_macosx_sdk_path(dir):
             f = os.path.join(sysroot, dir[1:], filename)
 
         if os.path.exists(f): return []
@@ -89,7 +96,7 @@
     for dir in paths:
         f = os.path.join(dir, filename)
 
-        if sys.platform == 'darwin' and is_macosx_sdk_path(dir):
+        if host_platform == 'darwin' and is_macosx_sdk_path(dir):
             f = os.path.join(sysroot, dir[1:], filename)
 
         if os.path.exists(f):
@@ -103,7 +110,7 @@
     if result is None:
         return None
 
-    if sys.platform == 'darwin':
+    if host_platform == 'darwin':
         sysroot = macosx_sdk_root()
 
     # Check whether the found file is in one of the standard directories
@@ -112,7 +119,7 @@
         # Ensure path doesn't end with path separator
         p = p.rstrip(os.sep)
 
-        if sys.platform == 'darwin' and is_macosx_sdk_path(p):
+        if host_platform == 'darwin' and is_macosx_sdk_path(p):
             if os.path.join(sysroot, p[1:]) == dirname:
                 return [ ]
 
@@ -125,7 +132,7 @@
         # Ensure path doesn't end with path separator
         p = p.rstrip(os.sep)
 
-        if sys.platform == 'darwin' and is_macosx_sdk_path(p):
+        if host_platform == 'darwin' and is_macosx_sdk_path(p):
             if os.path.join(sysroot, p[1:]) == dirname:
                 return [ p ]
 
@@ -186,9 +193,6 @@
         srcdir = os.path.abspath(srcdir)
         moddirlist = [os.path.join(srcdir, 'Modules')]
 
-        # Platform-dependent module source and include directories
-        platform = self.get_platform()
-
         # Fix up the paths for scripts, too
         self.distribution.scripts = [os.path.join(srcdir, filename)
                                      for filename in self.distribution.scripts]
@@ -303,7 +307,7 @@
                 ext.name)
             return
 
-        if self.get_platform() == 'darwin' and (
+        if host_platform == 'darwin' and (
                 sys.maxsize > 2**32 and '-arch' in ext.extra_link_args):
             # Don't bother doing an import check when an extension was
             # build with an explicit '-arch' flag on OSX. That's currently
@@ -317,7 +321,7 @@
 
         # Workaround for Cygwin: Cygwin currently has fork issues when many
         # modules have been imported
-        if self.get_platform() == 'cygwin':
+        if host_platform == 'cygwin':
             self.announce('WARNING: skipping import check for Cygwin-based "%s"'
                 % ext.name)
             return
@@ -361,12 +365,6 @@
                           level=3)
             self.failed.append(ext.name)
 
-    def get_platform(self):
-        # Get value of sys.platform
-        if sys.platform.startswith('osf1'):
-            return 'osf1'
-        return sys.platform
-
     def add_multiarch_paths(self):
         # Debian/Ubuntu multiarch support.
         # https://wiki.ubuntu.com/MultiarchSpec
@@ -457,18 +455,17 @@
         with open(config_h) as file:
             config_h_vars = sysconfig.parse_config_h(file)
 
-        platform = self.get_platform()
         srcdir = sysconfig.get_config_var('srcdir')
 
         # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
-        if platform in ['osf1', 'unixware7', 'openunix8']:
+        if host_platform in ['osf1', 'unixware7', 'openunix8']:
             lib_dirs += ['/usr/ccs/lib']
 
         # HP-UX11iv3 keeps files in lib/hpux folders.
-        if platform == 'hp-ux11':
+        if host_platform == 'hp-ux11':
             lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']
 
-        if platform == 'darwin':
+        if host_platform == 'darwin':
             # This should work on any unixy platform ;-)
             # If the user has bothered specifying additional -I and -L flags
             # in OPT and LDFLAGS we might as well use them here.
@@ -488,7 +485,7 @@
 
         # Check for MacOS X, which doesn't need libm.a at all
         math_libs = ['m']
-        if platform == 'darwin':
+        if host_platform == 'darwin':
             math_libs = []
 
         # XXX Omitted modules: gl, pure, dl, SGI-specific modules
@@ -624,7 +621,7 @@
         elif self.compiler.find_library_file(lib_dirs, 'curses'):
             curses_library = 'curses'
 
-        if platform == 'darwin':
+        if host_platform == 'darwin':
             os_release = int(os.uname()[2].split('.')[0])
             dep_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
             if dep_target and dep_target.split('.') < ['10', '5']:
@@ -636,7 +633,7 @@
                 if find_file('readline/rlconf.h', inc_dirs, []) is None:
                     do_readline = False
         if do_readline:
-            if platform == 'darwin' and os_release < 9:
+            if host_platform == 'darwin' and os_release < 9:
                 # In every directory on the search path search for a dynamic
                 # library and then a static library, instead of first looking
                 # for dynamic libraries on the entire path.
@@ -717,7 +714,7 @@
                 inc_dirs + search_for_ssl_incs_in)
         if opensslv_h:
             name = os.path.join(opensslv_h[0], 'openssl/opensslv.h')
-            if sys.platform == 'darwin' and is_macosx_sdk_path(name):
+            if host_platform == 'darwin' and is_macosx_sdk_path(name):
                 name = os.path.join(macosx_sdk_root(), name[1:])
             try:
                 with open(name, 'r') as incfile:
@@ -853,7 +850,7 @@
 
         db_ver_inc_map = {}
 
-        if sys.platform == 'darwin':
+        if host_platform == 'darwin':
             sysroot = macosx_sdk_root()
 
         class db_found(Exception): pass
@@ -862,7 +859,7 @@
             # search path.
             for d in inc_dirs + db_inc_paths:
                 f = os.path.join(d, "db.h")
-                if sys.platform == 'darwin' and is_macosx_sdk_path(d):
+                if host_platform == 'darwin' and is_macosx_sdk_path(d):
                     f = os.path.join(sysroot, d[1:], "db.h")
 
                 if db_setup_debug: print("db: looking for db.h in", f)
@@ -913,7 +910,7 @@
                     db_incdir.replace("include", 'lib'),
                 ]
 
-                if sys.platform != 'darwin':
+                if host_platform != 'darwin':
                     db_dirs_to_check = list(filter(os.path.isdir, db_dirs_to_check))
 
                 else:
@@ -977,13 +974,13 @@
         # Scan the default include directories before the SQLite specific
         # ones. This allows one to override the copy of sqlite on OSX,
         # where /usr/include contains an old version of sqlite.
-        if sys.platform == 'darwin':
+        if host_platform == 'darwin':
             sysroot = macosx_sdk_root()
 
         for d in inc_dirs + sqlite_inc_paths:
             f = os.path.join(d, "sqlite3.h")
 
-            if sys.platform == 'darwin' and is_macosx_sdk_path(d):
+            if host_platform == 'darwin' and is_macosx_sdk_path(d):
                 f = os.path.join(sysroot, d[1:], "sqlite3.h")
 
             if os.path.exists(f):
@@ -1033,7 +1030,7 @@
                 '_sqlite/util.c', ]
 
             sqlite_defines = []
-            if sys.platform != "win32":
+            if host_platform != "win32":
                 sqlite_defines.append(('MODULE_NAME', '"sqlite3"'))
             else:
                 sqlite_defines.append(('MODULE_NAME', '\\"sqlite3\\"'))
@@ -1043,7 +1040,7 @@
             if '--enable-loadable-sqlite-extensions' not in sysconfig.get_config_var("CONFIG_ARGS"):
                 sqlite_defines.append(("SQLITE_OMIT_LOAD_EXTENSION", "1"))
 
-            if sys.platform == 'darwin':
+            if host_platform == 'darwin':
                 # In every directory on the search path search for a dynamic
                 # library and then a static library, instead of first looking
                 # for dynamic libraries on the entire path.
@@ -1072,7 +1069,7 @@
         dbm_setup_debug = False   # verbose debug prints from this script?
         dbm_order = ['gdbm']
         # The standard Unix dbm module:
-        if platform not in ['cygwin']:
+        if host_platform not in ['cygwin']:
             config_args = [arg.strip("'")
                            for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
             dbm_args = [arg for arg in config_args
@@ -1154,14 +1151,14 @@
             missing.append('_gdbm')
 
         # Unix-only modules
-        if platform != 'win32':
+        if host_platform != 'win32':
             # Steen Lumholt's termios module
             exts.append( Extension('termios', ['termios.c']) )
             # Jeremy Hylton's rlimit interface
             exts.append( Extension('resource', ['resource.c']) )
 
             # Sun yellow pages. Some systems have the functions in libc.
-            if (platform not in ['cygwin', 'qnx6'] and
+            if (host_platform not in ['cygwin', 'qnx6'] and
                 find_file('rpcsvc/yp_prot.h', inc_dirs, []) is not None):
                 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
                     libs = ['nsl']
@@ -1185,7 +1182,7 @@
             # Bug 1464056: If _curses.so links with ncursesw,
             # _curses_panel.so must link with panelw.
             panel_library = 'panelw'
-            if platform == 'darwin':
+            if host_platform == 'darwin':
                 # On OS X, there is no separate /usr/lib/libncursesw nor
                 # libpanelw.  If we are here, we found a locally-supplied
                 # version of libncursesw.  There should be also be a
@@ -1193,7 +1190,7 @@
                 # for OS X but we need _XOPEN_SOURCE_EXTENDED here for
                 # ncurses wide char support
                 curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
-        elif platform == 'darwin' and curses_library == 'ncurses':
+        elif host_platform == 'darwin' and curses_library == 'ncurses':
             # Building with the system-suppied combined libncurses/libpanel
             curses_defines.append(('HAVE_NCURSESW', '1'))
             curses_defines.append(('_XOPEN_SOURCE_EXTENDED', '1'))
@@ -1204,7 +1201,7 @@
                                    include_dirs=curses_includes,
                                    define_macros=curses_defines,
                                    libraries = curses_libs) )
-        elif curses_library == 'curses' and platform != 'darwin':
+        elif curses_library == 'curses' and host_platform != 'darwin':
                 # OSX has an old Berkeley curses, not good enough for
                 # the _curses module.
             if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
@@ -1258,7 +1255,7 @@
                         break
             if version >= version_req:
                 if (self.compiler.find_library_file(lib_dirs, 'z')):
-                    if sys.platform == "darwin":
+                    if host_platform == "darwin":
                         zlib_extra_link_args = ('-Wl,-search_paths_first',)
                     else:
                         zlib_extra_link_args = ()
@@ -1290,7 +1287,7 @@
 
         # Gustavo Niemeyer's bz2 module.
         if (self.compiler.find_library_file(lib_dirs, 'bz2')):
-            if sys.platform == "darwin":
+            if host_platform == "darwin":
                 bz2_extra_link_args = ('-Wl,-search_paths_first',)
             else:
                 bz2_extra_link_args = ()
@@ -1368,29 +1365,29 @@
         self.detect_ctypes(inc_dirs, lib_dirs)
 
         # Richard Oudkerk's multiprocessing module
-        if platform == 'win32':             # Windows
+        if host_platform == 'win32':        # Windows
             macros = dict()
             libraries = ['ws2_32']
 
-        elif platform == 'darwin':          # Mac OSX
+        elif host_platform == 'darwin':     # Mac OSX
             macros = dict()
             libraries = []
 
-        elif platform == 'cygwin':          # Cygwin
+        elif host_platform == 'cygwin':     # Cygwin
             macros = dict()
             libraries = []
 
-        elif platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'):
+        elif host_platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'):
             # FreeBSD's P1003.1b semaphore support is very experimental
             # and has many known problems. (as of June 2008)
             macros = dict()
             libraries = []
 
-        elif platform.startswith('openbsd'):
+        elif host_platform.startswith('openbsd'):
             macros = dict()
             libraries = []
 
-        elif platform.startswith('netbsd'):
+        elif host_platform.startswith('netbsd'):
             macros = dict()
             libraries = []
 
@@ -1398,7 +1395,7 @@
             macros = dict()
             libraries = ['rt']
 
-        if platform == 'win32':
+        if host_platform == 'win32':
             multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
                                      '_multiprocessing/semaphore.c',
                                    ]
@@ -1419,12 +1416,12 @@
         # End multiprocessing
 
         # Platform-specific libraries
-        if platform.startswith(('linux', 'freebsd', 'gnukfreebsd')):
+        if host_platform.startswith(('linux', 'freebsd', 'gnukfreebsd')):
             exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) )
         else:
             missing.append('ossaudiodev')
 
-        if sys.platform == 'darwin':
+        if host_platform == 'darwin':
             exts.append(
                        Extension('_gestalt', ['_gestalt.c'],
                        extra_link_args=['-framework', 'Carbon'])
@@ -1542,8 +1539,7 @@
         # Rather than complicate the code below, detecting and building
         # AquaTk is a separate method. Only one Tkinter will be built on
         # Darwin - either AquaTk, if it is found, or X11 based Tk.
-        platform = self.get_platform()
-        if (platform == 'darwin' and
+        if (host_platform == 'darwin' and
             self.detect_tkinter_darwin(inc_dirs, lib_dirs)):
             return
 
@@ -1566,7 +1562,7 @@
             # Check for the include files on Debian and {Free,Open}BSD, where
             # they're put in /usr/include/{tcl,tk}X.Y
             dotversion = version
-            if '.' not in dotversion and "bsd" in sys.platform.lower():
+            if '.' not in dotversion and "bsd" in host_platform.lower():
                 # OpenBSD and FreeBSD use Tcl/Tk library names like libtcl83.a,
                 # but the include subdirs are named like .../include/tcl8.3.
                 dotversion = dotversion[:-1] + '.' + dotversion[-1]
@@ -1592,7 +1588,7 @@
                 include_dirs.append(dir)
 
         # Check for various platform-specific directories
-        if platform == 'sunos5':
+        if host_platform == 'sunos5':
             include_dirs.append('/usr/openwin/include')
             added_lib_dirs.append('/usr/openwin/lib')
         elif os.path.exists('/usr/X11R6/include'):
@@ -1608,7 +1604,7 @@
             added_lib_dirs.append('/usr/X11/lib')
 
         # If Cygwin, then verify that X is installed before proceeding
-        if platform == 'cygwin':
+        if host_platform == 'cygwin':
             x11_inc = find_file('X11/Xlib.h', [], include_dirs)
             if x11_inc is None:
                 return
@@ -1627,11 +1623,11 @@
         libs.append('tk'+ version)
         libs.append('tcl'+ version)
 
-        if platform in ['aix3', 'aix4']:
+        if host_platform in ['aix3', 'aix4']:
             libs.append('ld')
 
         # Finally, link with the X11 libraries (not appropriate on cygwin)
-        if platform != "cygwin":
+        if host_platform != "cygwin":
             libs.append('X11')
 
         ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
@@ -1687,7 +1683,7 @@
 
     def configure_ctypes(self, ext):
         if not self.use_system_libffi:
-            if sys.platform == 'darwin':
+            if host_platform == 'darwin':
                 return self.configure_ctypes_darwin(ext)
 
             srcdir = sysconfig.get_config_var('srcdir')
@@ -1747,7 +1743,7 @@
                    '_ctypes/cfield.c']
         depends = ['_ctypes/ctypes.h']
 
-        if sys.platform == 'darwin':
+        if host_platform == 'darwin':
             sources.append('_ctypes/malloc_closure.c')
             sources.append('_ctypes/darwin/dlfcn_simple.c')
             extra_compile_args.append('-DMACOSX')
@@ -1755,7 +1751,7 @@
 # XXX Is this still needed?
 ##            extra_link_args.extend(['-read_only_relocs', 'warning'])
 
-        elif sys.platform == 'sunos5':
+        elif host_platform == 'sunos5':
             # XXX This shouldn't be necessary; it appears that some
             # of the assembler code is non-PIC (i.e. it has relocations
             # when it shouldn't. The proper fix would be to rewrite
@@ -1766,7 +1762,7 @@
             # finding some -z option for the Sun compiler.
             extra_link_args.append('-mimpure-text')
 
-        elif sys.platform.startswith('hp-ux'):
+        elif host_platform.startswith('hp-ux'):
             extra_link_args.append('-fPIC')
 
         ext = Extension('_ctypes',
@@ -1783,7 +1779,7 @@
         if not '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS"):
             return
 
-        if sys.platform == 'darwin':
+        if host_platform == 'darwin':
             # OS X 10.5 comes with libffi.dylib; the include files are
             # in /usr/include/ffi
             inc_dirs.append('/usr/include/ffi')
@@ -1876,7 +1872,6 @@
           'universal':   [('UNIVERSAL','1')]
         }
 
-        platform = self.get_platform()
         cc = sysconfig.get_config_var('CC')
         sizeof_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
         machine = os.environ.get('PYTHON_DECIMAL_WITH_MACHINE')
@@ -1884,7 +1879,7 @@
         if machine:
             # Override automatic configuration to facilitate testing.
             define_macros = config[machine]
-        elif platform == 'darwin':
+        elif host_platform == 'darwin':
             # Universal here means: build with the same options Python
             # was built with.
             define_macros = config['universal']
@@ -1898,7 +1893,7 @@
         elif sizeof_size_t == 4:
             ppro = sysconfig.get_config_var('HAVE_GCC_ASM_FOR_X87')
             if ppro and ('gcc' in cc or 'clang' in cc) and \
-               not 'sunos' in platform:
+               not 'sunos' in host_platform:
                 # solaris: problems with register allocation.
                 # icc >= 11.0 works as well.
                 define_macros = config['ppro']

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list