Skip to content

Commit

Permalink
fix: validate description for 0.9+ (#709)
Browse files Browse the repository at this point in the history
Validating only if scikit-build-core minimum-version is 0.9+ or not
present.

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii authored Apr 18, 2024
1 parent ff527b7 commit 1a691ea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/scikit_build_core/build/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@ def get_standard_metadata(
new_pyproject_dict["project"]["dynamic"].remove(field)

metadata = StandardMetadata.from_pyproject(new_pyproject_dict)

# pyproject-metadata normalizes the name - see https://github.com/FFY00/python-pyproject-metadata/pull/65
# For scikit-build-core 0.5+, we keep the un-normalized name, and normalize it when using it for filenames
if settings.minimum_version is None or settings.minimum_version >= Version("0.5"):
metadata.name = new_pyproject_dict["project"]["name"]

# The description field is required to be one line. Instead of merging it
# or cutting off subsequent lines (setuptools), we throw a nice error.
# But we didn't validate before 0.9.
if (
settings.minimum_version is None or settings.minimum_version >= Version("0.9")
) and "\n" in (metadata.description or ""):
msg = "Multiple lines in project.description are not supported; this is supposed to be a one line summary"
raise ValueError(msg)

return metadata
36 changes: 36 additions & 0 deletions tests/test_prepare_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
from pathlib import Path

import pytest
from packaging.version import Version

from scikit_build_core.build import (
prepare_metadata_for_build_editable,
prepare_metadata_for_build_wheel,
)
from scikit_build_core.build.metadata import get_standard_metadata
from scikit_build_core.settings.skbuild_model import ScikitBuildSettings


@pytest.mark.usefixtures("package_simplest_c")
Expand Down Expand Up @@ -41,3 +44,36 @@ def test_prepare_metadata_for_build(fp, editable):

assert len(list(Path("simple/simplest-0.0.1.dist-info").iterdir())) == 3
assert len(list(Path("simple").iterdir())) == 1


def test_multiline_description():
with pytest.raises(ValueError, match="one line summary"):
get_standard_metadata(
pyproject_dict={
"project": {
"name": "hello",
"version": "1.1.1",
"description": "One\nTwo",
}
},
settings=ScikitBuildSettings(),
)

with pytest.raises(ValueError, match="one line summary"):
get_standard_metadata(
pyproject_dict={
"project": {
"name": "hello",
"version": "1.1.1",
"description": "One\nTwo",
}
},
settings=ScikitBuildSettings(minimum_version=Version("0.9")),
)

get_standard_metadata(
pyproject_dict={
"project": {"name": "hello", "version": "1.1.1", "description": "One\nTwo"}
},
settings=ScikitBuildSettings(minimum_version=Version("0.8")),
)

0 comments on commit 1a691ea

Please sign in to comment.