Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .distro/python-scikit-build-core.spec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Requires: cmake
Requires: ninja-build
BuildArch: noarch

Provides: bundled(python3dist(pyproject-metadata)) = 0.9.1

Obsoletes: python3-scikit-build-core+pyproject < 0.10.7-3

%description -n python3-scikit-build-core %_description
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dynamic = ["version"]
dependencies = [
"exceptiongroup >=1.0; python_version<'3.11'",
"importlib-resources >=1.3; python_version<'3.9'",
"packaging >=21.3",
"packaging >=23.2",
"pathspec >=0.10.1",
"tomli >=1.2.2; python_version<'3.11'",
"typing-extensions >=3.10.0; python_version<'3.9'",
Expand Down
69 changes: 54 additions & 15 deletions src/scikit_build_core/_vendor/pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import os
import os.path
import pathlib
import re
import sys
import typing
import warnings
Expand Down Expand Up @@ -68,7 +67,14 @@
import packaging.utils
import packaging.version

__version__ = "0.9.0"
if sys.version_info < (3, 12, 4):
import re

RE_EOL_STR = re.compile(r"[\r\n]+")
RE_EOL_BYTES = re.compile(rb"[\r\n]+")


__version__ = "0.9.1"

__all__ = [
"ConfigurationError",
Expand All @@ -77,10 +83,10 @@
"RFC822Policy",
"Readme",
"StandardMetadata",
"field_to_metadata",
"extras_build_system",
"extras_project",
"extras_top_level",
"field_to_metadata",
]


Expand Down Expand Up @@ -187,6 +193,37 @@
value = value.replace("\n", "\n" + " " * size)
return (name, value)

if sys.version_info < (3, 12, 4):
# Work around Python bug https://github.com/python/cpython/issues/117313
def _fold(
self, name: str, value: Any, refold_binary: bool = False
) -> str: # pragma: no cover
if hasattr(value, "name"):
return value.fold(policy=self) # type: ignore[no-any-return]
maxlen = self.max_line_length if self.max_line_length else sys.maxsize

# this is from the library version, and it improperly breaks on chars like 0x0c, treating
# them as 'form feed' etc.
# we need to ensure that only CR/LF is used as end of line
# lines = value.splitlines()

# this is a workaround which splits only on CR/LF characters
if isinstance(value, bytes):
lines = RE_EOL_BYTES.split(value)
else:
lines = RE_EOL_STR.split(value)

refold = self.refold_source == "all" or (
self.refold_source == "long"
and (
(lines and len(lines[0]) + len(name) + 2 > maxlen)
or any(len(x) > maxlen for x in lines[1:])
)
)
if refold or (refold_binary and email.policy._has_surrogates(value)): # type: ignore[attr-defined]
return self.header_factory(name, "".join(lines)).fold(policy=self) # type: ignore[arg-type,no-any-return]
return name + ": " + self.linesep.join(lines) + self.linesep # type: ignore[arg-type]


class RFC822Message(email.message.EmailMessage):
"""
Expand Down Expand Up @@ -474,11 +511,9 @@
msg = "The metadata_version must be one of {versions} or None (default)"
errors.config_error(msg, versions=constants.KNOWN_METADATA_VERSIONS)

# See https://packaging.python.org/en/latest/specifications/core-metadata/#name and
# https://packaging.python.org/en/latest/specifications/name-normalization/#name-format
if not re.match(
r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", self.name, re.IGNORECASE
):
try:
packaging.utils.canonicalize_name(self.name, validate=True)
except packaging.utils.InvalidName:

Check warning on line 516 in src/scikit_build_core/_vendor/pyproject_metadata/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/_vendor/pyproject_metadata/__init__.py#L516

Added line #L516 was not covered by tests
msg = (
"Invalid project name {name!r}. A valid name consists only of ASCII letters and "
"numbers, period, underscore and hyphen. It must start and end with a letter or number"
Expand Down Expand Up @@ -543,13 +578,15 @@
"""
Write the metadata to the message. Handles JSON or Message.
"""
self.validate(warn=False)
errors = ErrorCollector(collect_errors=self.all_errors)
with errors.collect():
self.validate(warn=False)

smart_message["Metadata-Version"] = self.auto_metadata_version
smart_message["Name"] = self.name
if not self.version:
msg = "Missing version field"
raise ConfigurationError(msg)
msg = "Field {key} missing"
errors.config_error(msg, key="project.version")

Check warning on line 589 in src/scikit_build_core/_vendor/pyproject_metadata/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/_vendor/pyproject_metadata/__init__.py#L588-L589

Added lines #L588 - L589 were not covered by tests
smart_message["Version"] = str(self.version)
# skip 'Platform'
# skip 'Supported-Platform'
Expand Down Expand Up @@ -604,13 +641,15 @@
if self.auto_metadata_version != "2.1":
for field in self.dynamic_metadata:
if field.lower() in {"name", "version", "dynamic"}:
msg = f"Field cannot be set as dynamic metadata: {field}"
raise ConfigurationError(msg)
msg = f"Metadata field {field!r} cannot be declared dynamic"
errors.config_error(msg)

Check warning on line 645 in src/scikit_build_core/_vendor/pyproject_metadata/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/_vendor/pyproject_metadata/__init__.py#L644-L645

Added lines #L644 - L645 were not covered by tests
if field.lower() not in constants.KNOWN_METADATA_FIELDS:
msg = f"Field is not known: {field}"
raise ConfigurationError(msg)
msg = f"Unknown metadata field {field!r} cannot be declared dynamic"
errors.config_error(msg)

Check warning on line 648 in src/scikit_build_core/_vendor/pyproject_metadata/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/_vendor/pyproject_metadata/__init__.py#L647-L648

Added lines #L647 - L648 were not covered by tests
smart_message["Dynamic"] = field

errors.finalize("Failed to write metadata")


def _name_list(people: list[tuple[str, str | None]]) -> str | None:
"""
Expand Down
Loading