diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2017-08-28 09:44:20 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-28 09:44:20 -0400 |
| commit | fffd844b4523a0708c43126174360aaf7baa5fd0 (patch) | |
| tree | 526a0501545491ad910799994529b939367e38bd | |
| parent | 60cfeeacd34da6eb3881808f556ae4b194b60c73 (diff) | |
| parent | 9e708961e7fa64e56c9469ca52163d7e2df31477 (diff) | |
| download | python-setuptools-git-fffd844b4523a0708c43126174360aaf7baa5fd0.tar.gz | |
Merge pull request #1131 from webknjaz/feature/long-desc-few-files
Allow combining several files in metadata.long_description
| -rw-r--r-- | CHANGES.rst | 6 | ||||
| -rw-r--r-- | docs/setuptools.txt | 4 | ||||
| -rw-r--r-- | setuptools/config.py | 34 | ||||
| -rw-r--r-- | setuptools/tests/test_config.py | 18 |
4 files changed, 46 insertions, 16 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 19afc8cb..1392e2a6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v36.3.0 +------- + +* #1131: Make possible using several files within ``file:`` directive + in metadata.long_description in ``setup.cfg``. + v36.2.7 ------- diff --git a/docs/setuptools.txt b/docs/setuptools.txt index eb9fdbd3..45d746d2 100644 --- a/docs/setuptools.txt +++ b/docs/setuptools.txt @@ -2306,7 +2306,7 @@ boilerplate code in some cases. name = my_package version = attr: src.VERSION description = My package description - long_description = file: README.rst + long_description = file: README.rst, CHANGELOG.rst, LICENSE.rst keywords = one, two license = BSD 3-Clause License classifiers = @@ -2379,7 +2379,7 @@ Type names used below: Special directives: * ``attr:`` - value could be read from module attribute -* ``file:`` - value could be read from a file +* ``file:`` - value could be read from a list of files and then concatenated .. note:: 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( |
