Skip to content

Commit

Permalink
fix: validate description (#76)
Browse files Browse the repository at this point in the history
* fix: validate description

Signed-off-by: Henry Schreiner <[email protected]>

* refactor: address feedback

Signed-off-by: Henry Schreiner <[email protected]>

---------

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Nov 29, 2023
1 parent aa98a68 commit f5e1688
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,15 @@ def from_pyproject(
version_string = fetcher.get_str('project.version')
requires_python_string = fetcher.get_str('project.requires-python')

# Description can't be multiline
description = fetcher.get_str('project.description')
if description and '\n' in description:
raise ConfigurationError('The description must be a single line')

return cls(
name,
packaging.version.Version(version_string) if version_string else None,
fetcher.get_str('project.description'),
description,
cls._get_license(fetcher, project_dir),
cls._get_readme(fetcher, project_dir),
packaging.specifiers.SpecifierSet(requires_python_string) if requires_python_string else None,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_standard_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@
'''),
('Field "project.description" has an invalid type, expecting a string (got "True")'),
),
(
textwrap.dedent('''
[project]
name = 'test'
description = """Multiple
lines."""
'''),
('The description must be a single line'),
),
# dependencies
(
textwrap.dedent('''
Expand Down

0 comments on commit f5e1688

Please sign in to comment.