Skip to content

Commit 06138ee

Browse files
authored
fix: warn on multiline Summary (project.description) (#162)
* fix: warn on multiline Summary (project.description) Signed-off-by: Henry Schreiner <[email protected]> * Update pyproject_metadata/__init__.py * Update test_standard_metadata.py --------- Signed-off-by: Henry Schreiner <[email protected]>
1 parent 945d626 commit 06138ee

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ extend-select = [
8888
ignore = ["ISC001"] # conflicts with formatter
8989
isort.lines-after-imports = 2
9090
isort.lines-between-types = 1
91-
pylint.max-branches = 25
9291

9392
[tool.ruff.format]
9493
quote-style = "single"

pyproject_metadata/__init__.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def get_license_files(self, project_dir: pathlib.Path) -> list[pathlib.Path] | N
338338

339339
return list(_get_files_from_globs(project_dir, license_files))
340340

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

@@ -543,7 +543,7 @@ def __setattr__(self, name: str, value: Any) -> None:
543543
raise AttributeError(msg)
544544
super().__setattr__(name, value)
545545

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

572-
if warn and self.auto_metadata_version not in PRE_SPDX_METADATA_VERSIONS:
573-
if isinstance(self.license, License):
572+
if warn:
573+
if self.description and '\n' in self.description:
574574
warnings.warn(
575-
'Set "project.license" to an SPDX license expression for metadata >= 2.4',
576-
ConfigurationWarning,
577-
stacklevel=2,
578-
)
579-
elif any(c.startswith('License ::') for c in self.classifiers):
580-
warnings.warn(
581-
'"License ::" classifiers are deprecated for metadata >= 2.4, use a SPDX license expression for "project.license" instead',
575+
'The one-line summary "project.description" should not contain more than one line. Readers might merge or truncate newlines.',
582576
ConfigurationWarning,
583577
stacklevel=2,
584578
)
579+
if self.auto_metadata_version not in PRE_SPDX_METADATA_VERSIONS:
580+
if isinstance(self.license, License):
581+
warnings.warn(
582+
'Set "project.license" to an SPDX license expression for metadata >= 2.4',
583+
ConfigurationWarning,
584+
stacklevel=2,
585+
)
586+
elif any(c.startswith('License ::') for c in self.classifiers):
587+
warnings.warn(
588+
'"License ::" classifiers are deprecated for metadata >= 2.4, use a SPDX license expression for "project.license" instead',
589+
ConfigurationWarning,
590+
stacklevel=2,
591+
)
585592

586593
if (
587594
isinstance(self.license, str)
@@ -701,7 +708,7 @@ def as_rfc822(self) -> RFC822Message:
701708
self.write_to_rfc822(message)
702709
return message
703710

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

707714
smart_message = _SmartMessageSetter(message)

tests/test_standard_metadata.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,3 +1150,21 @@ def test_extra_build_system() -> None:
11501150
}
11511151
}
11521152
)
1153+
1154+
1155+
def test_multiline_description_warns() -> None:
1156+
with pytest.warns(
1157+
pyproject_metadata.ConfigurationWarning,
1158+
match=re.escape(
1159+
'The one-line summary "project.description" should not contain more than one line. Readers might merge or truncate newlines.'
1160+
),
1161+
):
1162+
pyproject_metadata.StandardMetadata.from_pyproject(
1163+
{
1164+
'project': {
1165+
'name': 'example',
1166+
'version': '1.2.3',
1167+
'description': 'this\nis multiline',
1168+
},
1169+
}
1170+
)

0 commit comments

Comments
 (0)