Index: setup.py =================================================================== --- setup.py (revision 64406) +++ setup.py (working copy) @@ -112,51 +112,36 @@ self.extensions = extensions # Fix up the autodetected modules, prefixing all the source files - # with Modules/ and adding Python's include directory to the path. - (srcdir,) = sysconfig.get_config_vars('srcdir') + # with Modules/. + srcdir = sysconfig.get_config_var('srcdir') if not srcdir: # Maybe running on Windows but not using CYGWIN? raise ValueError("No source directory; cannot proceed.") - - # Figure out the location of the source code for extension modules - # (This logic is copied in distutils.test.test_sysconfig, - # so building in a separate directory does not break test_distutils.) - moddir = os.path.join(os.getcwd(), srcdir, 'Modules') - moddir = os.path.normpath(moddir) - srcdir, tail = os.path.split(moddir) srcdir = os.path.normpath(srcdir) - moddir = os.path.normpath(moddir) + moddirlist = [os.path.normpath(os.path.join(srcdir, 'Modules'))] - moddirlist = [moddir] - incdirlist = ['./Include'] - # Platform-dependent module source and include directories platform = self.get_platform() - alldirlist = moddirlist + incdirlist - # Fix up the paths for scripts, too self.distribution.scripts = [os.path.join(srcdir, filename) for filename in self.distribution.scripts] # Python header files - headers = glob("Include/*.h") + ["pyconfig.h"] + headers = [sysconfig.get_config_h_filename()] + headers += glob(os.path.join(sysconfig.get_python_inc(), "*.h")) for ext in self.extensions[:]: ext.sources = [ find_module_file(filename, moddirlist) for filename in ext.sources ] if ext.depends is not None: - ext.depends = [find_module_file(filename, alldirlist) + ext.depends = [find_module_file(filename, moddirlist) for filename in ext.depends] else: ext.depends = [] # re-compile extensions if a header file has been changed ext.depends.extend(headers) - ext.include_dirs.append( '.' ) # to get config.h - for incdir in incdirlist: - ext.include_dirs.append( os.path.join(srcdir, incdir) ) - # If a module has already been built statically, # don't build it here if ext.name in sys.builtin_module_names: @@ -347,7 +332,7 @@ config_h_vars = sysconfig.parse_config_h(open(config_h)) platform = self.get_platform() - (srcdir,) = sysconfig.get_config_vars('srcdir') + srcdir = sysconfig.get_config_var('srcdir') # Check for AtheOS which has libraries in non-standard locations if platform == 'atheos': @@ -1360,7 +1345,7 @@ def configure_ctypes_darwin(self, ext): # Darwin (OS X) uses preconfigured files, in # the Modules/_ctypes/libffi_osx directory. - (srcdir,) = sysconfig.get_config_vars('srcdir') + srcdir = sysconfig.get_config_var('srcdir') ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', '_ctypes', 'libffi_osx')) sources = [os.path.join(ffi_srcdir, p) @@ -1388,7 +1373,7 @@ if sys.platform == 'darwin': return self.configure_ctypes_darwin(ext) - (srcdir,) = sysconfig.get_config_vars('srcdir') + srcdir = sysconfig.get_config_var('srcdir') ffi_builddir = os.path.join(self.build_temp, 'libffi') ffi_srcdir = os.path.abspath(os.path.join(srcdir, 'Modules', '_ctypes', 'libffi')) Index: Lib/distutils/tests/test_build_ext.py =================================================================== --- Lib/distutils/tests/test_build_ext.py (revision 64406) +++ Lib/distutils/tests/test_build_ext.py (working copy) @@ -11,6 +11,10 @@ import unittest from test import support +def _get_source_filename(): + srcdir = sysconfig.get_config_var('srcdir') + return os.path.join(srcdir, 'Modules', 'xxmodule.c') + class BuildExtTestCase(unittest.TestCase): def setUp(self): # Create a simple test environment @@ -18,10 +22,8 @@ self.tmp_dir = tempfile.mkdtemp(prefix="pythontest_") self.sys_path = sys.path[:] sys.path.append(self.tmp_dir) + shutil.copy(_get_source_filename(), self.tmp_dir) - xx_c = os.path.join(sysconfig.project_base, 'Modules', 'xxmodule.c') - shutil.copy(xx_c, self.tmp_dir) - def test_build_ext(self): xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') xx_ext = Extension('xx', [xx_c]) @@ -66,9 +68,11 @@ shutil.rmtree(self.tmp_dir, False if os.name != "nt" else True) def test_suite(): - if not sysconfig.python_build: + src = _get_source_filename() + if not os.path.exists(src): if support.verbose: - print('test_build_ext: The test must be run in a python build dir') + print('test_build_ext: Cannot find source code (test' + ' must run in python build dir)') return unittest.TestSuite() else: return unittest.makeSuite(BuildExtTestCase) Index: Lib/distutils/tests/test_sysconfig.py =================================================================== --- Lib/distutils/tests/test_sysconfig.py (revision 64406) +++ Lib/distutils/tests/test_sysconfig.py (working copy) @@ -19,27 +19,10 @@ # test for pythonxx.lib? def test_get_python_inc(self): - # The check for srcdir is copied from Python's setup.py, - # and is necessary to make this test pass when building - # Python in a directory other than the source directory. - (srcdir,) = sysconfig.get_config_vars('srcdir') - if not srcdir: - inc_dir = sysconfig.get_python_inc() - else: - # This test is not really a proper test: when building - # Python from source, even in the same directory, - # we won't be testing the same thing as when running - # distutils' tests on an installed Python. Nevertheless, - # let's try to do our best: if we are running Python's - # unittests from a build directory that is not the source - # directory, the normal inc_dir will exist, it will just not - # contain anything of interest. - inc_dir = sysconfig.get_python_inc() - self.assert_(os.path.isdir(inc_dir)) - # Now test the source location, to make sure Python.h does - # exist. - inc_dir = os.path.join(os.getcwd(), srcdir, 'Include') - inc_dir = os.path.normpath(inc_dir) + inc_dir = sysconfig.get_python_inc() + # This is not much of a test. We make sure Python.h exists + # in the directory returned by get_python_inc() but we don't know + # it is the correct file. self.assert_(os.path.isdir(inc_dir), inc_dir) python_h = os.path.join(inc_dir, "Python.h") self.assert_(os.path.isfile(python_h), python_h) Index: Lib/distutils/sysconfig.py =================================================================== --- Lib/distutils/sysconfig.py (revision 64406) +++ Lib/distutils/sysconfig.py (working copy) @@ -72,15 +72,20 @@ prefix = plat_specific and EXEC_PREFIX or PREFIX if os.name == "posix": if python_build: - base = os.path.dirname(os.path.abspath(sys.executable)) + # 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. + exedir = os.path.dirname(os.path.abspath(sys.executable)) if plat_specific: - inc_dir = base + return exedir else: - inc_dir = os.path.join(base, "Include") - if not os.path.exists(inc_dir): - inc_dir = os.path.join(os.path.dirname(base), "Include") - return inc_dir - return os.path.join(prefix, "include", "python" + get_python_version()) + incdir = os.path.join(get_config_var('srcdir'), 'Include') + return os.path.normpath(incdir) + else: + return os.path.join(prefix, "include", "python" + + get_python_version()) elif os.name == "nt": return os.path.join(prefix, "include") elif os.name == "mac":