summaryrefslogtreecommitdiff
path: root/setuptools/dist.py
diff options
context:
space:
mode:
authorDaniel Himmelstein <daniel.himmelstein@gmail.com>2019-05-22 17:45:44 -0400
committerBenoit Pierre <benoit.pierre@gmail.com>2019-07-16 13:20:36 +0200
commit8f848bd777278fc8dcb42dc45751cd8b95ec2a02 (patch)
treed78ada4b85b44d48a3bda0a2a43b4261c4847e89 /setuptools/dist.py
parent305bb1cefc3251c67b55149139a768ddf474f7b6 (diff)
downloadpython-setuptools-git-8f848bd777278fc8dcb42dc45751cd8b95ec2a02.tar.gz
improve `package_data` check
Ensure the dictionary values are lists/tuples of strings. Fix #1459.
Diffstat (limited to 'setuptools/dist.py')
-rw-r--r--setuptools/dist.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 1e1b83be..f0f030b5 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -215,6 +215,10 @@ def check_importable(dist, attr, value):
def assert_string_list(dist, attr, value):
"""Verify that value is a string list"""
try:
+ # verify that value is a list or tuple to exclude unordered
+ # or single-use iterables
+ assert isinstance(value, (list, tuple))
+ # verify that elements of value are strings
assert ''.join(value) != value
except (TypeError, ValueError, AttributeError, AssertionError):
raise DistutilsSetupError(
@@ -307,20 +311,17 @@ def check_test_suite(dist, attr, value):
def check_package_data(dist, attr, value):
"""Verify that value is a dictionary of package names to glob lists"""
- if isinstance(value, dict):
- for k, v in value.items():
- if not isinstance(k, str):
- break
- try:
- iter(v)
- except TypeError:
- break
- else:
- return
- raise DistutilsSetupError(
- attr + " must be a dictionary mapping package names to lists of "
- "wildcard patterns"
- )
+ if not isinstance(value, dict):
+ raise DistutilsSetupError(
+ "{!r} must be a dictionary mapping package names to lists of "
+ "string wildcard patterns".format(attr))
+ for k, v in value.items():
+ if not isinstance(k, six.string_types):
+ raise DistutilsSetupError(
+ "keys of {!r} dict must be strings (got {!r})"
+ .format(attr, k)
+ )
+ assert_string_list(dist, 'values of {!r} dict'.format(attr), v)
def check_packages(dist, attr, value):