summaryrefslogtreecommitdiff
path: root/setuptools/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/config.py')
-rw-r--r--setuptools/config.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/setuptools/config.py b/setuptools/config.py
index 06a61d16..9a62e2ec 100644
--- a/setuptools/config.py
+++ b/setuptools/config.py
@@ -245,33 +245,39 @@ class ConfigHandler(object):
directory with setup.py.
Examples:
- include: LICENSE
- include: src/file.txt
+ file: LICENSE
+ file: README.rst, CHANGELOG.md, src/file.txt
:param str value:
:rtype: str
"""
+ include_directive = 'file:'
+
if not isinstance(value, string_types):
return value
- include_directive = 'file:'
if not value.startswith(include_directive):
return value
- current_directory = os.getcwd()
-
- filepath = value.replace(include_directive, '').strip()
- filepath = os.path.abspath(filepath)
-
- if not filepath.startswith(current_directory):
+ spec = value[len(include_directive):]
+ filepaths = (os.path.abspath(path.strip()) for path in spec.split(','))
+ return '\n'.join(
+ cls._read_file(path)
+ for path in filepaths
+ if (cls._assert_local(path) or True)
+ and os.path.isfile(path)
+ )
+
+ @staticmethod
+ def _assert_local(filepath):
+ if not filepath.startswith(os.getcwd()):
raise DistutilsOptionError(
'`file:` directive can not access %s' % filepath)
- if os.path.isfile(filepath):
- with io.open(filepath, encoding='utf-8') as f:
- value = f.read()
-
- return value
+ @staticmethod
+ def _read_file(filepath):
+ with io.open(filepath, encoding='utf-8') as f:
+ return f.read()
@classmethod
def _parse_attr(cls, value):