Skip to content

Commit

Permalink
Enforce single line description (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Apr 17, 2024
1 parent 1d06639 commit 2cc3932
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/pyproject_fmt/formatter/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .config import Config

_PY_MIN_VERSION: int = 7
_ANY_WHITESPACE = re.compile(r"\s+")


def fmt_project(parsed: TOMLDocument, conf: Config) -> None: # noqa: C901
Expand All @@ -40,7 +41,9 @@ def fmt_project(parsed: TOMLDocument, conf: Config) -> None: # noqa: C901
assert isinstance(name, str) # noqa: S101
project["name"] = canonicalize_name(name)
if "description" in project:
project["description"] = String.from_raw(str(project["description"]).strip())
# Convert multiline description to a single line
_description = _ANY_WHITESPACE.sub(" ", str(project["description"]).strip())
project["description"] = String.from_raw(_description, escape=False)

sorted_array(cast(Optional[Array], project.get("keywords")), indent=conf.indent)
sorted_array(cast(Optional[Array], project.get("dynamic")), indent=conf.indent)
Expand Down
13 changes: 13 additions & 0 deletions tests/formatter/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ def test_project_description(fmt: Fmt) -> None:
fmt(fmt_project, start, expected)


def test_project_description_multiline(fmt: Fmt) -> None:
start = dedent('''\
[project]
description="""A multi-line
description."""
''')
expected = dedent("""\
[project]
description="A multi-line description."
""")
fmt(fmt_project, start, expected)


def test_project_scripts(fmt: Fmt) -> None:
start = """
[project.scripts]
Expand Down

0 comments on commit 2cc3932

Please sign in to comment.