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 | |
| 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
| -rw-r--r-- | setuptools/config.py | 30 | ||||
| -rw-r--r-- | setuptools/tests/test_config.py | 10 |
2 files changed, 21 insertions, 19 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, } diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py index 95ae60b2..d81d4288 100644 --- a/setuptools/tests/test_config.py +++ b/setuptools/tests/test_config.py @@ -144,11 +144,7 @@ class TestMetadata: fake_env( tmpdir, '[metadata]\n' - 'long_description =\n' - ' Some normal line\n' - ' file: README.rst\n' - ' Another line\n' - ' file: CHANGES.rst\n' + 'long_description = file: README.rst, CHANGES.rst\n' '\n' ) @@ -157,9 +153,7 @@ class TestMetadata: with get_dist(tmpdir) as dist: assert dist.metadata.long_description == ( - 'Some normal line\n' 'readme contents\nline2\n' - 'Another line\n' 'changelog contents\nand stuff' ) @@ -168,7 +162,7 @@ class TestMetadata: fake_env( tmpdir, '[metadata]\n' - 'long_description = file: ../../README\n' + 'long_description = file: CHANGES.rst, ../../README\n' ) with get_dist(tmpdir, parse=False) as dist: |
