]> granicus.if.org Git - python/commitdiff
Make test_build_ext.py use sysconfig "srcdir" to find the source for
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>
Fri, 6 Feb 2009 21:42:05 +0000 (21:42 +0000)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>
Fri, 6 Feb 2009 21:42:05 +0000 (21:42 +0000)
xxmodule.c.  Have sysconfig make the srcdir path absolute if that seems
necessary (running non-installed Python outside the build directory).

Lib/distutils/sysconfig.py
Lib/distutils/tests/test_build_ext.py

index 386ae89b83e2420a3a7603cae902d48455ea8a79..a3ef3f6d88a6f1e2e270144574a8835d24f136c7 100644 (file)
@@ -504,6 +504,20 @@ def get_config_vars(*args):
         _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])
index 4c5723255ad39d4d4fb0e9b6d93d58882675504c..5e42943c38b7bf1c6ba80df2fa44ec4c28539da5 100644 (file)
@@ -15,6 +15,10 @@ from test import support
 # Don't load the xx module more than once.
 ALREADY_TESTED = False
 
+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
@@ -22,9 +26,7 @@ class BuildExtTestCase(unittest.TestCase):
         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):
         global ALREADY_TESTED
@@ -97,9 +99,11 @@ class BuildExtTestCase(unittest.TestCase):
         self.assert_(len(cmd.library_dirs) > 0)
 
 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)