[Python-checkins] r77818 - in python/branches/py3k: Lib/distutils/ccompiler.py Lib/distutils/command/bdist.py Lib/distutils/command/bdist_dumb.py Lib/distutils/command/bdist_wininst.py Lib/distutils/command/build.py Lib/distutils/command/build_clib.py Lib/distutils/command/build_ext.py Lib/distutils/command/build_scripts.py Lib/distutils/command/config.py Lib/distutils/command/install.py Lib/distutils/core.py Lib/distutils/cygwinccompiler.py Lib/distutils/extension.py Lib/distutils/msvc9compiler.py Lib/distutils/sysconfig.py Lib/distutils/tests/support.py Lib/distutils/tests/test_build.py Lib/distutils/tests/test_build_clib.py Lib/distutils/tests/test_build_ext.py Lib/distutils/tests/test_build_scripts.py Lib/distutils/tests/test_ccompiler.py Lib/distutils/tests/test_cygwinccompiler.py Lib/distutils/tests/test_extension.py Lib/distutils/tests/test_install.py Lib/distutils/tests/test_sysconfig.py Lib/distutils/tests/test_unixccompiler.py Lib/distutils/tests/test_util.py Lib/distutils/unixccompiler.py Lib/distutils/util.py Lib/site.py Lib/sysconfig.py Lib/test/test_site.py Lib/test/test_sysconfig.py Makefile.pre.in setup.py

tarek.ziade python-checkins at python.org
Fri Jan 29 12:41:04 CET 2010


Author: tarek.ziade
Date: Fri Jan 29 12:41:03 2010
New Revision: 77818

Log:
Merged revisions 77704,77752 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77704 | tarek.ziade | 2010-01-23 10:23:15 +0100 (Sat, 23 Jan 2010) | 1 line
  
  taking sysconfig out of distutils
........
  r77752 | tarek.ziade | 2010-01-26 00:19:56 +0100 (Tue, 26 Jan 2010) | 1 line
  
  switched the call order so this call works without suffering from issue #7774
........


Added:
   python/branches/py3k/Lib/sysconfig.py
      - copied, changed from r77704, /python/trunk/Lib/sysconfig.py
   python/branches/py3k/Lib/test/test_sysconfig.py
      - copied, changed from r77704, /python/trunk/Lib/test/test_sysconfig.py
Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/distutils/ccompiler.py
   python/branches/py3k/Lib/distutils/command/bdist.py
   python/branches/py3k/Lib/distutils/command/bdist_dumb.py
   python/branches/py3k/Lib/distutils/command/bdist_wininst.py
   python/branches/py3k/Lib/distutils/command/build.py
   python/branches/py3k/Lib/distutils/command/build_clib.py
   python/branches/py3k/Lib/distutils/command/build_ext.py
   python/branches/py3k/Lib/distutils/command/build_scripts.py
   python/branches/py3k/Lib/distutils/command/config.py
   python/branches/py3k/Lib/distutils/command/install.py
   python/branches/py3k/Lib/distutils/core.py
   python/branches/py3k/Lib/distutils/cygwinccompiler.py
   python/branches/py3k/Lib/distutils/extension.py
   python/branches/py3k/Lib/distutils/msvc9compiler.py
   python/branches/py3k/Lib/distutils/sysconfig.py
   python/branches/py3k/Lib/distutils/tests/support.py
   python/branches/py3k/Lib/distutils/tests/test_build.py
   python/branches/py3k/Lib/distutils/tests/test_build_clib.py
   python/branches/py3k/Lib/distutils/tests/test_build_ext.py
   python/branches/py3k/Lib/distutils/tests/test_build_scripts.py
   python/branches/py3k/Lib/distutils/tests/test_ccompiler.py
   python/branches/py3k/Lib/distutils/tests/test_cygwinccompiler.py
   python/branches/py3k/Lib/distutils/tests/test_extension.py
   python/branches/py3k/Lib/distutils/tests/test_install.py
   python/branches/py3k/Lib/distutils/tests/test_sysconfig.py
   python/branches/py3k/Lib/distutils/tests/test_unixccompiler.py
   python/branches/py3k/Lib/distutils/tests/test_util.py
   python/branches/py3k/Lib/distutils/unixccompiler.py
   python/branches/py3k/Lib/distutils/util.py
   python/branches/py3k/Lib/site.py
   python/branches/py3k/Lib/test/test_site.py
   python/branches/py3k/Makefile.pre.in
   python/branches/py3k/setup.py

Modified: python/branches/py3k/Lib/distutils/ccompiler.py
==============================================================================
--- python/branches/py3k/Lib/distutils/ccompiler.py	(original)
+++ python/branches/py3k/Lib/distutils/ccompiler.py	Fri Jan 29 12:41:03 2010
@@ -18,6 +18,58 @@
 from distutils.util import split_quoted, execute
 from distutils import log
 
+_sysconfig = __import__('sysconfig')
+
+def customize_compiler(compiler):
+    """Do any platform-specific customization of a CCompiler instance.
+
+    Mainly needed on Unix, so we can plug in the information that
+    varies across Unices and is stored in Python's Makefile.
+    """
+    if compiler.compiler_type == "unix":
+        (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
+            _sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
+                                       'CCSHARED', 'LDSHARED', 'SO', 'AR',
+                                       'ARFLAGS')
+
+        if 'CC' in os.environ:
+            cc = os.environ['CC']
+        if 'CXX' in os.environ:
+            cxx = os.environ['CXX']
+        if 'LDSHARED' in os.environ:
+            ldshared = os.environ['LDSHARED']
+        if 'CPP' in os.environ:
+            cpp = os.environ['CPP']
+        else:
+            cpp = cc + " -E"           # not always
+        if 'LDFLAGS' in os.environ:
+            ldshared = ldshared + ' ' + os.environ['LDFLAGS']
+        if 'CFLAGS' in os.environ:
+            cflags = opt + ' ' + os.environ['CFLAGS']
+            ldshared = ldshared + ' ' + os.environ['CFLAGS']
+        if 'CPPFLAGS' in os.environ:
+            cpp = cpp + ' ' + os.environ['CPPFLAGS']
+            cflags = cflags + ' ' + os.environ['CPPFLAGS']
+            ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
+        if 'AR' in os.environ:
+            ar = os.environ['AR']
+        if 'ARFLAGS' in os.environ:
+            archiver = ar + ' ' + os.environ['ARFLAGS']
+        else:
+            archiver = ar + ' ' + ar_flags
+
+        cc_cmd = cc + ' ' + cflags
+        compiler.set_executables(
+            preprocessor=cpp,
+            compiler=cc_cmd,
+            compiler_so=cc_cmd + ' ' + ccshared,
+            compiler_cxx=cxx,
+            linker_so=ldshared,
+            linker_exe=cc,
+            archiver=archiver)
+
+        compiler.shared_lib_extension = so_ext
+
 class CCompiler:
     """Abstract base class to define the interface that must be implemented
     by real compiler classes.  Also has some utility methods used by

Modified: python/branches/py3k/Lib/distutils/command/bdist.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/bdist.py	(original)
+++ python/branches/py3k/Lib/distutils/command/bdist.py	Fri Jan 29 12:41:03 2010
@@ -6,10 +6,10 @@
 __revision__ = "$Id$"
 
 import os
+from sysconfig import get_platform
 
 from distutils.core import Command
 from distutils.errors import DistutilsPlatformError, DistutilsOptionError
-from distutils.util import get_platform
 
 
 def show_formats():

Modified: python/branches/py3k/Lib/distutils/command/bdist_dumb.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/bdist_dumb.py	(original)
+++ python/branches/py3k/Lib/distutils/command/bdist_dumb.py	Fri Jan 29 12:41:03 2010
@@ -8,11 +8,11 @@
 
 import os
 
+from sysconfig import get_python_version, get_platform
+
 from distutils.core import Command
-from distutils.util import get_platform
 from distutils.dir_util import remove_tree, ensure_relative
 from distutils.errors import DistutilsPlatformError
-from distutils.sysconfig import get_python_version
 from distutils import log
 
 class bdist_dumb(Command):

Modified: python/branches/py3k/Lib/distutils/command/bdist_wininst.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/bdist_wininst.py	(original)
+++ python/branches/py3k/Lib/distutils/command/bdist_wininst.py	Fri Jan 29 12:41:03 2010
@@ -8,11 +8,11 @@
 import sys
 import os
 
+from sysconfig import get_python_version, get_platform
+
 from distutils.core import Command
-from distutils.util import get_platform
 from distutils.dir_util import remove_tree
 from distutils.errors import DistutilsOptionError, DistutilsPlatformError
-from distutils.sysconfig import get_python_version
 from distutils import log
 
 class bdist_wininst(Command):

Modified: python/branches/py3k/Lib/distutils/command/build.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/build.py	(original)
+++ python/branches/py3k/Lib/distutils/command/build.py	Fri Jan 29 12:41:03 2010
@@ -5,9 +5,10 @@
 __revision__ = "$Id$"
 
 import sys, os
+from sysconfig import get_platform
+
 from distutils.core import Command
 from distutils.errors import DistutilsOptionError
-from distutils.util import get_platform
 
 def show_compilers():
     from distutils.ccompiler import show_compilers

Modified: python/branches/py3k/Lib/distutils/command/build_clib.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/build_clib.py	(original)
+++ python/branches/py3k/Lib/distutils/command/build_clib.py	Fri Jan 29 12:41:03 2010
@@ -19,7 +19,7 @@
 import os
 from distutils.core import Command
 from distutils.errors import DistutilsSetupError
-from distutils.sysconfig import customize_compiler
+from distutils.ccompiler import customize_compiler
 from distutils import log
 
 def show_compilers():

Modified: python/branches/py3k/Lib/distutils/command/build_ext.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/build_ext.py	(original)
+++ python/branches/py3k/Lib/distutils/command/build_ext.py	Fri Jan 29 12:41:03 2010
@@ -9,13 +9,14 @@
 import sys, os, re
 from warnings import warn
 
+from sysconfig import get_platform
+
 from distutils.core import Command
-from distutils.errors import (CCompilerError, DistutilsError, CompileError,
-                              DistutilsSetupError, DistutilsPlatformError)
-from distutils.sysconfig import customize_compiler, get_python_version
+from distutils.errors import *
+from distutils.ccompiler import customize_compiler
 from distutils.dep_util import newer_group
 from distutils.extension import Extension
-from distutils.util import get_platform
+
 from distutils import log
 
 # this keeps compatibility from 2.3 to 2.5
@@ -172,8 +173,7 @@
         self.user = None
 
     def finalize_options(self):
-        from distutils import sysconfig
-
+        _sysconfig = __import__('sysconfig')
         self.set_undefined_options('build',
                                    ('build_lib', 'build_lib'),
                                    ('build_temp', 'build_temp'),
@@ -190,8 +190,8 @@
 
         # Make sure Python's include directories (for Python.h, pyconfig.h,
         # etc.) are in the include search path.
-        py_include = sysconfig.get_python_inc()
-        plat_py_include = sysconfig.get_python_inc(plat_specific=1)
+        py_include = _sysconfig.get_path('include')
+        plat_py_include = _sysconfig.get_path('platinclude')
         if self.include_dirs is None:
             self.include_dirs = self.distribution.include_dirs or []
         if isinstance(self.include_dirs, str):
@@ -269,7 +269,7 @@
             if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
                 # building third party extensions
                 self.library_dirs.append(os.path.join(sys.prefix, "lib",
-                                                      "python" + get_python_version(),
+                                  "python" + _sysconfig.get_python_version(),
                                                       "config"))
             else:
                 # building python standard extensions
@@ -277,13 +277,13 @@
 
         # 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')
+        _sysconfig.get_config_var('Py_ENABLE_SHARED')
         if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
              or sys.platform.startswith('sunos'))
-            and sysconfig.get_config_var('Py_ENABLE_SHARED')):
+            and _sysconfig.get_config_var('Py_ENABLE_SHARED')):
             if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
                 # building third party extensions
-                self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
+                self.library_dirs.append(_sysconfig.get_config_var('LIBDIR'))
             else:
                 # building python standard extensions
                 self.library_dirs.append('.')
@@ -712,13 +712,13 @@
         of the file from which it will be loaded (eg. "foo/bar.so", or
         "foo\bar.pyd").
         """
-        from distutils.sysconfig import get_config_var
+        _sysconfig = __import__('sysconfig')
         ext_path = ext_name.split('.')
         # OS/2 has an 8 character module (extension) limit :-(
         if os.name == "os2":
             ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
         # extensions in debug_mode are named 'module_d.pyd' under windows
-        so_ext = get_config_var('SO')
+        so_ext = _sysconfig.get_config_var('SO')
         if os.name == 'nt' and self.debug:
             return os.path.join(*ext_path) + '_d' + so_ext
         return os.path.join(*ext_path) + so_ext
@@ -781,8 +781,8 @@
             # Don't use the default code below
             return ext.libraries
         else:
-            from distutils import sysconfig
-            if sysconfig.get_config_var('Py_ENABLE_SHARED'):
+            _sysconfig = __import__('sysconfig')
+            if _sysconfig.get_config_var('Py_ENABLE_SHARED'):
                 template = "python%d.%d"
                 pythonlib = (template %
                              (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))

Modified: python/branches/py3k/Lib/distutils/command/build_scripts.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/build_scripts.py	(original)
+++ python/branches/py3k/Lib/distutils/command/build_scripts.py	Fri Jan 29 12:41:03 2010
@@ -6,7 +6,6 @@
 
 import os, re
 from stat import ST_MODE
-from distutils import sysconfig
 from distutils.core import Command
 from distutils.dep_util import newer
 from distutils.util import convert_path, Mixin2to3
@@ -57,6 +56,7 @@
         ie. starts with "\#!" and contains "python"), then adjust the first
         line to refer to the current Python interpreter as we copy.
         """
+        _sysconfig = __import__('sysconfig')
         self.mkpath(self.build_dir)
         outfiles = []
         updated_files = []
@@ -96,16 +96,16 @@
                 updated_files.append(outfile)
                 if not self.dry_run:
                     outf = open(outfile, "w")
-                    if not sysconfig.python_build:
+                    if not _sysconfig.is_python_build():
                         outf.write("#!%s%s\n" %
                                    (self.executable,
                                     post_interp))
                     else:
                         outf.write("#!%s%s\n" %
                                    (os.path.join(
-                            sysconfig.get_config_var("BINDIR"),
-                           "python%s%s" % (sysconfig.get_config_var("VERSION"),
-                                           sysconfig.get_config_var("EXE"))),
+                            _sysconfig.get_config_var("BINDIR"),
+                           "python%s%s" % (_sysconfig.get_config_var("VERSION"),
+                                           _sysconfig.get_config_var("EXE"))),
                                     post_interp))
                     outf.writelines(f.readlines())
                     outf.close()

Modified: python/branches/py3k/Lib/distutils/command/config.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/config.py	(original)
+++ python/branches/py3k/Lib/distutils/command/config.py	Fri Jan 29 12:41:03 2010
@@ -16,7 +16,7 @@
 
 from distutils.core import Command
 from distutils.errors import DistutilsExecError
-from distutils.sysconfig import customize_compiler
+from distutils.ccompiler import customize_compiler
 from distutils import log
 
 LANG_EXT = {"c": ".c", "c++": ".cxx"}

Modified: python/branches/py3k/Lib/distutils/command/install.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/install.py	(original)
+++ python/branches/py3k/Lib/distutils/command/install.py	Fri Jan 29 12:41:03 2010
@@ -7,115 +7,25 @@
 import sys
 import os
 
+from sysconfig import (get_config_vars, get_platform, get_paths, get_path,
+                       get_config_var)
+
 from distutils import log
 from distutils.core import Command
 from distutils.debug import DEBUG
-from distutils.sysconfig import get_config_vars
 from distutils.errors import DistutilsPlatformError
 from distutils.file_util import write_file
-from distutils.util import convert_path, subst_vars, change_root
-from distutils.util import get_platform
+from distutils.util import convert_path, change_root
 from distutils.errors import DistutilsOptionError
 
-# this keeps compatibility from 2.3 to 2.5
-if sys.version < "2.6":
-    USER_BASE = None
-    USER_SITE = None
-    HAS_USER_SITE = False
-else:
-    from site import USER_BASE
-    from site import USER_SITE
-    HAS_USER_SITE = True
-
-if sys.version < "2.2":
-    WINDOWS_SCHEME = {
-        'purelib': '$base',
-        'platlib': '$base',
-        'headers': '$base/Include/$dist_name',
-        'scripts': '$base/Scripts',
-        'data'   : '$base',
-    }
-else:
-    WINDOWS_SCHEME = {
-        'purelib': '$base/Lib/site-packages',
-        'platlib': '$base/Lib/site-packages',
-        'headers': '$base/Include/$dist_name',
-        'scripts': '$base/Scripts',
-        'data'   : '$base',
-    }
-
-INSTALL_SCHEMES = {
-    'unix_prefix': {
-        'purelib': '$base/lib/python$py_version_short/site-packages',
-        'platlib': '$platbase/lib/python$py_version_short/site-packages',
-        'headers': '$base/include/python$py_version_short/$dist_name',
-        'scripts': '$base/bin',
-        'data'   : '$base',
-        },
-    'unix_home': {
-        'purelib': '$base/lib/python',
-        'platlib': '$base/lib/python',
-        'headers': '$base/include/python/$dist_name',
-        'scripts': '$base/bin',
-        'data'   : '$base',
-        },
-    'nt': WINDOWS_SCHEME,
-    'mac': {
-        'purelib': '$base/Lib/site-packages',
-        'platlib': '$base/Lib/site-packages',
-        'headers': '$base/Include/$dist_name',
-        'scripts': '$base/Scripts',
-        'data'   : '$base',
-        },
-
-    'os2': {
-        'purelib': '$base/Lib/site-packages',
-        'platlib': '$base/Lib/site-packages',
-        'headers': '$base/Include/$dist_name',
-        'scripts': '$base/Scripts',
-        'data'   : '$base',
-        },
-    }
-
-# user site schemes
-if HAS_USER_SITE:
-    INSTALL_SCHEMES['nt_user'] = {
-        'purelib': '$usersite',
-        'platlib': '$usersite',
-        'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
-        'scripts': '$userbase/Scripts',
-        'data'   : '$userbase',
-        }
-
-    INSTALL_SCHEMES['unix_user'] = {
-        'purelib': '$usersite',
-        'platlib': '$usersite',
-        'headers': '$userbase/include/python$py_version_short/$dist_name',
-        'scripts': '$userbase/bin',
-        'data'   : '$userbase',
-        }
-
-    INSTALL_SCHEMES['mac_user'] = {
-        'purelib': '$usersite',
-        'platlib': '$usersite',
-        'headers': '$userbase/$py_version_short/include/$dist_name',
-        'scripts': '$userbase/bin',
-        'data'   : '$userbase',
-        }
-
-    INSTALL_SCHEMES['os2_home'] = {
-        'purelib': '$usersite',
-        'platlib': '$usersite',
-        'headers': '$userbase/include/python$py_version_short/$dist_name',
-        'scripts': '$userbase/bin',
-        'data'   : '$userbase',
-        }
-
-# The keys to an installation scheme; if any new types of files are to be
-# installed, be sure to add an entry to every installation scheme above,
-# and to SCHEME_KEYS here.
-SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
-
+def _subst_vars(s, local_vars):
+    try:
+        return s.format(**local_vars)
+    except KeyError:
+        try:
+            return s.format(**os.environ)
+        except KeyError as var:
+            raise AttributeError('{%s}' % var)
 
 class install(Command):
 
@@ -182,11 +92,10 @@
 
     boolean_options = ['compile', 'force', 'skip-build']
 
-    if HAS_USER_SITE:
-        user_options.append(('user', None,
-                             "install in user site-package '%s'" % USER_SITE))
-        boolean_options.append('user')
-
+    user_options.append(('user', None,
+                        "install in user site-package '%s'" % \
+                            get_path('purelib', '%s_user' % os.name)))
+    boolean_options.append('user')
     negative_opt = {'no-compile' : 'compile'}
 
 
@@ -216,8 +125,8 @@
         self.install_lib = None         # set to either purelib or platlib
         self.install_scripts = None
         self.install_data = None
-        self.install_userbase = USER_BASE
-        self.install_usersite = USER_SITE
+        self.install_userbase = get_config_var('userbase')
+        self.install_usersite = get_path('purelib', '%s_user' % os.name)
 
         self.compile = None
         self.optimize = None
@@ -327,7 +236,9 @@
         # about needing recursive variable expansion (shudder).
 
         py_version = sys.version.split()[0]
-        (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
+        prefix, exec_prefix, srcdir = get_config_vars('prefix', 'exec_prefix',
+                                                      'srcdir')
+
         self.config_vars = {'dist_name': self.distribution.get_name(),
                             'dist_version': self.distribution.get_version(),
                             'dist_fullname': self.distribution.get_fullname(),
@@ -338,12 +249,11 @@
                             'prefix': prefix,
                             'sys_exec_prefix': exec_prefix,
                             'exec_prefix': exec_prefix,
+                            'srcdir': srcdir,
                            }
 
-        if HAS_USER_SITE:
-            self.config_vars['userbase'] = self.install_userbase
-            self.config_vars['usersite'] = self.install_usersite
-
+        self.config_vars['userbase'] = self.install_userbase
+        self.config_vars['usersite'] = self.install_usersite
         self.expand_basedirs()
 
         self.dump_dirs("post-expand_basedirs()")
@@ -447,10 +357,10 @@
                 raise DistutilsPlatformError(
                     "User base directory is not specified")
             self.install_base = self.install_platbase = self.install_userbase
-            self.select_scheme("unix_user")
+            self.select_scheme("posix_user")
         elif self.home is not None:
             self.install_base = self.install_platbase = self.home
-            self.select_scheme("unix_home")
+            self.select_scheme("posix_home")
         else:
             if self.prefix is None:
                 if self.exec_prefix is not None:
@@ -466,7 +376,7 @@
 
             self.install_base = self.prefix
             self.install_platbase = self.exec_prefix
-            self.select_scheme("unix_prefix")
+            self.select_scheme("posix_prefix")
 
     def finalize_other(self):
         """Finalizes options for non-posix platforms"""
@@ -478,7 +388,7 @@
             self.select_scheme(os.name + "_user")
         elif self.home is not None:
             self.install_base = self.install_platbase = self.home
-            self.select_scheme("unix_home")
+            self.select_scheme("posix_home")
         else:
             if self.prefix is None:
                 self.prefix = os.path.normpath(sys.prefix)
@@ -493,11 +403,15 @@
     def select_scheme(self, name):
         """Sets the install directories by applying the install schemes."""
         # it's the caller's problem if they supply a bad name!
-        scheme = INSTALL_SCHEMES[name]
-        for key in SCHEME_KEYS:
+        scheme = get_paths(name, expand=False)
+        for key, value in scheme.items():
+            if key == 'platinclude':
+                key = 'headers'
+                value = os.path.join(value, self.distribution.get_name())
             attrname = 'install_' + key
-            if getattr(self, attrname) is None:
-                setattr(self, attrname, scheme[key])
+            if hasattr(self, attrname):
+                if getattr(self, attrname) is None:
+                    setattr(self, attrname, value)
 
     def _expand_attrs(self, attrs):
         for attr in attrs:
@@ -505,7 +419,10 @@
             if val is not None:
                 if os.name == 'posix' or os.name == 'nt':
                     val = os.path.expanduser(val)
-                val = subst_vars(val, self.config_vars)
+                try:
+                    val = _subst_vars(val, self.config_vars)
+                except:
+                    import pdb; pdb.set_trace()
                 setattr(self, attr, val)
 
     def expand_basedirs(self):

Modified: python/branches/py3k/Lib/distutils/core.py
==============================================================================
--- python/branches/py3k/Lib/distutils/core.py	(original)
+++ python/branches/py3k/Lib/distutils/core.py	Fri Jan 29 12:41:03 2010
@@ -35,7 +35,7 @@
 
 def gen_usage(script_name):
     script = os.path.basename(script_name)
-    return USAGE % vars()
+    return USAGE % {'script': script}
 
 
 # Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.

Modified: python/branches/py3k/Lib/distutils/cygwinccompiler.py
==============================================================================
--- python/branches/py3k/Lib/distutils/cygwinccompiler.py	(original)
+++ python/branches/py3k/Lib/distutils/cygwinccompiler.py	Fri Jan 29 12:41:03 2010
@@ -337,7 +337,7 @@
     # XXX since this function also checks sys.version, it's not strictly a
     # "pyconfig.h" check -- should probably be renamed...
 
-    from distutils import sysconfig
+    _sysconfig = __import__('sysconfig')
 
     # if sys.version contains GCC then python was compiled with GCC, and the
     # pyconfig.h file should be OK
@@ -345,7 +345,7 @@
         return CONFIG_H_OK, "sys.version mentions 'GCC'"
 
     # let's see if __GNUC__ is mentioned in python.h
-    fn = sysconfig.get_config_h_filename()
+    fn = _sysconfig.get_config_h_filename()
     try:
         with open(fn) as config_h:
             if "__GNUC__" in config_h.read():

Modified: python/branches/py3k/Lib/distutils/extension.py
==============================================================================
--- python/branches/py3k/Lib/distutils/extension.py	(original)
+++ python/branches/py3k/Lib/distutils/extension.py	Fri Jan 29 12:41:03 2010
@@ -134,14 +134,17 @@
 
 def read_setup_file(filename):
     """Reads a Setup file and returns Extension instances."""
-    from distutils.sysconfig import (parse_makefile, expand_makefile_vars,
+    warnings.warn('distutils.extensions.read_setup_file is deprecated. '
+                  'It will be removed in the next Python release.')
+    _sysconfig = __import__('sysconfig')
+    from distutils.sysconfig import (expand_makefile_vars,
                                      _variable_rx)
 
     from distutils.text_file import TextFile
     from distutils.util import split_quoted
 
     # First pass over the file to gather "VAR = VALUE" assignments.
-    vars = parse_makefile(filename)
+    vars = _sysconfig._parse_makefile(filename)
 
     # Second pass to gobble up the real content: lines of the form
     #   <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
@@ -161,7 +164,10 @@
             file.warn("'%s' lines not handled yet" % line)
             continue
 
-        line = expand_makefile_vars(line, vars)
+        with warnings.catch_warnings():
+            warnings.simplefilter("ignore")
+            line = expand_makefile_vars(line, vars)
+
         words = split_quoted(line)
 
         # NB. this parses a slightly different syntax than the old

Modified: python/branches/py3k/Lib/distutils/msvc9compiler.py
==============================================================================
--- python/branches/py3k/Lib/distutils/msvc9compiler.py	(original)
+++ python/branches/py3k/Lib/distutils/msvc9compiler.py	Fri Jan 29 12:41:03 2010
@@ -23,10 +23,10 @@
                               CompileError, LibError, LinkError)
 from distutils.ccompiler import CCompiler, gen_lib_options
 from distutils import log
-from distutils.util import get_platform
-
 import winreg
 
+_sysconfig = __import__('sysconfig')
+
 RegOpenKeyEx = winreg.OpenKeyEx
 RegEnumKey = winreg.EnumKey
 RegEnumValue = winreg.EnumValue
@@ -327,7 +327,7 @@
         # multi-init means we would need to check platform same each time...
         assert not self.initialized, "don't init multiple times"
         if plat_name is None:
-            plat_name = get_platform()
+            plat_name = _sysconfig.get_platform()
         # sanity check for platforms to prevent obscure errors later.
         ok_plats = 'win32', 'win-amd64', 'win-ia64'
         if plat_name not in ok_plats:
@@ -348,12 +348,12 @@
             # On AMD64, 'vcvars32.bat amd64' is a native build env; to cross
             # compile use 'x86' (ie, it runs the x86 compiler directly)
             # No idea how itanium handles this, if at all.
-            if plat_name == get_platform() or plat_name == 'win32':
+            if plat_name == _sysconfig.get_platform() or plat_name == 'win32':
                 # native build or cross-compile to win32
                 plat_spec = PLAT_TO_VCVARS[plat_name]
             else:
                 # cross compile from win32 -> some 64bit
-                plat_spec = PLAT_TO_VCVARS[get_platform()] + '_' + \
+                plat_spec = PLAT_TO_VCVARS[_sysconfig.get_platform()] + '_' + \
                             PLAT_TO_VCVARS[plat_name]
 
             vc_env = query_vcvarsall(VERSION, plat_spec)

Modified: python/branches/py3k/Lib/distutils/sysconfig.py
==============================================================================
--- python/branches/py3k/Lib/distutils/sysconfig.py	(original)
+++ python/branches/py3k/Lib/distutils/sysconfig.py	Fri Jan 29 12:41:03 2010
@@ -7,6 +7,9 @@
 
 Written by:   Fred L. Drake, Jr.
 Email:        <fdrake at acm.org>
+
+**This module has been moved out of Distutils and will be removed from
+Python in the next version (3.2)**
 """
 
 __revision__ = "$Id$"
@@ -14,51 +17,36 @@
 import io
 import os
 import re
-import sys
+from warnings import warn
 
-from .errors import DistutilsPlatformError
+from distutils.errors import DistutilsPlatformError
 
-# These are needed in a couple of spots, so just compute them once.
-PREFIX = os.path.normpath(sys.prefix)
-EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
-
-# Path to the base directory of the project. On Windows the binary may
-# live in project/PCBuild9.  If we're dealing with an x64 Windows build,
-# it'll live in project/PCbuild/amd64.
-project_base = os.path.dirname(os.path.abspath(sys.executable))
-if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
-    project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
-# PC/VS7.1
-if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
-    project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
-                                                os.path.pardir))
-# PC/AMD64
-if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
-    project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
-                                                os.path.pardir))
-
-# python_build: (Boolean) if true, we're either building Python or
-# building an extension with an un-installed Python, so we use
-# different (hard-wired) directories.
-# Setup.local is available for Makefile builds including VPATH builds,
-# Setup.dist is available on Windows
-def _python_build():
-    for fn in ("Setup.dist", "Setup.local"):
-        if os.path.isfile(os.path.join(project_base, "Modules", fn)):
-            return True
-    return False
-python_build = _python_build()
+# importing sysconfig from Lib
+# to avoid this module to shadow it
+_sysconfig = __import__('sysconfig')
 
-def get_python_version():
-    """Return a string containing the major and minor Python version,
-    leaving off the patchlevel.  Sample return values could be '1.5'
-    or '2.2'.
-    """
-    return sys.version[:3]
+_DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. "
+                    "Use the APIs provided by the sysconfig module instead")
+
+def _get_project_base():
+    return _sysconfig._PROJECT_BASE
 
+project_base = _get_project_base()
+
+class _DeprecatedBool(int):
+    def __nonzero__(self):
+        warn(_DEPRECATION_MSG % 'get_python_version', DeprecationWarning)
+        return super(_DeprecatedBool, self).__nonzero__()
+
+def _python_build():
+    return _DeprecatedBool(_sysconfig.is_python_build())
+
+python_build = _python_build()
 
 def get_python_inc(plat_specific=0, prefix=None):
-    """Return the directory containing installed Python header files.
+    """This function is deprecated.
+
+    Return the directory containing installed Python header files.
 
     If 'plat_specific' is false (the default), this is the path to the
     non-platform-specific header files, i.e. Python.h and so on;
@@ -68,39 +56,22 @@
     If 'prefix' is supplied, use it instead of sys.prefix or
     sys.exec_prefix -- i.e., ignore 'plat_specific'.
     """
-    if prefix is None:
-        prefix = plat_specific and EXEC_PREFIX or PREFIX
-    if os.name == "posix":
-        if python_build:
-            # Assume the executable is in the build directory.  The
-            # pyconfig.h file should be in the same directory.  Since
-            # the build directory may not be the source directory, we
-            # must use "srcdir" from the makefile to find the "Include"
-            # directory.
-            base = os.path.dirname(os.path.abspath(sys.executable))
-            if plat_specific:
-                return base
-            else:
-                incdir = os.path.join(get_config_var('srcdir'), 'Include')
-                return os.path.normpath(incdir)
-        return os.path.join(prefix, "include", "python" + get_python_version())
-    elif os.name == "nt":
-        return os.path.join(prefix, "include")
-    elif os.name == "mac":
-        if plat_specific:
-            return os.path.join(prefix, "Mac", "Include")
-        else:
-            return os.path.join(prefix, "Include")
-    elif os.name == "os2":
-        return os.path.join(prefix, "Include")
+    warn(_DEPRECATION_MSG % 'get_python_inc', DeprecationWarning)
+    get_path = _sysconfig.get_path
+
+    if prefix is not None:
+        vars = {'base': prefix}
+        return get_path('include', vars=vars)
+
+    if not plat_specific:
+        return get_path('include')
     else:
-        raise DistutilsPlatformError(
-            "I don't know where Python installs its C header files "
-            "on platform '%s'" % os.name)
+        return get_path('platinclude')
 
+def get_python_lib(plat_specific=False, standard_lib=False, prefix=None):
+    """This function is deprecated.
 
-def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
-    """Return the directory containing the Python library (standard or
+    Return the directory containing the Python library (standard or
     site additions).
 
     If 'plat_specific' is true, return the directory containing
@@ -113,149 +84,33 @@
     If 'prefix' is supplied, use it instead of sys.prefix or
     sys.exec_prefix -- i.e., ignore 'plat_specific'.
     """
-    if prefix is None:
-        prefix = plat_specific and EXEC_PREFIX or PREFIX
-
-    if os.name == "posix":
-        libpython = os.path.join(prefix,
-                                 "lib", "python" + get_python_version())
-        if standard_lib:
-            return libpython
-        else:
-            return os.path.join(libpython, "site-packages")
-    elif os.name == "nt":
-        if standard_lib:
-            return os.path.join(prefix, "Lib")
-        else:
-            if get_python_version() < "2.2":
-                return prefix
-            else:
-                return os.path.join(prefix, "Lib", "site-packages")
-    elif os.name == "mac":
+    warn(_DEPRECATION_MSG % 'get_python_lib', DeprecationWarning)
+    vars = {}
+    get_path = _sysconfig.get_path
+    if prefix is not None:
         if plat_specific:
-            if standard_lib:
-                return os.path.join(prefix, "Lib", "lib-dynload")
-            else:
-                return os.path.join(prefix, "Lib", "site-packages")
+            vars['platbase'] = prefix
         else:
-            if standard_lib:
-                return os.path.join(prefix, "Lib")
-            else:
-                return os.path.join(prefix, "Lib", "site-packages")
-    elif os.name == "os2":
-        if standard_lib:
-            return os.path.join(prefix, "Lib")
+            vars['base'] = prefix
+    if standard_lib:
+        if plat_specific:
+            return get_path('platstdlib', vars=vars)
         else:
-            return os.path.join(prefix, "Lib", "site-packages")
+            return get_path('stdlib', vars=vars)
     else:
-        raise DistutilsPlatformError(
-            "I don't know where Python installs its library "
-            "on platform '%s'" % os.name)
-
-
-def customize_compiler(compiler):
-    """Do any platform-specific customization of a CCompiler instance.
-
-    Mainly needed on Unix, so we can plug in the information that
-    varies across Unices and is stored in Python's Makefile.
-    """
-    if compiler.compiler_type == "unix":
-        (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
-            get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
-                            'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
-
-        if 'CC' in os.environ:
-            cc = os.environ['CC']
-        if 'CXX' in os.environ:
-            cxx = os.environ['CXX']
-        if 'LDSHARED' in os.environ:
-            ldshared = os.environ['LDSHARED']
-        if 'CPP' in os.environ:
-            cpp = os.environ['CPP']
-        else:
-            cpp = cc + " -E"           # not always
-        if 'LDFLAGS' in os.environ:
-            ldshared = ldshared + ' ' + os.environ['LDFLAGS']
-        if 'CFLAGS' in os.environ:
-            cflags = opt + ' ' + os.environ['CFLAGS']
-            ldshared = ldshared + ' ' + os.environ['CFLAGS']
-        if 'CPPFLAGS' in os.environ:
-            cpp = cpp + ' ' + os.environ['CPPFLAGS']
-            cflags = cflags + ' ' + os.environ['CPPFLAGS']
-            ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
-        if 'AR' in os.environ:
-            ar = os.environ['AR']
-        if 'ARFLAGS' in os.environ:
-            archiver = ar + ' ' + os.environ['ARFLAGS']
-        else:
-            archiver = ar + ' ' + ar_flags
-
-        cc_cmd = cc + ' ' + cflags
-        compiler.set_executables(
-            preprocessor=cpp,
-            compiler=cc_cmd,
-            compiler_so=cc_cmd + ' ' + ccshared,
-            compiler_cxx=cxx,
-            linker_so=ldshared,
-            linker_exe=cc,
-            archiver=archiver)
-
-        compiler.shared_lib_extension = so_ext
-
-
-def get_config_h_filename():
-    """Return full pathname of installed pyconfig.h file."""
-    if python_build:
-        if os.name == "nt":
-            inc_dir = os.path.join(project_base, "PC")
+        if plat_specific:
+            return get_path('platlib', vars=vars)
         else:
-            inc_dir = project_base
-    else:
-        inc_dir = get_python_inc(plat_specific=1)
-    if get_python_version() < '2.2':
-        config_h = 'config.h'
-    else:
-        # The name of the config.h file changed in 2.2
-        config_h = 'pyconfig.h'
-    return os.path.join(inc_dir, config_h)
-
+            return get_path('purelib', vars=vars)
 
 def get_makefile_filename():
-    """Return full pathname of installed Makefile from the Python build."""
-    if python_build:
-        return os.path.join(os.path.dirname(sys.executable), "Makefile")
-    lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
-    return os.path.join(lib_dir, "config", "Makefile")
+    """This function is deprecated.
 
-
-def parse_config_h(fp, g=None):
-    """Parse a config.h-style file.
-
-    A dictionary containing name/value pairs is returned.  If an
-    optional dictionary is passed in as the second argument, it is
-    used instead of a new dictionary.
+    Return full pathname of installed Makefile from the Python build.
     """
-    if g is None:
-        g = {}
-    define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
-    undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
-    #
-    while True:
-        line = fp.readline()
-        if not line:
-            break
-        m = define_rx.match(line)
-        if m:
-            n, v = m.group(1, 2)
-            try: v = int(v)
-            except ValueError: pass
-            g[n] = v
-        else:
-            m = undef_rx.match(line)
-            if m:
-                g[m.group(1)] = 0
-    return g
 
+    warn(_DEPRECATION_MSG % 'get_makefile_filename', DeprecationWarning)
+    return _sysconfig._get_makefile_filename()
 
 # Regexes needed for parsing Makefile (and similar syntaxes,
 # like old-style Setup files).
@@ -264,91 +119,29 @@
 _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
 
 def parse_makefile(fn, g=None):
-    """Parse a Makefile-style file.
+    """This function is deprecated.
+
+    Parse a Makefile-style file.
 
     A dictionary containing name/value pairs is returned.  If an
     optional dictionary is passed in as the second argument, it is
     used instead of a new dictionary.
     """
-    from distutils.text_file import TextFile
-    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
-
-    if g is None:
-        g = {}
-    done = {}
-    notdone = {}
-
-    while True:
-        line = fp.readline()
-        if line is None: # eof
-            break
-        m = _variable_rx.match(line)
-        if m:
-            n, v = m.group(1, 2)
-            v = v.strip()
-            # `$$' is a literal `$' in make
-            tmpv = v.replace('$$', '')
-
-            if "$" in tmpv:
-                notdone[n] = v
-            else:
-                try:
-                    v = int(v)
-                except ValueError:
-                    # insert literal `$'
-                    done[n] = v.replace('$$', '$')
-                else:
-                    done[n] = v
-
-    # do variable interpolation here
-    while notdone:
-        for name in list(notdone):
-            value = notdone[name]
-            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
-            if m:
-                n = m.group(1)
-                found = True
-                if n in done:
-                    item = str(done[n])
-                elif n in notdone:
-                    # get it on a subsequent round
-                    found = False
-                elif n in os.environ:
-                    # do it like make: fall back to environment
-                    item = os.environ[n]
-                else:
-                    done[n] = item = ""
-                if found:
-                    after = value[m.end():]
-                    value = value[:m.start()] + item + after
-                    if "$" in after:
-                        notdone[name] = value
-                    else:
-                        try: value = int(value)
-                        except ValueError:
-                            done[name] = value.strip()
-                        else:
-                            done[name] = value
-                        del notdone[name]
-            else:
-                # bogus variable reference; just drop it since we can't deal
-                del notdone[name]
-
-    fp.close()
-
-    # save the results in the global dictionary
-    g.update(done)
-    return g
-
+    warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning)
+    return _sysconfig._parse_makefile(fn, g)
 
 def expand_makefile_vars(s, vars):
-    """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
+    """This function is deprecated.
+
+    Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
     'string' according to 'vars' (a dictionary mapping variable names to
     values).  Variables not present in 'vars' are silently expanded to the
     empty string.  The variable values in 'vars' should not contain further
     variable expansions; if 'vars' is the output of 'parse_makefile()',
     you're fine.  Returns a variable-expanded version of 's'.
     """
+    warn('this function will be removed in then next version of Python',
+         DeprecationWarning)
 
     # This algorithm does multiple expansion, so if vars['foo'] contains
     # "${bar}", it will expand ${foo} to ${bar}, and then expand
@@ -364,220 +157,3 @@
         else:
             break
     return s
-
-
-_config_vars = None
-
-def _init_posix():
-    """Initialize the module as appropriate for POSIX systems."""
-    g = {}
-    # load the installed Makefile:
-    try:
-        filename = get_makefile_filename()
-        parse_makefile(filename, g)
-    except IOError as msg:
-        my_msg = "invalid Python installation: unable to open %s" % filename
-        if hasattr(msg, "strerror"):
-            my_msg = my_msg + " (%s)" % msg.strerror
-
-        raise DistutilsPlatformError(my_msg)
-
-    # load the installed pyconfig.h:
-    try:
-        filename = get_config_h_filename()
-        parse_config_h(io.open(filename), g)
-    except IOError as msg:
-        my_msg = "invalid Python installation: unable to open %s" % filename
-        if hasattr(msg, "strerror"):
-            my_msg = my_msg + " (%s)" % msg.strerror
-
-        raise DistutilsPlatformError(my_msg)
-
-    # On MacOSX we need to check the setting of the environment variable
-    # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
-    # it needs to be compatible.
-    # If it isn't set we set it to the configure-time value
-    if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
-        cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
-        cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
-        if cur_target == '':
-            cur_target = cfg_target
-            os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
-        elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_target.split('.')]:
-            my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
-                % (cur_target, cfg_target))
-            raise DistutilsPlatformError(my_msg)
-
-    # On AIX, there are wrong paths to the linker scripts in the Makefile
-    # -- these paths are relative to the Python source, but when installed
-    # the scripts are in another directory.
-    if python_build:
-        g['LDSHARED'] = g['BLDSHARED']
-
-    elif get_python_version() < '2.1':
-        # The following two branches are for 1.5.2 compatibility.
-        if sys.platform == 'aix4':          # what about AIX 3.x ?
-            # Linker script is in the config directory, not in Modules as the
-            # Makefile says.
-            python_lib = get_python_lib(standard_lib=1)
-            ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
-            python_exp = os.path.join(python_lib, 'config', 'python.exp')
-
-            g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
-
-    global _config_vars
-    _config_vars = g
-
-
-def _init_nt():
-    """Initialize the module as appropriate for NT"""
-    g = {}
-    # set basic install directories
-    g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
-    g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
-
-    # XXX hmmm.. a normal install puts include files here
-    g['INCLUDEPY'] = get_python_inc(plat_specific=0)
-
-    g['SO'] = '.pyd'
-    g['EXE'] = ".exe"
-    g['VERSION'] = get_python_version().replace(".", "")
-    g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
-
-    global _config_vars
-    _config_vars = g
-
-
-def _init_mac():
-    """Initialize the module as appropriate for Macintosh systems"""
-    g = {}
-    # set basic install directories
-    g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
-    g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
-
-    # XXX hmmm.. a normal install puts include files here
-    g['INCLUDEPY'] = get_python_inc(plat_specific=0)
-
-    import MacOS
-    if not hasattr(MacOS, 'runtimemodel'):
-        g['SO'] = '.ppc.slb'
-    else:
-        g['SO'] = '.%s.slb' % MacOS.runtimemodel
-
-    # XXX are these used anywhere?
-    g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
-    g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
-
-    # These are used by the extension module build
-    g['srcdir'] = ':'
-    global _config_vars
-    _config_vars = g
-
-
-def _init_os2():
-    """Initialize the module as appropriate for OS/2"""
-    g = {}
-    # set basic install directories
-    g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
-    g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
-
-    # XXX hmmm.. a normal install puts include files here
-    g['INCLUDEPY'] = get_python_inc(plat_specific=0)
-
-    g['SO'] = '.pyd'
-    g['EXE'] = ".exe"
-
-    global _config_vars
-    _config_vars = g
-
-
-def get_config_vars(*args):
-    """With no arguments, return a dictionary of all configuration
-    variables relevant for the current platform.  Generally this includes
-    everything needed to build extensions and install both pure modules and
-    extensions.  On Unix, this means every variable defined in Python's
-    installed Makefile; on Windows and Mac OS it's a much smaller set.
-
-    With arguments, return a list of values that result from looking up
-    each argument in the configuration variable dictionary.
-    """
-    global _config_vars
-    if _config_vars is None:
-        func = globals().get("_init_" + os.name)
-        if func:
-            func()
-        else:
-            _config_vars = {}
-
-        # Normalized versions of prefix and exec_prefix are handy to have;
-        # in fact, these are the standard versions used most places in the
-        # Distutils.
-        _config_vars['prefix'] = PREFIX
-        _config_vars['exec_prefix'] = EXEC_PREFIX
-
-        # Convert srcdir into an absolute path if it appears necessary.
-        # Normally it is relative to the build directory.  However, during
-        # testing, for example, we might be running a non-installed python
-        # from a different directory.
-        if python_build and os.name == "posix":
-            base = os.path.dirname(os.path.abspath(sys.executable))
-            if (not os.path.isabs(_config_vars['srcdir']) and
-                base != os.getcwd()):
-                # srcdir is relative and we are not in the same directory
-                # as the executable. Assume executable is in the build
-                # directory and make srcdir absolute.
-                srcdir = os.path.join(base, _config_vars['srcdir'])
-                _config_vars['srcdir'] = os.path.normpath(srcdir)
-
-        if sys.platform == 'darwin':
-            kernel_version = os.uname()[2] # Kernel version (8.4.3)
-            major_version = int(kernel_version.split('.')[0])
-
-            if major_version < 8:
-                # On Mac OS X before 10.4, check if -arch and -isysroot
-                # are in CFLAGS or LDFLAGS and remove them if they are.
-                # This is needed when building extensions on a 10.3 system
-                # using a universal build of python.
-                for key in ('LDFLAGS', 'BASECFLAGS',
-                        # a number of derived variables. These need to be
-                        # patched up as well.
-                        'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
-                    flags = _config_vars[key]
-                    flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
-                    flags = re.sub('-isysroot [^ \t]*', ' ', flags)
-                    _config_vars[key] = flags
-
-            else:
-
-                # Allow the user to override the architecture flags using
-                # an environment variable.
-                # NOTE: This name was introduced by Apple in OSX 10.5 and
-                # is used by several scripting languages distributed with
-                # that OS release.
-
-                if 'ARCHFLAGS' in os.environ:
-                    arch = os.environ['ARCHFLAGS']
-                    for key in ('LDFLAGS', 'BASECFLAGS',
-                        # a number of derived variables. These need to be
-                        # patched up as well.
-                        'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
-
-                        flags = _config_vars[key]
-                        flags = re.sub('-arch\s+\w+\s', ' ', flags)
-                        flags = flags + ' ' + arch
-                        _config_vars[key] = flags
-
-    if args:
-        vals = []
-        for name in args:
-            vals.append(_config_vars.get(name))
-        return vals
-    else:
-        return _config_vars
-
-def get_config_var(name):
-    """Return the value of a single variable using the dictionary
-    returned by 'get_config_vars()'.  Equivalent to
-    get_config_vars().get(name)
-    """
-    return get_config_vars().get(name)

Modified: python/branches/py3k/Lib/distutils/tests/support.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/support.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/support.py	Fri Jan 29 12:41:03 2010
@@ -3,11 +3,19 @@
 import shutil
 import tempfile
 from copy import deepcopy
+import warnings
 
 from distutils import log
 from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
 from distutils.core import Distribution
 
+def capture_warnings(func):
+    def _capture_warnings(*args, **kw):
+        with warnings.catch_warnings():
+            warnings.simplefilter("ignore")
+            return func(*args, **kw)
+    return _capture_warnings
+
 class LoggingSilencer(object):
 
     def setUp(self):

Modified: python/branches/py3k/Lib/distutils/tests/test_build.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_build.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_build.py	Fri Jan 29 12:41:03 2010
@@ -5,7 +5,7 @@
 
 from distutils.command.build import build
 from distutils.tests import support
-from distutils.util import get_platform
+from sysconfig import get_platform
 
 class BuildTestCase(support.TempdirManager,
                     support.LoggingSilencer,

Modified: python/branches/py3k/Lib/distutils/tests/test_build_clib.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_build_clib.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_build_clib.py	Fri Jan 29 12:41:03 2010
@@ -120,8 +120,7 @@
         # before we run the command, we want to make sure
         # all commands are present on the system
         # by creating a compiler and checking its executables
-        from distutils.ccompiler import new_compiler
-        from distutils.sysconfig import customize_compiler
+        from distutils.ccompiler import new_compiler, customize_compiler
 
         compiler = new_compiler()
         customize_compiler(compiler)

Modified: python/branches/py3k/Lib/distutils/tests/test_build_ext.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_build_ext.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_build_ext.py	Fri Jan 29 12:41:03 2010
@@ -9,7 +9,7 @@
 
 from distutils.core import Extension, Distribution
 from distutils.command.build_ext import build_ext
-from distutils import sysconfig
+import sysconfig
 from distutils.tests.support import TempdirManager
 from distutils.tests.support import LoggingSilencer
 from distutils.extension import Extension
@@ -105,17 +105,17 @@
         old = sys.platform
 
         sys.platform = 'sunos' # fooling finalize_options
-        from distutils.sysconfig import  _config_vars
-        old_var = _config_vars.get('Py_ENABLE_SHARED')
-        _config_vars['Py_ENABLE_SHARED'] = 1
+        from sysconfig import _CONFIG_VARS
+        old_var = _CONFIG_VARS.get('Py_ENABLE_SHARED')
+        _CONFIG_VARS['Py_ENABLE_SHARED'] = 1
         try:
             cmd.ensure_finalized()
         finally:
             sys.platform = old
             if old_var is None:
-                del _config_vars['Py_ENABLE_SHARED']
+                del _CONFIG_VARS['Py_ENABLE_SHARED']
             else:
-                _config_vars['Py_ENABLE_SHARED'] = old_var
+                _CONFIG_VARS['Py_ENABLE_SHARED'] = old_var
 
         # make sure we get some library dirs under solaris
         self.assertTrue(len(cmd.library_dirs) > 0)
@@ -177,11 +177,10 @@
         cmd = build_ext(dist)
         cmd.finalize_options()
 
-        from distutils import sysconfig
-        py_include = sysconfig.get_python_inc()
+        py_include = sysconfig.get_path('include')
         self.assertTrue(py_include in cmd.include_dirs)
 
-        plat_py_include = sysconfig.get_python_inc(plat_specific=1)
+        plat_py_include = sysconfig.get_path('platinclude')
         self.assertTrue(plat_py_include in cmd.include_dirs)
 
         # make sure cmd.libraries is turned into a list

Modified: python/branches/py3k/Lib/distutils/tests/test_build_scripts.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_build_scripts.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_build_scripts.py	Fri Jan 29 12:41:03 2010
@@ -5,7 +5,7 @@
 
 from distutils.command.build_scripts import build_scripts
 from distutils.core import Distribution
-from distutils import sysconfig
+import sysconfig
 
 from distutils.tests import support
 
@@ -91,12 +91,12 @@
         # --with-suffix=3`, python is compiled okay but the build scripts
         # failed when writing the name of the executable
         old = sysconfig.get_config_vars().get('VERSION')
-        sysconfig._config_vars['VERSION'] = 4
+        sysconfig._CONFIG_VARS['VERSION'] = 4
         try:
             cmd.run()
         finally:
             if old is not None:
-                sysconfig._config_vars['VERSION'] = old
+                sysconfig._CONFIG_VARS['VERSION'] = old
 
         built = os.listdir(target)
         for name in expected:

Modified: python/branches/py3k/Lib/distutils/tests/test_ccompiler.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_ccompiler.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_ccompiler.py	Fri Jan 29 12:41:03 2010
@@ -3,8 +3,10 @@
 import unittest
 from test.support import captured_stdout
 
-from distutils.ccompiler import gen_lib_options, CCompiler
+from distutils.ccompiler import (gen_lib_options, CCompiler,
+                                 get_default_compiler, customize_compiler)
 from distutils import debug
+from distutils.tests import support
 
 class FakeCompiler(object):
     def library_dir_option(self, dir):
@@ -19,7 +21,7 @@
     def library_option(self, lib):
         return "-l" + lib
 
-class CCompilerTestCase(unittest.TestCase):
+class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
 
     def test_gen_lib_options(self):
         compiler = FakeCompiler()
@@ -52,6 +54,26 @@
         finally:
             debug.DEBUG = False
 
+    def test_customize_compiler(self):
+
+        # not testing if default compiler is not unix
+        if get_default_compiler() != 'unix':
+            return
+
+        os.environ['AR'] = 'my_ar'
+        os.environ['ARFLAGS'] = '-arflags'
+
+        # make sure AR gets caught
+        class compiler:
+            compiler_type = 'unix'
+
+            def set_executables(self, **kw):
+                self.exes = kw
+
+        comp = compiler()
+        customize_compiler(comp)
+        self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
+
 def test_suite():
     return unittest.makeSuite(CCompilerTestCase)
 

Modified: python/branches/py3k/Lib/distutils/tests/test_cygwinccompiler.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_cygwinccompiler.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_cygwinccompiler.py	Fri Jan 29 12:41:03 2010
@@ -4,6 +4,7 @@
 import os
 import subprocess
 import warnings
+import sysconfig
 
 from test.support import check_warnings
 from test.support import captured_stdout
@@ -23,13 +24,11 @@
         super(CygwinCCompilerTestCase, self).setUp()
         self.version = sys.version
         self.python_h = os.path.join(self.mkdtemp(), 'python.h')
-        from distutils import sysconfig
         self.old_get_config_h_filename = sysconfig.get_config_h_filename
         sysconfig.get_config_h_filename = self._get_config_h_filename
 
     def tearDown(self):
         sys.version = self.version
-        from distutils import sysconfig
         sysconfig.get_config_h_filename = self.old_get_config_h_filename
         super(CygwinCCompilerTestCase, self).tearDown()
 

Modified: python/branches/py3k/Lib/distutils/tests/test_extension.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_extension.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_extension.py	Fri Jan 29 12:41:03 2010
@@ -5,9 +5,11 @@
 
 from test.support import check_warnings
 from distutils.extension import read_setup_file, Extension
+from distutils.tests.support import capture_warnings
 
 class ExtensionTestCase(unittest.TestCase):
 
+    @capture_warnings
     def test_read_setup_file(self):
         # trying to read a Setup file
         # (sample extracted from the PyGame project)

Modified: python/branches/py3k/Lib/distutils/tests/test_install.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_install.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_install.py	Fri Jan 29 12:41:03 2010
@@ -5,12 +5,14 @@
 import sys
 import unittest
 import site
+import sysconfig
+from sysconfig import (get_scheme_names, _CONFIG_VARS, _INSTALL_SCHEMES,
+                       get_config_var, get_path)
 
 from test.support import captured_stdout
 
 from distutils.command.install import install
 from distutils.command import install as install_module
-from distutils.command.install import INSTALL_SCHEMES
 from distutils.core import Distribution
 from distutils.errors import DistutilsOptionError
 
@@ -36,9 +38,23 @@
             build_lib=os.path.join(builddir, "lib"),
             )
 
-        cmd = install(dist)
-        cmd.home = destination
-        cmd.ensure_finalized()
+
+
+        posix_prefix = _INSTALL_SCHEMES['posix_prefix']
+        old_posix_prefix = posix_prefix['platinclude']
+        posix_prefix['platinclude'] = \
+                '{platbase}/include/python{py_version_short}'
+
+        posix_home = _INSTALL_SCHEMES['posix_home']
+        old_posix_home = posix_home['platinclude']
+        posix_home['platinclude'] = '{base}/include/python'
+        try:
+            cmd = install(dist)
+            cmd.home = destination
+            cmd.ensure_finalized()
+        finally:
+            posix_home['platinclude'] = old_posix_home
+            posix_prefix['platinclude'] = old_posix_prefix
 
         self.assertEqual(cmd.install_base, destination)
         self.assertEqual(cmd.install_platbase, destination)
@@ -63,18 +79,19 @@
             return
 
         # preparing the environement for the test
-        self.old_user_base = site.USER_BASE
-        self.old_user_site = site.USER_SITE
+        self.old_user_base = get_config_var('userbase')
+        self.old_user_site = get_path('purelib', '%s_user' % os.name)
         self.tmpdir = self.mkdtemp()
         self.user_base = os.path.join(self.tmpdir, 'B')
         self.user_site = os.path.join(self.tmpdir, 'S')
-        site.USER_BASE = self.user_base
-        site.USER_SITE = self.user_site
-        install_module.USER_BASE = self.user_base
-        install_module.USER_SITE = self.user_site
+        _CONFIG_VARS['userbase'] = self.user_base
+        scheme = _INSTALL_SCHEMES['%s_user' % os.name]
+        scheme['purelib'] = self.user_site
 
         def _expanduser(path):
-            return self.tmpdir
+            if path[0] == '~':
+                path = os.path.normpath(self.tmpdir) + path[1:]
+            return path
         self.old_expand = os.path.expanduser
         os.path.expanduser = _expanduser
 
@@ -82,19 +99,17 @@
             # this is the actual test
             self._test_user_site()
         finally:
-            site.USER_BASE = self.old_user_base
-            site.USER_SITE = self.old_user_site
-            install_module.USER_BASE = self.old_user_base
-            install_module.USER_SITE = self.old_user_site
+            _CONFIG_VARS['userbase'] = self.old_user_base
+            scheme['purelib'] = self.old_user_site
             os.path.expanduser = self.old_expand
 
     def _test_user_site(self):
-        for key in ('nt_user', 'unix_user', 'os2_home'):
-            self.assertTrue(key in INSTALL_SCHEMES)
+        schemes = get_scheme_names()
+        for key in ('nt_user', 'posix_user', 'os2_home'):
+            self.assertTrue(key in schemes)
 
         dist = Distribution({'name': 'xx'})
         cmd = install(dist)
-
         # making sure the user option is there
         options = [name for name, short, lable in
                    cmd.user_options]
@@ -185,7 +200,7 @@
         with open(cmd.record) as f:
             self.assertEquals(len(f.readlines()), 1)
 
-    def test_debug_mode(self):
+    def _test_debug_mode(self):
         # this covers the code called when DEBUG is set
         old_logs_len = len(self.logs)
         install_module.DEBUG = True

Modified: python/branches/py3k/Lib/distutils/tests/test_sysconfig.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_sysconfig.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_sysconfig.py	Fri Jan 29 12:41:03 2010
@@ -4,7 +4,6 @@
 import unittest
 
 from distutils import sysconfig
-from distutils.ccompiler import get_default_compiler
 from distutils.tests import support
 from test.support import TESTFN, run_unittest
 
@@ -26,10 +25,7 @@
         elif os.path.isdir(TESTFN):
             shutil.rmtree(TESTFN)
 
-    def test_get_config_h_filename(self):
-        config_h = sysconfig.get_config_h_filename()
-        self.assertTrue(os.path.isfile(config_h), config_h)
-
+    @support.capture_warnings
     def test_get_python_lib(self):
         lib_dir = sysconfig.get_python_lib()
         # XXX doesn't work on Linux when Python was never installed before
@@ -37,7 +33,11 @@
         # test for pythonxx.lib?
         self.assertNotEqual(sysconfig.get_python_lib(),
                             sysconfig.get_python_lib(prefix=TESTFN))
+        _sysconfig = __import__('sysconfig')
+        res = sysconfig.get_python_lib(True, True)
+        self.assertEquals(_sysconfig.get_path('platstdlib'), res)
 
+    @support.capture_warnings
     def test_get_python_inc(self):
         inc_dir = sysconfig.get_python_inc()
         # This is not much of a test.  We make sure Python.h exists
@@ -47,31 +47,7 @@
         python_h = os.path.join(inc_dir, "Python.h")
         self.assertTrue(os.path.isfile(python_h), python_h)
 
-    def test_get_config_vars(self):
-        cvars = sysconfig.get_config_vars()
-        self.assertTrue(isinstance(cvars, dict))
-        self.assertTrue(cvars)
-
-    def test_customize_compiler(self):
-
-        # not testing if default compiler is not unix
-        if get_default_compiler() != 'unix':
-            return
-
-        os.environ['AR'] = 'my_ar'
-        os.environ['ARFLAGS'] = '-arflags'
-
-        # make sure AR gets caught
-        class compiler:
-            compiler_type = 'unix'
-
-            def set_executables(self, **kw):
-                self.exes = kw
-
-        comp = compiler()
-        sysconfig.customize_compiler(comp)
-        self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
-
+    @support.capture_warnings
     def test_parse_makefile_base(self):
         self.makefile = TESTFN
         fd = open(self.makefile, 'w')

Modified: python/branches/py3k/Lib/distutils/tests/test_unixccompiler.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_unixccompiler.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_unixccompiler.py	Fri Jan 29 12:41:03 2010
@@ -1,8 +1,8 @@
 """Tests for distutils.unixccompiler."""
 import sys
 import unittest
+import sysconfig
 
-from distutils import sysconfig
 from distutils.unixccompiler import UnixCCompiler
 
 class UnixCCompilerTestCase(unittest.TestCase):

Modified: python/branches/py3k/Lib/distutils/tests/test_util.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_util.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_util.py	Fri Jan 29 12:41:03 2010
@@ -6,15 +6,14 @@
 from io import BytesIO
 import subprocess
 
+from sysconfig import get_config_vars, get_platform
 from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
-from distutils.util import (get_platform, convert_path, change_root,
+from distutils.util import (convert_path, change_root,
                             check_environ, split_quoted, strtobool,
                             rfc822_escape, get_compiler_versions,
                             _find_exe_version, _MAC_OS_X_LD_VERSION,
                             byte_compile)
 from distutils import util
-from distutils.sysconfig import get_config_vars
-from distutils import sysconfig
 from distutils.tests import support
 from distutils.version import LooseVersion
 
@@ -44,7 +43,7 @@
         self.join = os.path.join
         self.isabs = os.path.isabs
         self.splitdrive = os.path.splitdrive
-        self._config_vars = copy(sysconfig._config_vars)
+        #self._config_vars = copy(sysconfig._config_vars)
 
         # patching os.uname
         if hasattr(os, 'uname'):
@@ -78,7 +77,7 @@
             os.uname = self.uname
         else:
             del os.uname
-        sysconfig._config_vars = copy(self._config_vars)
+        #sysconfig._config_vars = copy(self._config_vars)
         util.find_executable = self.old_find_executable
         subprocess.Popen = self.old_popen
         sys.old_stdout  = self.old_stdout
@@ -91,7 +90,7 @@
     def _get_uname(self):
         return self._uname
 
-    def test_get_platform(self):
+    def _test_get_platform(self):
 
         # windows XP, 32bits
         os.name = 'nt'
@@ -119,7 +118,6 @@
         sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) '
                        '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]')
         sys.platform = 'darwin'
-
         self._set_uname(('Darwin', 'macziade', '8.11.1',
                    ('Darwin Kernel Version 8.11.1: '
                     'Wed Oct 10 18:23:28 PDT 2007; '
@@ -157,7 +155,6 @@
         finally:
             sys.maxsize = maxsize
 
-
         # macbook with fat binaries (fat, universal or fat64)
         os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
         get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
@@ -201,7 +198,6 @@
 
             self.assertEquals(get_platform(), 'macosx-10.4-%s'%(arch,))
 
-
         # linux debian sarge
         os.name = 'posix'
         sys.version = ('2.3.5 (#1, Jul  4 2007, 17:28:59) '

Modified: python/branches/py3k/Lib/distutils/unixccompiler.py
==============================================================================
--- python/branches/py3k/Lib/distutils/unixccompiler.py	(original)
+++ python/branches/py3k/Lib/distutils/unixccompiler.py	Fri Jan 29 12:41:03 2010
@@ -17,7 +17,6 @@
 
 import os, sys
 
-from distutils import sysconfig
 from distutils.dep_util import newer
 from distutils.ccompiler import \
      CCompiler, gen_preprocess_options, gen_lib_options
@@ -25,6 +24,7 @@
      DistutilsExecError, CompileError, LibError, LinkError
 from distutils import log
 
+
 # XXX Things not currently handled:
 #   * optimization/debug/warning flags; we just use whatever's in Python's
 #     Makefile and live with it.  Is this adequate?  If not, we might
@@ -74,7 +74,7 @@
 
     if 'ARCHFLAGS' in os.environ and not stripArch:
         # User specified different -arch flags in the environ,
-        # see also distutils.sysconfig
+        # see also the sysconfig
         compiler_so = compiler_so + os.environ['ARCHFLAGS'].split()
 
     if stripSysroot:
@@ -281,7 +281,9 @@
         # this time, there's no way to determine this information from
         # the configuration data stored in the Python installation, so
         # we use this hack.
-        compiler = os.path.basename(sysconfig.get_config_var("CC"))
+        _sysconfig = __import__('sysconfig')
+
+        compiler = os.path.basename(_sysconfig.get_config_var("CC"))
         if sys.platform[:6] == "darwin":
             # MacOSX's linker doesn't understand the -R flag at all
             return "-L" + dir
@@ -296,7 +298,7 @@
             # use it anyway.  Since distutils has always passed in
             # -Wl whenever gcc was used in the past it is probably
             # safest to keep doing so.
-            if sysconfig.get_config_var("GNULD") == "yes":
+            if _sysconfig.get_config_var("GNULD") == "yes":
                 # GNU ld needs an extra option to get a RUNPATH
                 # instead of just an RPATH.
                 return "-Wl,--enable-new-dtags,-R" + dir

Modified: python/branches/py3k/Lib/distutils/util.py
==============================================================================
--- python/branches/py3k/Lib/distutils/util.py	(original)
+++ python/branches/py3k/Lib/distutils/util.py	Fri Jan 29 12:41:03 2010
@@ -15,173 +15,7 @@
 from distutils.version import LooseVersion
 from distutils.errors import DistutilsByteCompileError
 
-def get_platform():
-    """Return a string that identifies the current platform.
-
-    This is used mainly to distinguish platform-specific build directories and
-    platform-specific built distributions.  Typically includes the OS name
-    and version and the architecture (as supplied by 'os.uname()'),
-    although the exact information included depends on the OS; eg. for IRIX
-    the architecture isn't particularly important (IRIX only runs on SGI
-    hardware), but for Linux the kernel version isn't particularly
-    important.
-
-    Examples of returned values:
-       linux-i586
-       linux-alpha (?)
-       solaris-2.6-sun4u
-       irix-5.3
-       irix64-6.2
-
-    Windows will return one of:
-       win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
-       win-ia64 (64bit Windows on Itanium)
-       win32 (all others - specifically, sys.platform is returned)
-
-    For other non-POSIX platforms, currently just returns 'sys.platform'.
-    """
-    if os.name == 'nt':
-        # sniff sys.version for architecture.
-        prefix = " bit ("
-        i = sys.version.find(prefix)
-        if i == -1:
-            return sys.platform
-        j = sys.version.find(")", i)
-        look = sys.version[i+len(prefix):j].lower()
-        if look == 'amd64':
-            return 'win-amd64'
-        if look == 'itanium':
-            return 'win-ia64'
-        return sys.platform
-
-    if os.name != "posix" or not hasattr(os, 'uname'):
-        # XXX what about the architecture? NT is Intel or Alpha,
-        # Mac OS is M68k or PPC, etc.
-        return sys.platform
-
-    # Try to distinguish various flavours of Unix
-
-    (osname, host, release, version, machine) = os.uname()
-
-    # Convert the OS name to lowercase, remove '/' characters
-    # (to accommodate BSD/OS), and translate spaces (for "Power Macintosh")
-    osname = osname.lower().replace('/', '')
-    machine = machine.replace(' ', '_')
-    machine = machine.replace('/', '-')
-
-    if osname[:5] == "linux":
-        # At least on Linux/Intel, 'machine' is the processor --
-        # i386, etc.
-        # XXX what about Alpha, SPARC, etc?
-        return  "%s-%s" % (osname, machine)
-    elif osname[:5] == "sunos":
-        if release[0] >= "5":           # SunOS 5 == Solaris 2
-            osname = "solaris"
-            release = "%d.%s" % (int(release[0]) - 3, release[2:])
-        # fall through to standard osname-release-machine representation
-    elif osname[:4] == "irix":              # could be "irix64"!
-        return "%s-%s" % (osname, release)
-    elif osname[:3] == "aix":
-        return "%s-%s.%s" % (osname, version, release)
-    elif osname[:6] == "cygwin":
-        osname = "cygwin"
-        rel_re = re.compile (r'[\d.]+', re.ASCII)
-        m = rel_re.match(release)
-        if m:
-            release = m.group()
-    elif osname[:6] == "darwin":
-        #
-        # For our purposes, we'll assume that the system version from
-        # distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set
-        # to. This makes the compatibility story a bit more sane because the
-        # machine is going to compile and link as if it were
-        # MACOSX_DEPLOYMENT_TARGET.
-        from distutils.sysconfig import get_config_vars
-        cfgvars = get_config_vars()
-
-        macver = os.environ.get('MACOSX_DEPLOYMENT_TARGET')
-        if not macver:
-            macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET')
-
-        if 1:
-            # Always calculate the release of the running machine,
-            # needed to determine if we can build fat binaries or not.
-
-            macrelease = macver
-            # Get the system version. Reading this plist is a documented
-            # way to get the system version (see the documentation for
-            # the Gestalt Manager)
-            try:
-                f = open('/System/Library/CoreServices/SystemVersion.plist')
-            except IOError:
-                # We're on a plain darwin box, fall back to the default
-                # behaviour.
-                pass
-            else:
-                m = re.search(
-                        r'<key>ProductUserVisibleVersion</key>\s*' +
-                        r'<string>(.*?)</string>', f.read())
-                f.close()
-                if m is not None:
-                    macrelease = '.'.join(m.group(1).split('.')[:2])
-                # else: fall back to the default behaviour
-
-        if not macver:
-            macver = macrelease
-
-        if macver:
-            from distutils.sysconfig import get_config_vars
-            release = macver
-            osname = "macosx"
-
-            if (macrelease + '.') >= '10.4.' and \
-                    '-arch' in get_config_vars().get('CFLAGS', '').strip():
-                # The universal build will build fat binaries, but not on
-                # systems before 10.4
-                #
-                # Try to detect 4-way universal builds, those have machine-type
-                # 'universal' instead of 'fat'.
-
-                machine = 'fat'
-                cflags = get_config_vars().get('CFLAGS')
-
-                archs = re.findall('-arch\s+(\S+)', cflags)
-                archs.sort()
-                archs = tuple(archs)
-
-                if len(archs) == 1:
-                    machine = archs[0]
-                elif archs == ('i386', 'ppc'):
-                    machine = 'fat'
-                elif archs == ('i386', 'x86_64'):
-                    machine = 'intel'
-                elif archs == ('i386', 'ppc', 'x86_64'):
-                    machine = 'fat3'
-                elif archs == ('ppc64', 'x86_64'):
-                    machine = 'fat64'
-                elif archs == ('i386', 'ppc', 'ppc64', 'x86_64'):
-                    machine = 'universal'
-                else:
-                    raise ValueError(
-                       "Don't know machine value for archs=%r"%(archs,))
-
-            elif machine == 'i386':
-                # On OSX the machine type returned by uname is always the
-                # 32-bit variant, even if the executable architecture is
-                # the 64-bit variant
-                if sys.maxsize >= 2**32:
-                    machine = 'x86_64'
-
-            elif machine in ('PowerPC', 'Power_Macintosh'):
-                # Pick a sane name for the PPC architecture.
-                machine = 'ppc'
-
-                # See 'i386' case
-                if sys.maxsize >= 2**32:
-                    machine = 'ppc64'
-
-    return "%s-%s-%s" % (osname, release, machine)
-
+_sysconfig = __import__('sysconfig')
 
 def convert_path(pathname):
     """Return 'pathname' as a name that will work on the native filesystem.
@@ -269,7 +103,7 @@
         os.environ['HOME'] = pwd.getpwuid(os.getuid())[5]
 
     if 'PLAT' not in os.environ:
-        os.environ['PLAT'] = get_platform()
+        os.environ['PLAT'] = _sysconfig.get_platform()
 
     _environ_checked = 1
 

Modified: python/branches/py3k/Lib/site.py
==============================================================================
--- python/branches/py3k/Lib/site.py	(original)
+++ python/branches/py3k/Lib/site.py	Fri Jan 29 12:41:03 2010
@@ -108,7 +108,7 @@
 def addbuilddir():
     """Append ./build/lib.<platform> in case we're running in the build dir
     (especially for Guido :-)"""
-    from distutils.util import get_platform
+    from sysconfig import get_platform
     s = "build/lib.%s-%.3s" % (get_platform(), sys.version)
     if hasattr(sys, 'gettotalrefcount'):
         s += '-pydebug'
@@ -218,19 +218,8 @@
     global USER_BASE
     if USER_BASE is not None:
         return USER_BASE
-
-    env_base = os.environ.get("PYTHONUSERBASE", None)
-
-    def joinuser(*args):
-        return os.path.expanduser(os.path.join(*args))
-
-    # what about 'os2emx', 'riscos' ?
-    if os.name == "nt":
-        base = os.environ.get("APPDATA") or "~"
-        USER_BASE = env_base if env_base else joinuser(base, "Python")
-    else:
-        USER_BASE = env_base if env_base else joinuser("~", ".local")
-
+    from sysconfig import get_config_var
+    USER_BASE = get_config_var('userbase')
     return USER_BASE
 
 def getusersitepackages():
@@ -245,13 +234,9 @@
     if USER_SITE is not None:
         return USER_SITE
 
-    if os.name == "nt":
-        USER_SITE = os.path.join(user_base, "Python" + sys.version[0] +
-                                 sys.version[2], "site-packages")
-    else:
-        USER_SITE = os.path.join(user_base, "lib", "python" + sys.version[:3],
-                                 "site-packages")
-
+    from sysconfig import get_path
+    import os
+    USER_SITE = get_path('purelib', '%s_user' % os.name)
     return USER_SITE
 
 def addusersitepackages(known_paths):

Copied: python/branches/py3k/Lib/sysconfig.py (from r77704, /python/trunk/Lib/sysconfig.py)
==============================================================================
--- /python/trunk/Lib/sysconfig.py	(original)
+++ python/branches/py3k/Lib/sysconfig.py	Fri Jan 29 12:41:03 2010
@@ -84,7 +84,7 @@
 _EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
 _CONFIG_VARS = None
 _USER_BASE = None
-_PROJECT_BASE = os.path.dirname(abspath(sys.executable))
+_PROJECT_BASE = abspath(os.path.dirname(sys.executable))
 
 if os.name == "nt" and "pcbuild" in _PROJECT_BASE[-8:].lower():
     _PROJECT_BASE = abspath(os.path.join(_PROJECT_BASE, pardir))
@@ -114,7 +114,7 @@
     except KeyError:
         try:
             return s.format(**os.environ)
-        except KeyError, var:
+        except KeyError as var:
             raise AttributeError('{%s}' % var)
 
 def _extend_dict(target_dict, other_dict):
@@ -199,11 +199,13 @@
                     done[n] = v
 
     # do variable interpolation here
-    while notdone:
-        for name in notdone.keys():
+    variables = list(notdone.keys())
+
+    while len(variables) > 0:
+        for name in tuple(variables):
             value = notdone[name]
             m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
-            if m:
+            if m is not None:
                 n = m.group(1)
                 found = True
                 if n in done:
@@ -222,15 +224,17 @@
                     if "$" in after:
                         notdone[name] = value
                     else:
-                        try: value = int(value)
+                        try:
+                            value = int(value)
                         except ValueError:
                             done[name] = value.strip()
                         else:
                             done[name] = value
-                        del notdone[name]
+                        variables.remove(name)
             else:
                 # bogus variable reference; just drop it since we can't deal
-                del notdone[name]
+                variables.remove(name)
+
     # save the results in the global dictionary
     vars.update(done)
     return vars
@@ -285,22 +289,20 @@
     makefile = _get_makefile_filename()
     try:
         _parse_makefile(makefile, vars)
-    except IOError, e:
+    except IOError as e:
         msg = "invalid Python installation: unable to open %s" % makefile
         if hasattr(e, "strerror"):
             msg = msg + " (%s)" % e.strerror
         raise IOError(msg)
-
     # load the installed pyconfig.h:
     config_h = get_config_h_filename()
     try:
         parse_config_h(open(config_h), vars)
-    except IOError, e:
+    except IOError as e:
         msg = "invalid Python installation: unable to open %s" % config_h
         if hasattr(e, "strerror"):
             msg = msg + " (%s)" % e.strerror
         raise IOError(msg)
-
     # On MacOSX we need to check the setting of the environment variable
     # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
     # it needs to be compatible.
@@ -311,11 +313,11 @@
         if cur_target == '':
             cur_target = cfg_target
             os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
-        elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
+        elif (list(map(int, cfg_target.split('.'))) >
+              list(map(int, cur_target.split('.')))):
             msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" '
                    'during configure' % (cur_target, cfg_target))
             raise IOError(msg)
-
     # On AIX, there are wrong paths to the linker scripts in the Makefile
     # -- these paths are relative to the Python source, but when installed
     # the scripts are in another directory.
@@ -392,10 +394,10 @@
             _init_non_posix(_CONFIG_VARS)
         if os.name == 'posix':
             _init_posix(_CONFIG_VARS)
-
         if 'srcdir' not in _CONFIG_VARS:
             _CONFIG_VARS['srcdir'] = _PROJECT_BASE
 
+
         # Convert srcdir into an absolute path if it appears necessary.
         # Normally it is relative to the build directory.  However, during
         # testing, for example, we might be running a non-installed python
@@ -636,13 +638,13 @@
                 # On OSX the machine type returned by uname is always the
                 # 32-bit variant, even if the executable architecture is
                 # the 64-bit variant
-                if sys.maxint >= 2**32:
+                if sys.maxsize >= 2**32:
                     machine = 'x86_64'
 
             elif machine in ('PowerPC', 'Power_Macintosh'):
                 # Pick a sane name for the PPC architecture.
                 # See 'i386' case
-                if sys.maxint >= 2**32:
+                if sys.maxsize >= 2**32:
                     machine = 'ppc64'
                 else:
                     machine = 'ppc'

Modified: python/branches/py3k/Lib/test/test_site.py
==============================================================================
--- python/branches/py3k/Lib/test/test_site.py	(original)
+++ python/branches/py3k/Lib/test/test_site.py	Fri Jan 29 12:41:03 2010
@@ -11,6 +11,9 @@
 import sys
 import encodings
 import subprocess
+import sysconfig
+from copy import copy
+
 # Need to make sure to not import 'site' if someone specified ``-S`` at the
 # command-line.  Detect this by just making sure 'site' has not been imported
 # already.
@@ -38,6 +41,7 @@
         self.old_base = site.USER_BASE
         self.old_site = site.USER_SITE
         self.old_prefixes = site.PREFIXES
+        self.old_vars = copy(sysconfig._CONFIG_VARS)
 
     def tearDown(self):
         """Restore sys.path"""
@@ -45,6 +49,7 @@
         site.USER_BASE = self.old_base
         site.USER_SITE = self.old_site
         site.PREFIXES = self.old_prefixes
+        sysconfig._CONFIG_VARS = self.old_vars
 
     def test_makepath(self):
         # Test makepath() have an absolute path for its first return value
@@ -137,6 +142,9 @@
 
         # let's set PYTHONUSERBASE and see if it uses it
         site.USER_BASE = None
+        import sysconfig
+        sysconfig._CONFIG_VARS = None
+
         with EnvironmentVarGuard() as environ:
             environ['PYTHONUSERBASE'] = 'xoxo'
             self.assertTrue(site.getuserbase().startswith('xoxo'),

Copied: python/branches/py3k/Lib/test/test_sysconfig.py (from r77704, /python/trunk/Lib/test/test_sysconfig.py)
==============================================================================
--- /python/trunk/Lib/test/test_sysconfig.py	(original)
+++ python/branches/py3k/Lib/test/test_sysconfig.py	Fri Jan 29 12:41:03 2010
@@ -10,7 +10,7 @@
 import os
 from copy import copy, deepcopy
 
-from test.test_support import run_unittest, TESTFN
+from test.support import run_unittest, TESTFN
 
 import sysconfig
 from sysconfig import (get_paths, get_platform, get_config_vars,
@@ -65,7 +65,7 @@
             if os.environ.get(key) != value:
                 os.environ[key] = value
 
-        for key in os.environ.keys():
+        for key in list(os.environ.keys()):
             if key not in self.old_environ:
                 del os.environ[key]
 
@@ -78,7 +78,7 @@
         return self._uname
 
     def _cleanup_testfn(self):
-        path = test.test_support.TESTFN
+        path = TESTFN
         if os.path.isfile(path):
             os.remove(path)
         elif os.path.isdir(path):
@@ -91,9 +91,9 @@
         scheme = get_paths()
         default_scheme = _get_default_scheme()
         wanted = _expand_vars(default_scheme, None)
-        wanted = wanted.items()
+        wanted = list(wanted.items())
         wanted.sort()
-        scheme = scheme.items()
+        scheme = list(scheme.items())
         scheme.sort()
         self.assertEquals(scheme, wanted)
 

Modified: python/branches/py3k/Makefile.pre.in
==============================================================================
--- python/branches/py3k/Makefile.pre.in	(original)
+++ python/branches/py3k/Makefile.pre.in	Fri Jan 29 12:41:03 2010
@@ -412,7 +412,7 @@
 			$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
 
 platform: $(BUILDPYTHON)
-	$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
+	$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
 
 
 # Build the shared modules

Modified: python/branches/py3k/setup.py
==============================================================================
--- python/branches/py3k/setup.py	(original)
+++ python/branches/py3k/setup.py	Fri Jan 29 12:41:03 2010
@@ -5,9 +5,9 @@
 
 import sys, os, imp, re, optparse
 from glob import glob
+import sysconfig
 
 from distutils import log
-from distutils import sysconfig
 from distutils import text_file
 from distutils.errors import *
 from distutils.core import Extension, setup
@@ -132,7 +132,7 @@
 
         # Python header files
         headers = [sysconfig.get_config_h_filename()]
-        headers += glob(os.path.join(sysconfig.get_python_inc(), "*.h"))
+        headers += glob(os.path.join(sysconfig.get_path('platinclude'), "*.h"))
 
         for ext in self.extensions[:]:
             ext.sources = [ find_module_file(filename, moddirlist)


More information about the Python-checkins mailing list