[Python-checkins] r59386 - in python/trunk/Lib/distutils: sysconfig.py tests/test_sysconfig.py

christian.heimes python-checkins at python.org
Thu Dec 6 14:15:13 CET 2007


Author: christian.heimes
Date: Thu Dec  6 14:15:13 2007
New Revision: 59386

Added:
   python/trunk/Lib/distutils/tests/test_sysconfig.py   (contents, props changed)
Modified:
   python/trunk/Lib/distutils/sysconfig.py
Log:
Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
Added several small unit tests for sysconfig.

Modified: python/trunk/Lib/distutils/sysconfig.py
==============================================================================
--- python/trunk/Lib/distutils/sysconfig.py	(original)
+++ python/trunk/Lib/distutils/sysconfig.py	Thu Dec  6 14:15:13 2007
@@ -22,16 +22,17 @@
 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
+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))
+
 # 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.
-
-argv0_path = os.path.dirname(os.path.abspath(sys.executable))
-landmark = os.path.join(argv0_path, "Modules", "Setup")
-
-python_build = os.path.isfile(landmark)
-
-del landmark
+python_build = os.path.isfile(os.path.join(project_base, "Modules",
+                                           "Setup.dist"))
 
 
 def get_python_version():
@@ -185,7 +186,10 @@
 def get_config_h_filename():
     """Return full pathname of installed pyconfig.h file."""
     if python_build:
-        inc_dir = argv0_path
+        if os.name == "nt":
+            inc_dir = os.path.join(project_base, "PC")
+        else:
+            inc_dir = project_base
     else:
         inc_dir = get_python_inc(plat_specific=1)
     if get_python_version() < '2.2':
@@ -428,6 +432,8 @@
 
     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

Added: python/trunk/Lib/distutils/tests/test_sysconfig.py
==============================================================================
--- (empty file)
+++ python/trunk/Lib/distutils/tests/test_sysconfig.py	Thu Dec  6 14:15:13 2007
@@ -0,0 +1,36 @@
+"""Tests for distutils.dist."""
+
+from distutils import sysconfig
+import os
+import sys
+import unittest
+
+from test.test_support import TESTFN
+
+class SysconfigTestCase(unittest.TestCase):
+
+    def test_get_config_h_filename(self):
+        config_h = sysconfig.get_config_h_filename()
+        self.assert_(os.path.isfile(config_h), config_h)
+
+    def test_get_python_lib(self):
+        lib_dir = sysconfig.get_python_lib()
+        self.assert_(os.path.isdir(lib_dir), lib_dir)
+        # test for pythonxx.lib?
+
+    def test_get_python_inc(self):
+        inc_dir = sysconfig.get_python_inc()
+        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)
+
+    def test_get_config_vars(self):
+        cvars = sysconfig.get_config_vars()
+        self.assert_(isinstance(cvars, dict))
+        self.assert_(cvars)
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(SysconfigTestCase))
+    return suite


More information about the Python-checkins mailing list