]> granicus.if.org Git - python/commitdiff
Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig...
authorChristian Heimes <christian@cheimes.de>
Thu, 6 Dec 2007 13:15:13 +0000 (13:15 +0000)
committerChristian Heimes <christian@cheimes.de>
Thu, 6 Dec 2007 13:15:13 +0000 (13:15 +0000)
Added several small unit tests for sysconfig.

Lib/distutils/sysconfig.py
Lib/distutils/tests/test_sysconfig.py [new file with mode: 0644]

index 0cfafab99b4578034cbb2c086916f49ad9134b75..2ea7c78b8397d3aa332ab4009ade2593f04ef8cb 100644 (file)
@@ -22,16 +22,17 @@ from distutils.errors import DistutilsPlatformError
 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 customize_compiler(compiler):
 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 @@ def _init_nt():
 
     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
diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py
new file mode 100644 (file)
index 0000000..8337b0d
--- /dev/null
@@ -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