Modified:
branches/release-2009Q1-maint/ (props changed)
branches/release-2009Q1-maint/Lib/distutils/sysconfig.py
branches/release-2009Q1-maint/Lib/distutils/tests/test_build_ext.py
branches/release-2009Q1-maint/Lib/distutils/tests/test_sysconfig.py
Log:
Backport r565. This allows test_distutils to pass when run from an obj dir.
Modified: branches/release-2009Q1-maint/Lib/distutils/sysconfig.py
==============================================================================
--- branches/release-2009Q1-maint/Lib/distutils/sysconfig.py (original)
+++ branches/release-2009Q1-maint/Lib/distutils/sysconfig.py Fri May 15
19:27:50 2009
@@ -73,14 +73,17 @@
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:
- inc_dir = base
+ return base
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
+ 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")
@@ -528,6 +531,9 @@
# Distutils.
_config_vars['prefix'] = PREFIX
_config_vars['exec_prefix'] = EXEC_PREFIX
+
+ if 'srcdir' not in _config_vars:
+ _config_vars['srcdir'] = project_base
if sys.platform == 'darwin':
kernel_version = os.uname()[2] # Kernel version (8.4.3)
Modified:
branches/release-2009Q1-maint/Lib/distutils/tests/test_build_ext.py
==============================================================================
--- branches/release-2009Q1-maint/Lib/distutils/tests/test_build_ext.py
(original)
+++ branches/release-2009Q1-maint/Lib/distutils/tests/test_build_ext.py Fri
May 15 19:27:50 2009
@@ -11,6 +11,10 @@
import unittest
from test import test_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,9 +22,7 @@
self.tmp_dir = tempfile.mkdtemp(prefix="pythontest_")
self.sys_path = sys.path[:]
sys.path.append(self.tmp_dir)
-
- xx_c =
os.path.join(sysconfig.project_base, 'Modules', 'xxmodule.c')
- shutil.copy(xx_c, self.tmp_dir)
+ shutil.copy(_get_source_filename(), self.tmp_dir)
def test_build_ext(self):
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
@@ -66,9 +68,11 @@
shutil.rmtree(self.tmp_dir, os.name == 'nt' or sys.platform
== 'cygwin')
def test_suite():
- if not sysconfig.python_build:
+ src = _get_source_filename()
+ if not os.path.exists(src):
if test_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)
Modified:
branches/release-2009Q1-maint/Lib/distutils/tests/test_sysconfig.py
==============================================================================
--- branches/release-2009Q1-maint/Lib/distutils/tests/test_sysconfig.py
(original)
+++ branches/release-2009Q1-maint/Lib/distutils/tests/test_sysconfig.py Fri
May 15 19:27:50 2009
@@ -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)