[Python-checkins] distutils2: Minor improvement to extensions section in setup.cfg.

eric.araujo python-checkins at python.org
Mon Sep 19 15:12:39 CEST 2011


http://hg.python.org/distutils2/rev/e3168d27daae
changeset:   1170:e3168d27daae
user:        Éric Araujo <merwok at netwok.org>
date:        Mon Sep 19 04:13:44 2011 +0200
summary:
  Minor improvement to extensions section in setup.cfg.

The right-hand part in [extension: foo] is now used as the name of the
extension module.  (I changed the separator from = to : and allowed
whitespace to make the sections look nicer.)

files:
  distutils2/config.py            |  11 +++++++----
  distutils2/tests/test_config.py |  17 ++++++++++++-----
  2 files changed, 19 insertions(+), 9 deletions(-)


diff --git a/distutils2/config.py b/distutils2/config.py
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -257,13 +257,16 @@
 
         ext_modules = self.dist.ext_modules
         for section_key in content:
-            labels = section_key.split('=')
+            # no str.partition in 2.4 :(
+            labels = section_key.split(':')
             if len(labels) == 2 and labels[0] == 'extension':
-                # labels[1] not used from now but should be implemented
-                # for extension build dependency
                 values_dct = content[section_key]
+                if 'name' in values_dct:
+                    raise PackagingOptionError(
+                        'extension name should be given as [extension: name], '
+                        'not as key')
                 ext_modules.append(Extension(
-                    values_dct.pop('name'),
+                    labels[1].strip(),
                     _pop_values(values_dct, 'sources'),
                     _pop_values(values_dct, 'include_dirs'),
                     _pop_values(values_dct, 'define_macros'),
diff --git a/distutils2/tests/test_config.py b/distutils2/tests/test_config.py
--- a/distutils2/tests/test_config.py
+++ b/distutils2/tests/test_config.py
@@ -7,7 +7,7 @@
 
 from distutils2 import command
 from distutils2.dist import Distribution
-from distutils2.errors import PackagingFileError
+from distutils2.errors import PackagingFileError, PackagingOptionError
 from distutils2.compiler import new_compiler, _COMPILERS
 from distutils2.command.sdist import sdist
 
@@ -101,21 +101,20 @@
 
 # Can not be merged with SETUP_CFG else install_dist
 # command will fail when trying to compile C sources
+# TODO use a DummyCommand to mock build_ext
 EXT_SETUP_CFG = """
 [files]
 packages = one
            two
 
-[extension=speed_coconuts]
-name = one.speed_coconuts
+[extension:one.speed_coconuts]
 sources = c_src/speed_coconuts.c
 extra_link_args = "`gcc -print-file-name=libgcc.a`" -shared
 define_macros = HAVE_CAIRO HAVE_GTK2
 libraries = gecodeint gecodekernel -- sys.platform != 'win32'
     GecodeInt GecodeKernel -- sys.platform == 'win32'
 
-[extension=fast_taunt]
-name = two.fast_taunt
+[extension: two.fast_taunt]
 sources = cxx_src/utils_taunt.cxx
           cxx_src/python_module.cxx
 include_dirs = /usr/include/gecode
@@ -127,6 +126,11 @@
 
 """
 
+EXT_SETUP_CFG_BUGGY_1 = """
+[extension: realname]
+name = crash_here
+"""
+
 HOOKS_MODULE = """
 import logging
 
@@ -336,6 +340,9 @@
         self.assertEqual(ext.extra_compile_args, cargs)
         self.assertEqual(ext.language, 'cxx')
 
+        self.write_file('setup.cfg', EXT_SETUP_CFG_BUGGY_1)
+        self.assertRaises(PackagingOptionError, self.get_dist)
+
     def test_project_setup_hook_works(self):
         # Bug #11637: ensure the project directory is on sys.path to allow
         # project-specific hooks

-- 
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list