Skip to content

Commit

Permalink
fix: support METADATA 2.4 being set explicilty & 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 14, 2024
1 parent 49fd43f commit 5c210bd
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 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
12 changes: 11 additions & 1 deletion pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,23 @@ def _write_metadata( # noqa: C901
smart_message["Maintainer-Email"] = _email_list(self.maintainers)

if isinstance(self.license, License):
smart_message["License"] = self.license.text
if (
self.auto_metadata_version in constants.PRE_SPDX_METADATA_VERSIONS
or not self.license.file
):
smart_message["License"] = self.license.text
elif isinstance(self.license, str):
smart_message["License-Expression"] = self.license

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
34 changes: 34 additions & 0 deletions tests/packages/fulltext_license/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Minuit is from SEAL Minuit It's LGPL v2
http://seal.web.cern.ch/seal/main/license.html.

For iminuit, I'm releasing it as MIT license:

Copyright (c) 2012 Piti Ongmongkolkul

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 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.


Note:
MIT license is GPL compatible, so it is an acceptable license for a wrapper,
as can be seen here:
http://www.gnu.org/licenses/old-licenses/gpl-2.0-faq.html#GPLWrapper
http://www.gnu.org/licenses/old-licenses/gpl-2.0-faq.html#OrigBSD

(L)GPL can be combined or included in code that does not impose more restrictive
conditions.
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


@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 {
"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 5c210bd

Please sign in to comment.