Skip to content

Commit

Permalink
Check for empty description when converting metadata (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
intentionally-left-nil authored Jan 5, 2025
1 parent 426b8dd commit edb5f7a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
5 changes: 5 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release Notes
=============

**UNRELEASED**

- Fixed an exception when calling the ``convert`` command with an empty description
field

**0.45.1 (2024-11-23)**

- Fixed pure Python wheels converted from eggs and wininst files having the ABI tag in
Expand Down
16 changes: 10 additions & 6 deletions src/wheel/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ def convert_pkg_info(pkginfo: str, metadata: Message):

if key_lower == "description":
description_lines = value.splitlines()
value = "\n".join(
(
description_lines[0].lstrip(),
dedent("\n".join(description_lines[1:])),
"\n",
if description_lines:
value = "\n".join(
(
description_lines[0].lstrip(),
dedent("\n".join(description_lines[1:])),
"\n",
)
)
)
else:
value = "\n"

metadata.set_payload(value)
elif key_lower == "home-page":
metadata.add_header("Project-URL", f"Homepage, {value}")
Expand Down
32 changes: 31 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,32 @@ 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 edb5f7a

Please sign in to comment.