Skip to content

Commit

Permalink
fix: warn on multiline Summary (project.description) (#162)
Browse files Browse the repository at this point in the history
* fix: warn on multiline Summary (project.description)

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Update pyproject_metadata/__init__.py

* Update test_standard_metadata.py

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Sep 20, 2024
1 parent 945d626 commit 06138ee
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ extend-select = [
ignore = ["ISC001"] # conflicts with formatter
isort.lines-after-imports = 2
isort.lines-between-types = 1
pylint.max-branches = 25

[tool.ruff.format]
quote-style = "single"
Expand Down
31 changes: 19 additions & 12 deletions pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def get_license_files(self, project_dir: pathlib.Path) -> list[pathlib.Path] | N

return list(_get_files_from_globs(project_dir, license_files))

def get_readme(self, project_dir: pathlib.Path) -> Readme | None: # noqa: C901
def get_readme(self, project_dir: pathlib.Path) -> Readme | None: # noqa: C901, PLR0912
if 'project.readme' not in self:
return None

Expand Down Expand Up @@ -543,7 +543,7 @@ def __setattr__(self, name: str, value: Any) -> None:
raise AttributeError(msg)
super().__setattr__(name, value)

def validate(self, *, warn: bool = True) -> None:
def validate(self, *, warn: bool = True) -> None: # noqa: C901
if self.auto_metadata_version not in KNOWN_METADATA_VERSIONS:
msg = f'The metadata_version must be one of {KNOWN_METADATA_VERSIONS} or None (default)'
raise ConfigurationError(msg)
Expand All @@ -569,19 +569,26 @@ def validate(self, *, warn: bool = True) -> None:
msg = 'Setting "project.license" to an SPDX license expression is not compatible with "License ::" classifiers'
raise ConfigurationError(msg)

if warn and self.auto_metadata_version not in PRE_SPDX_METADATA_VERSIONS:
if isinstance(self.license, License):
if warn:
if self.description and '\n' in self.description:
warnings.warn(
'Set "project.license" to an SPDX license expression for metadata >= 2.4',
ConfigurationWarning,
stacklevel=2,
)
elif any(c.startswith('License ::') for c in self.classifiers):
warnings.warn(
'"License ::" classifiers are deprecated for metadata >= 2.4, use a SPDX license expression for "project.license" instead',
'The one-line summary "project.description" should not contain more than one line. Readers might merge or truncate newlines.',
ConfigurationWarning,
stacklevel=2,
)
if self.auto_metadata_version not in PRE_SPDX_METADATA_VERSIONS:
if isinstance(self.license, License):
warnings.warn(
'Set "project.license" to an SPDX license expression for metadata >= 2.4',
ConfigurationWarning,
stacklevel=2,
)
elif any(c.startswith('License ::') for c in self.classifiers):
warnings.warn(
'"License ::" classifiers are deprecated for metadata >= 2.4, use a SPDX license expression for "project.license" instead',
ConfigurationWarning,
stacklevel=2,
)

if (
isinstance(self.license, str)
Expand Down Expand Up @@ -701,7 +708,7 @@ def as_rfc822(self) -> RFC822Message:
self.write_to_rfc822(message)
return message

def write_to_rfc822(self, message: email.message.Message) -> None: # noqa: C901
def write_to_rfc822(self, message: email.message.Message) -> None: # noqa: C901, PLR0912
self.validate(warn=False)

smart_message = _SmartMessageSetter(message)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_standard_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,3 +1150,21 @@ def test_extra_build_system() -> None:
}
}
)


def test_multiline_description_warns() -> None:
with pytest.warns(
pyproject_metadata.ConfigurationWarning,
match=re.escape(
'The one-line summary "project.description" should not contain more than one line. Readers might merge or truncate newlines.'
),
):
pyproject_metadata.StandardMetadata.from_pyproject(
{
'project': {
'name': 'example',
'version': '1.2.3',
'description': 'this\nis multiline',
},
}
)

0 comments on commit 06138ee

Please sign in to comment.