Skip to content

Commit

Permalink
fix: support METADATA 2.4 being set explicitly & PEP 639
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 16, 2024
1 parent 49fd43f commit 4fadb57
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ By default, a warning (`pyproject_metadata.errors.ExtraKeyWarning`) will be
issued for extra fields at the project table. You can pass `allow_extra_keys=`
to either avoid the check (`True`) or hard error (`False`). If you want to
detect extra keys, you can get them with `pyproject_metadata.extra_top_level`
and `pyproject_metadata.extra_build_sytem`.
and `pyproject_metadata.extra_build_system`. It is recommended that build
systems only warn on failures with these extra keys.

## Validating classifiers

Expand Down
6 changes: 6 additions & 0 deletions pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ def _write_metadata( # noqa: C901
if self.license_files is not None:
for license_file in sorted(set(self.license_files)):
smart_message["License-File"] = os.fspath(license_file.as_posix())
elif (
self.auto_metadata_version not in constants.PRE_SPDX_METADATA_VERSIONS
and isinstance(self.license, License)
and self.license.file
):
smart_message["License-File"] = os.fspath(self.license.file.as_posix())

for classifier in self.classifiers:
smart_message["Classifier"] = classifier
Expand Down
20 changes: 20 additions & 0 deletions tests/packages/fulltext_license/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright © 2019 Filipe Laíns <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
33 changes: 32 additions & 1 deletion tests/test_standard_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import contextlib
import pathlib
import re
import shutil
Expand Down Expand Up @@ -29,6 +30,11 @@
exceptiongroup = None # type: ignore[assignment]


@pytest.fixture(params=["2.1", "2.2", "2.3", "2.4"])
def metadata_version(request: pytest.FixtureRequest) -> str:
return request.param # type: ignore[no-any-return]


@pytest.fixture(params=["one_error", "all_errors", "exceptiongroup"])
def all_errors(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch) -> bool:
param: str = request.param
Expand Down Expand Up @@ -1245,6 +1251,32 @@ def test_as_rfc822_spdx_empty_glob(
)


def test_license_file_24(
metadata_version: str, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.chdir(DIR / "packages/fulltext_license")
with contextlib.nullcontext() if metadata_version in { # type: ignore[attr-defined]
"2.1",
"2.2",
"2.3",
} else pytest.warns(pyproject_metadata.errors.ConfigurationWarning):
metadata = pyproject_metadata.StandardMetadata.from_pyproject(
{
"project": {
"name": "fulltext_license",
"version": "0.1.0",
"license": {"file": "LICENSE.txt"},
},
},
metadata_version=metadata_version,
)
message = str(metadata.as_rfc822())
if metadata_version in {"2.1", "2.2", "2.3"}:
assert "License-File: LICENSE.txt" not in message
else:
assert "License-File: LICENSE.txt" in message


def test_as_rfc822_dynamic(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.chdir(DIR / "packages/dynamic-description")

Expand All @@ -1260,7 +1292,6 @@ def test_as_rfc822_dynamic(monkeypatch: pytest.MonkeyPatch) -> None:
]


@pytest.mark.parametrize("metadata_version", ["2.1", "2.2", "2.3"])
def test_as_rfc822_set_metadata(metadata_version: str) -> None:
metadata = pyproject_metadata.StandardMetadata.from_pyproject(
{
Expand Down

0 comments on commit 4fadb57

Please sign in to comment.