Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Apr 3, 2021
1 parent 75b2f94 commit 5a502a2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
32 changes: 24 additions & 8 deletions setuptools/dist.py
Expand Up @@ -16,6 +16,7 @@
from distutils.debug import DEBUG
from distutils.fancy_getopt import translate_longopt
import itertools
import textwrap

from collections import defaultdict
from email import message_from_file
Expand Down Expand Up @@ -49,11 +50,7 @@ def get_metadata_version(self):
mv = getattr(self, 'metadata_version', None)

if mv is None:
if (
self.long_description_content_type
or self.provides_extras
or self.long_description
):
if self.long_description_content_type or self.provides_extras:
mv = StrictVersion('2.1')
elif (self.maintainer is not None or
self.maintainer_email is not None or
Expand All @@ -71,7 +68,7 @@ def get_metadata_version(self):
return mv


def read_pkg_file(self, file):
def read_pkg_file(self, file): # noqa: C901
"""Reads the metadata values from a file object."""
msg = message_from_file(file)

Expand All @@ -87,6 +84,24 @@ def _read_list(name):
return None
return values

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('name')
self.version = _read_field('version')
Expand All @@ -104,8 +119,9 @@ def _read_list(name):
else:
self.download_url = None

self.long_description = _read_field('description')
self.description = _read_field('summary')
self.long_description = _read_long_description()
if self.long_description is None and self.metadata_version >= StrictVersion('2.1'):
self.long_description = _read_payload()

if 'keywords' in msg:
self.keywords = _read_field('keywords').split(',')
Expand Down
4 changes: 4 additions & 0 deletions setuptools/tests/test_dist.py
Expand Up @@ -85,6 +85,9 @@ def __read_test_cases():
('Metadata version 1.1: Provides', params(
provides=['package'],
)),
('Metadata Version 1.0: Short long description', params(
long_description='Short long description',
)),
('Metadata version 1.1: Obsoletes', params(
obsoletes=['foo'],
)),
Expand Down Expand Up @@ -162,6 +165,7 @@ def test_read_metadata(name, attrs):
('metadata_version', dist_class.get_metadata_version),
('provides', dist_class.get_provides),
('description', dist_class.get_description),
('long_description', dist_class.get_long_description),
('download_url', dist_class.get_download_url),
('keywords', dist_class.get_keywords),
('platforms', dist_class.get_platforms),
Expand Down
10 changes: 8 additions & 2 deletions setuptools/tests/test_egg_info.py
Expand Up @@ -855,9 +855,15 @@ def test_long_description_content_type(self, tmpdir_cwd, env):
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'],
)
Expand Down

0 comments on commit 5a502a2

Please sign in to comment.