diff --git a/README.md b/README.md index 522fff7..3d09b7e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject_metadata/__init__.py b/pyproject_metadata/__init__.py index a624468..bac3d16 100644 --- a/pyproject_metadata/__init__.py +++ b/pyproject_metadata/__init__.py @@ -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 diff --git a/tests/packages/fulltext_license/LICENSE.txt b/tests/packages/fulltext_license/LICENSE.txt new file mode 100644 index 0000000..c3713cd --- /dev/null +++ b/tests/packages/fulltext_license/LICENSE.txt @@ -0,0 +1,20 @@ +Copyright © 2019 Filipe Laíns + +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. diff --git a/tests/test_standard_metadata.py b/tests/test_standard_metadata.py index 7bb93f6..ccd1c91 100644 --- a/tests/test_standard_metadata.py +++ b/tests/test_standard_metadata.py @@ -2,6 +2,7 @@ from __future__ import annotations +import contextlib import pathlib import re import shutil @@ -19,6 +20,7 @@ import tomllib import pyproject_metadata +import pyproject_metadata.constants DIR = pathlib.Path(__file__).parent.resolve() @@ -29,6 +31,11 @@ exceptiongroup = None # type: ignore[assignment] +@pytest.fixture(params=pyproject_metadata.constants.KNOWN_METADATA_VERSIONS) +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 @@ -1245,6 +1252,30 @@ 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 pyproject_metadata.constants.PRE_SPDX_METADATA_VERSIONS 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 pyproject_metadata.constants.PRE_SPDX_METADATA_VERSIONS: + 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") @@ -1260,7 +1291,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( {