Skip to content

Commit

Permalink
Fail on a multiline distribution package summary
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Nov 11, 2021
1 parent 0765143 commit f8fe4a8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ def read_pkg_file(self, file):
self.license_files = _read_list_from_msg(msg, 'license-file')


def single_line(val):
# quick and dirty validation for description pypa/setuptools#1390
def ensure_summary_single_line(val):
"""Validate that the summary does not have line breaks."""
# Ref: https://github.com/pypa/setuptools/issues/1390
if '\n' in val:
# TODO after 2021-07-31: Replace with `raise ValueError("newlines not allowed")`
warnings.warn("newlines not allowed and will break in the future")
val = val.replace('\n', ' ')
raise ValueError(
'Newlines in the package distribution summary are not allowed',
)

return val


Expand All @@ -164,7 +166,7 @@ def write_field(key, value):
write_field('Metadata-Version', str(version))
write_field('Name', self.get_name())
write_field('Version', self.get_version())
write_field('Summary', single_line(self.get_description()))
write_field('Summary', ensure_summary_single_line(self.get_description()))
write_field('Home-page', self.get_url())

optional_fields = (
Expand Down

0 comments on commit f8fe4a8

Please sign in to comment.