Commit b699f947 authored by Sviatoslav Sydorenko's avatar Sviatoslav Sydorenko

Support list of files passed to `file:` directive

* `file:` not accepts comma-separated list of filenames
* files' contents are glues with an LF separator
parent 30bf0a41
......@@ -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,
}
......
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment