summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/config.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-09-01 05:01:13 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-09-01 05:01:13 (GMT)
commitd9299e97ab9ff7fa8f158740be61572e04a936fa (patch)
tree95aa72197d836016e9398145ef209fb97f28be00 /Lib/packaging/config.py
parent336b4e4ff3edea750eb79bc59dab0f63141a1caa (diff)
downloadcpython-d9299e97ab9ff7fa8f158740be61572e04a936fa.zip
cpython-d9299e97ab9ff7fa8f158740be61572e04a936fa.tar.gz
cpython-d9299e97ab9ff7fa8f158740be61572e04a936fa.tar.bz2
Minor improvement to extensions in setup.cfg: check parent package
Diffstat (limited to 'Lib/packaging/config.py')
-rw-r--r--Lib/packaging/config.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/Lib/packaging/config.py b/Lib/packaging/config.py
index b138d08..e02800e 100644
--- a/Lib/packaging/config.py
+++ b/Lib/packaging/config.py
@@ -16,6 +16,19 @@ from packaging.command import set_command
from packaging.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, '')
@@ -142,7 +155,8 @@ class Config:
try:
hook = resolve_name(line)
except ImportError as e:
- logger.warning('cannot find setup hook: %s', e.args[0])
+ logger.warning('cannot find setup hook: %s',
+ e.args[0])
else:
self.setup_hooks.append(hook)
self.run_hooks(content)
@@ -259,8 +273,10 @@ class Config:
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'),