Skip to content

Commit

Permalink
Check for empty description when converting metadata
Browse files Browse the repository at this point in the history
To prevent an exception, check for an empty description Fixes: #645
  • Loading branch information
intentionally-left-nil committed Jan 3, 2025
1 parent 426b8dd commit a89b9f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/wheel/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def convert_pkg_info(pkginfo: str, metadata: Message):

if key_lower == "description":
description_lines = value.splitlines()
value = "\n".join(
if len(description_lines) == 0:
value = '\n'
else:
value = "\n".join(
(
description_lines[0].lstrip(),
dedent("\n".join(description_lines[1:])),
Expand Down
30 changes: 29 additions & 1 deletion tests/cli/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os.path
import zipfile
from email.message import Message
from pathlib import Path
from textwrap import dedent

Expand All @@ -10,7 +11,7 @@
from pytest import CaptureFixture, TempPathFactory

import wheel
from wheel.cli.convert import convert, egg_filename_re
from wheel.cli.convert import convert, convert_pkg_info, egg_filename_re
from wheel.wheelfile import WheelFile

PKG_INFO = """\
Expand Down Expand Up @@ -262,3 +263,30 @@ def test_convert_bdist_wininst(
assert wf.read("sampledist-1.0.0.dist-info/entry_points.txt") == b""

assert capsys.readouterr().out == f"{bdist_wininst_path}...OK\n"

def test_convert_pkg_info_with_empty_description():
# Regression test for https://github.com/pypa/wheel/issues/645
pkginfo = """\
Metadata-Version: 2.1
Name: Sampledist
Version: 1.0.0
Home-page: https://example.com
Download-URL: https://example.com/sampledist
Description:"""
message = Message()
convert_pkg_info(pkginfo, message)
assert message.get_all('Name') == ['Sampledist']
assert message.get_payload() == '\n'

def test_convert_pkg_info_with_one_line_description():
pkginfo = """\
Metadata-Version: 2.1
Name: Sampledist
Version: 1.0.0
Home-page: https://example.com
Download-URL: https://example.com/sampledist
Description: My cool package"""
message = Message()
convert_pkg_info(pkginfo, message)
assert message.get_all('Name') == ['Sampledist']
assert message.get_payload() == 'My cool package\n\n\n'

0 comments on commit a89b9f7

Please sign in to comment.