diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2021-05-22 19:27:14 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-22 19:27:14 -0400 |
| commit | 18d751da77750abdefa2868c19a19bd031502311 (patch) | |
| tree | 82b92690247d4f9021d26df80ace73bc177feb0f /setuptools | |
| parent | c6a761fd4dd86283f25d828c7b9b56d764dcf84b (diff) | |
| parent | 34c31ebe437edf9d6d4ee5010461668156793569 (diff) | |
| download | python-setuptools-git-18d751da77750abdefa2868c19a19bd031502311.tar.gz | |
Merge pull request #2628 from cdce8p/long-desc
Write long description in message payload
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/dist.py | 14 | ||||
| -rw-r--r-- | setuptools/tests/test_dist.py | 4 | ||||
| -rw-r--r-- | setuptools/tests/test_egg_info.py | 23 |
3 files changed, 36 insertions, 5 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py index a1b7e832..bf3b9461 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -92,6 +92,13 @@ def _read_list_from_msg(msg: "Message", field: str) -> Optional[List[str]]: return values +def _read_payload_from_msg(msg: "Message") -> Optional[str]: + value = msg.get_payload().strip() + if value == 'UNKNOWN': + return None + return value + + def read_pkg_file(self, file): """Reads the metadata values from a file object.""" msg = message_from_file(file) @@ -114,6 +121,8 @@ def read_pkg_file(self, file): self.download_url = None self.long_description = _read_field_unescaped_from_msg(msg, 'description') + if self.long_description is None and self.metadata_version >= StrictVersion('2.1'): + self.long_description = _read_payload_from_msg(msg) self.description = _read_field_from_msg(msg, 'summary') if 'keywords' in msg: @@ -176,9 +185,6 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME for project_url in self.project_urls.items(): write_field('Project-URL', '%s, %s' % project_url) - long_desc = rfc822_escape(self.get_long_description()) - write_field('Description', long_desc) - keywords = ','.join(self.get_keywords()) if keywords: write_field('Keywords', keywords) @@ -207,6 +213,8 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME for extra in self.provides_extras: write_field('Provides-Extra', extra) + file.write("\n%s\n\n" % self.get_long_description()) + sequence = tuple, list diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index 6378caef..c4279f0b 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -251,8 +251,8 @@ def test_maintainer_author(name, attrs, tmpdir): with io.open(str(fn.join('PKG-INFO')), 'r', encoding='utf-8') as f: raw_pkg_lines = f.readlines() - # Drop blank lines - pkg_lines = list(filter(None, raw_pkg_lines)) + # Drop blank lines and strip lines from default description + pkg_lines = list(filter(None, raw_pkg_lines[:-2])) pkg_lines_set = set(pkg_lines) diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 0d595ad0..d7657a47 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -875,6 +875,29 @@ class TestEggInfo: assert expected_line in pkg_info_lines assert 'Metadata-Version: 2.1' in pkg_info_lines + def test_long_description(self, tmpdir_cwd, env): + # Test that specifying `long_description` and `long_description_content_type` + # keyword args to the `setup` function results in writing + # the description in the message payload of the `PKG-INFO` file + # in the `<distribution>.egg-info` directory. + self._setup_script_with_requires( + "long_description='This is a long description\\nover multiple lines'," + "long_description_content_type='text/markdown'," + ) + code, data = environment.run_setup_py( + cmd=['egg_info'], + pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), + data_stream=1, + ) + egg_info_dir = os.path.join('.', 'foo.egg-info') + with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file: + pkg_info_lines = pkginfo_file.read().split('\n') + assert 'Metadata-Version: 2.1' in pkg_info_lines + assert '' == pkg_info_lines[-1] # last line should be empty + long_desc_lines = pkg_info_lines[pkg_info_lines.index(''):] + assert 'This is a long description' in long_desc_lines + assert 'over multiple lines' in long_desc_lines + def test_project_urls(self, tmpdir_cwd, env): # Test that specifying a `project_urls` dict to the `setup` # function results in writing multiple `Project-URL` lines to |
