diff options
author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-03-30 19:11:21 +0200 |
---|---|---|
committer | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-05-22 13:17:36 +0200 |
commit | 56bd73b26d379f1423ae8816941018c6a48c0ef7 (patch) | |
tree | 1471fbb37c61029bed4b5fd111f4ee2fea250daf | |
parent | badfe739c61dd6f3609b4e3854519cfbe663c5a2 (diff) | |
download | python-setuptools-git-56bd73b26d379f1423ae8816941018c6a48c0ef7.tar.gz |
Fix tests
-rw-r--r-- | setuptools/dist.py | 20 | ||||
-rw-r--r-- | setuptools/tests/test_egg_info.py | 10 |
2 files changed, 28 insertions, 2 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py index 71b31873..1eb51ba4 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -96,6 +96,24 @@ def read_pkg_file(self, file): """Reads the metadata values from a file object.""" msg = message_from_file(file) + def _read_long_description(): + value = msg['description'] + if value in ('UNKNOWN', None): + return None + description_lines = value.splitlines() + if len(description_lines) == 1: + return description_lines[0].lstrip() + description_dedent = '\n'.join( + (description_lines[0].lstrip(), + textwrap.dedent('\n'.join(description_lines[1:])))) + return description_dedent + + def _read_payload(): + value = msg.get_payload().strip() + if value == 'UNKNOWN': + return None + return value + self.metadata_version = StrictVersion(msg['metadata-version']) self.name = _read_field_from_msg(msg, 'name') self.version = _read_field_from_msg(msg, 'version') @@ -114,6 +132,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() self.description = _read_field_from_msg(msg, 'summary') if 'keywords' in msg: diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index ba683d08..d0183eef 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -875,9 +875,15 @@ class TestEggInfo: assert expected_line in pkg_info_lines assert 'Metadata-Version: 2.1' in pkg_info_lines - def test_description(self, tmpdir_cwd, env): + 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='This is a long description\\nover multiple lines'," + "long_description_content_type='text/markdown'," + ) environ = os.environ.copy().update( HOME=env.paths['home'], ) |