diff options
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/config.py | 34 | ||||
| -rw-r--r-- | setuptools/tests/test_config.py | 18 |
2 files changed, 38 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): diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py index dbabd69e..cdfa5af4 100644 --- a/setuptools/tests/test_config.py +++ b/setuptools/tests/test_config.py @@ -139,6 +139,24 @@ class TestMetadata: assert metadata.download_url == 'http://test.test.com/test/' assert metadata.maintainer_email == 'test@test.com' + def test_file_mixed(self, tmpdir): + + fake_env( + tmpdir, + '[metadata]\n' + 'long_description = file: README.rst, CHANGES.rst\n' + '\n' + ) + + tmpdir.join('README.rst').write('readme contents\nline2') + tmpdir.join('CHANGES.rst').write('changelog contents\nand stuff') + + with get_dist(tmpdir) as dist: + assert dist.metadata.long_description == ( + 'readme contents\nline2\n' + 'changelog contents\nand stuff' + ) + def test_file_sandboxed(self, tmpdir): fake_env( |
