[Python-checkins] distutils2: Minor improvement to extensions in setup.cfg: check parent package
eric.araujo
python-checkins at python.org
Mon Sep 19 15:12:39 CEST 2011
http://hg.python.org/distutils2/rev/8da735d33a06
changeset: 1171:8da735d33a06
user: Éric Araujo <merwok at netwok.org>
date: Mon Sep 19 04:17:33 2011 +0200
summary:
Minor improvement to extensions in setup.cfg: check parent package
files:
distutils2/config.py | 17 +++++++++++-
distutils2/tests/test_config.py | 30 +++++++++++++++++++-
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/distutils2/config.py b/distutils2/config.py
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -17,6 +17,19 @@
from distutils2.markers import interpret
+def _check_name(name, packages):
+ if '.' not in name:
+ return
+ parts = name.split('.')
+ modname = parts[-1]
+ parent = '.'.join(parts[:-1])
+ if parent not in packages:
+ # we could log a warning instead of raising, but what's the use
+ # of letting people build modules they can't import?
+ raise PackagingOptionError(
+ 'parent package for extension %r not found' % name)
+
+
def _pop_values(values_dct, key):
"""Remove values from the dictionary and convert them as a list"""
vals_str = values_dct.pop(key, '')
@@ -265,8 +278,10 @@
raise PackagingOptionError(
'extension name should be given as [extension: name], '
'not as key')
+ name = labels[1].strip()
+ _check_name(name, self.dist.packages)
ext_modules.append(Extension(
- labels[1].strip(),
+ name,
_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
@@ -106,6 +106,7 @@
[files]
packages = one
two
+ parent.undeclared
[extension:one.speed_coconuts]
sources = c_src/speed_coconuts.c
@@ -124,6 +125,10 @@
/DGECODE_VERSION='win32' -- sys.platform == 'win32'
language = cxx
+# corner case: if the parent package of an extension is declared but
+# not its grandparent, it's legal
+[extension: parent.undeclared._speed]
+sources = parent/undeclared/_speed.c
"""
EXT_SETUP_CFG_BUGGY_1 = """
@@ -131,6 +136,21 @@
name = crash_here
"""
+EXT_SETUP_CFG_BUGGY_2 = """
+[files]
+packages = ham
+
+[extension: spam.eggs]
+"""
+
+EXT_SETUP_CFG_BUGGY_3 = """
+[files]
+packages = ok
+ ok.works
+
+[extension: ok.works.breaks._ext]
+"""
+
HOOKS_MODULE = """
import logging
@@ -316,7 +336,7 @@
dist = self.get_dist()
ext_modules = dict((mod.name, mod) for mod in dist.ext_modules)
- self.assertEqual(len(ext_modules), 2)
+ self.assertEqual(len(ext_modules), 3)
ext = ext_modules.get('one.speed_coconuts')
self.assertEqual(ext.sources, ['c_src/speed_coconuts.c'])
self.assertEqual(ext.define_macros, ['HAVE_CAIRO', 'HAVE_GTK2'])
@@ -343,6 +363,12 @@
self.write_file('setup.cfg', EXT_SETUP_CFG_BUGGY_1)
self.assertRaises(PackagingOptionError, self.get_dist)
+ self.write_file('setup.cfg', EXT_SETUP_CFG_BUGGY_2)
+ self.assertRaises(PackagingOptionError, self.get_dist)
+
+ self.write_file('setup.cfg', EXT_SETUP_CFG_BUGGY_3)
+ 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
@@ -366,7 +392,7 @@
self.write_setup({
'setup-hooks': '\n distutils2.tests.test_config.first_hook'
'\n distutils2.tests.test_config.missing_hook'
- '\n distutils2.tests.test_config.third_hook'
+ '\n distutils2.tests.test_config.third_hook',
})
self.write_file('README', 'yeah')
dist = self.get_dist()
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list