diff options
| author | Sviatoslav Sydorenko <wk@sydorenko.org.ua> | 2017-08-28 10:22:21 +0300 |
|---|---|---|
| committer | Sviatoslav Sydorenko <wk@sydorenko.org.ua> | 2017-08-28 10:22:21 +0300 |
| commit | b699f94728c82691bed9b67a48b170951535fa38 (patch) | |
| tree | 61dc2ca4ca08de24b35f4b51b5f7cff34d0b989d /setuptools/config.py | |
| parent | 30bf0a41e410d17d118fd9bdf9385f035871951e (diff) | |
| download | external_python_setuptools-b699f94728c82691bed9b67a48b170951535fa38.tar.gz external_python_setuptools-b699f94728c82691bed9b67a48b170951535fa38.tar.bz2 external_python_setuptools-b699f94728c82691bed9b67a48b170951535fa38.zip | |
Support list of files passed to `file:` directive
* `file:` not accepts comma-separated list of filenames
* files' contents are glues with an LF separator
Diffstat (limited to 'setuptools/config.py')
| -rw-r--r-- | setuptools/config.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/setuptools/config.py b/setuptools/config.py index 4d3eff93..b6627c80 100644 --- a/setuptools/config.py +++ b/setuptools/config.py @@ -246,30 +246,38 @@ class ConfigHandler(object): Examples: file: LICENSE - file: src/file.txt + file: README.rst, CHANGELOG.md, src/file.txt :param str value: :rtype: str """ + include_directive = 'file:' + file_contents = [] + if not isinstance(value, string_types): return value - include_directive = 'file:' if not value.startswith(include_directive): return value + filepaths = value[len(include_directive):] + filepaths = filepaths.split(',') + filepaths = map(str.strip, filepaths) + filepaths = map(os.path.abspath, filepaths) + current_directory = os.getcwd() - filepath = value.replace(include_directive, '').strip() - filepath = os.path.abspath(filepath) + for filepath in filepaths: + if not filepath.startswith(current_directory): + raise DistutilsOptionError( + '`file:` directive can not access %s' % filepath) - if not filepath.startswith(current_directory): - raise DistutilsOptionError( - '`file:` directive can not access %s' % filepath) + if os.path.isfile(filepath): + with io.open(filepath, encoding='utf-8') as f: + file_contents.append(f.read()) - if os.path.isfile(filepath): - with io.open(filepath, encoding='utf-8') as f: - value = f.read() + if file_contents: + value = '\n'.join(file_contents) return value @@ -408,7 +416,7 @@ class ConfigMetadataHandler(ConfigHandler): 'classifiers': self._get_parser_compound(parse_file, parse_list), 'license': parse_file, 'description': parse_file, - 'long_description': self._get_parser_compound(parse_list, lambda l: '\n'.join(map(parse_file, l))), + 'long_description': parse_file, 'version': self._parse_version, } |
