summaryrefslogtreecommitdiff
path: root/setuptools/config.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-08-28 09:44:20 -0400
committerGitHub <noreply@github.com>2017-08-28 09:44:20 -0400
commitfffd844b4523a0708c43126174360aaf7baa5fd0 (patch)
tree526a0501545491ad910799994529b939367e38bd /setuptools/config.py
parent60cfeeacd34da6eb3881808f556ae4b194b60c73 (diff)
parent9e708961e7fa64e56c9469ca52163d7e2df31477 (diff)
downloadpython-setuptools-git-fffd844b4523a0708c43126174360aaf7baa5fd0.tar.gz
Merge pull request #1131 from webknjaz/feature/long-desc-few-files
Allow combining several files in metadata.long_description
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):