Skip to content

Commit

Permalink
harmonize with documentation
Browse files Browse the repository at this point in the history
although inconsistent (see Requires-External, Provides-Extra, Provides-Dist, Obsoletes-Dist...) pluralize the result for multiple use of `License-File`

https://packaging.pypa.io/en/stable/metadata.html#packaging.metadata.RawMetadata

> Any core metadata field that can be specified multiple times or can hold multiple values in a single field have a key with a plural name.
  • Loading branch information
ewdurbin committed Sep 3, 2024
1 parent 660fb2b commit 4bbae23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/packaging/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class RawMetadata(TypedDict, total=False):

# Metadata 2.4 - PEP 639
license_expression: str
license_file: list[str]
license_files: list[str]


_STRING_FIELDS = {
Expand All @@ -157,7 +157,7 @@ class RawMetadata(TypedDict, total=False):
_LIST_FIELDS = {
"classifiers",
"dynamic",
"license_file",
"license_files",
"obsoletes",
"obsoletes_dist",
"platforms",
Expand Down Expand Up @@ -261,7 +261,7 @@ def _get_payload(msg: email.message.Message, source: bytes | str) -> str:
"keywords": "keywords",
"license": "license",
"license-expression": "license_expression",
"license-file": "license_file",
"license-file": "license_files",
"maintainer": "maintainer",
"maintainer-email": "maintainer_email",
"metadata-version": "metadata_version",
Expand Down Expand Up @@ -655,7 +655,7 @@ def _process_license_expression(self, value: str) -> str:
f"{value!r} is invalid for {{field}}", cause=exc
) from exc

def _process_license_file(self, value: list[str]) -> list[str]:
def _process_license_files(self, value: list[str]) -> list[str]:
paths = []
for path in value:
if ".." in path:
Expand Down Expand Up @@ -805,7 +805,7 @@ def from_email(cls, data: bytes | str, *, validate: bool = True) -> Metadata:
""":external:ref:`core-metadata-license`"""
license_expression: _Validator[str | None] = _Validator(added="2.4")
""":external:ref:`core-metadata-license-expression`"""
license_file: _Validator[list[str] | None] = _Validator(added="2.4")
license_files: _Validator[list[str] | None] = _Validator(added="2.4")
""":external:ref:`core-metadata-license-file`"""
classifiers: _Validator[list[str] | None] = _Validator(added="1.1")
""":external:ref:`core-metadata-classifier`"""
Expand Down
18 changes: 9 additions & 9 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_complete(self):
" to redistribute it."
)
assert raw["license_expression"] == "Apache-2.0 OR BSD-2-Clause"
assert raw["license_file"] == ["LICENSE.APACHE", "LICENSE.BSD"]
assert raw["license_files"] == ["LICENSE.APACHE", "LICENSE.BSD"]
assert raw["classifiers"] == [
"Development Status :: 4 - Beta",
"Environment :: Console (Text Based)",
Expand Down Expand Up @@ -638,32 +638,32 @@ def test_invalid_license_expression(self):
meta.license_expression # noqa: B018

@pytest.mark.parametrize(
"license_file",
"license_files",
[
["LICENSE.txt", "licenses/*"],
[],
["licenses/LICENSE.MIT", "licenses/LICENSE.CC0"],
["LICENSE"],
],
)
def test_valid_license_file(self, license_file):
def test_valid_license_files(self, license_files):
meta = metadata.Metadata.from_raw(
{"license_file": license_file}, validate=False
{"license_files": license_files}, validate=False
)
assert meta.license_file == license_file
assert meta.license_files == license_files

@pytest.mark.parametrize(
"license_file",
"license_files",
[
["../LICENSE"],
["./../LICENSE"],
["licenses/../LICENSE"],
],
)
def test_invalid_license_file(self, license_file):
def test_invalid_license_files(self, license_files):
meta = metadata.Metadata.from_raw(
{"license_file": license_file}, validate=False
{"license_files": license_files}, validate=False
)

with pytest.raises(metadata.InvalidMetadata):
meta.license_file # noqa: B018
meta.license_files # noqa: B018

0 comments on commit 4bbae23

Please sign in to comment.