diff --git a/docs/_includes/pyproject.md b/docs/_includes/pyproject.md index f6831edc..e5eb6ec1 100644 --- a/docs/_includes/pyproject.md +++ b/docs/_includes/pyproject.md @@ -7,6 +7,7 @@ The metadata is specified in a [standards-based][metadata] format: name = "package" description = "A great package." readme = "README.md" +license.file = "LICENSE" authors = [ { name = "My Name", email = "me@email.com" }, ] diff --git a/noxfile.py b/noxfile.py index 8d780eeb..5b9c864d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -8,13 +8,16 @@ from __future__ import annotations import difflib +import email.message import json import os import re import shutil import stat import sys +import tarfile import urllib.request +import zipfile from collections.abc import Callable from pathlib import Path @@ -270,6 +273,27 @@ def dist(session: nox.Session, backend: str, vcs: bool) -> None: session.run("twine", "check", f"{sdist}", f"{wheel}") + # Check for LICENSE in SDist + with tarfile.open(sdist) as tf: + names = tf.getnames() + if not any(n.endswith("LICENSE") for n in names): + msg = f"license file missing from {backend} vcs={vcs}'s sdist. Found: {names}" + session.error(msg) + + # Check for LICENSE in wheel + with zipfile.ZipFile(wheel) as zf: + names = zf.namelist() + metadata_path = next(iter(n for n in names if n.endswith("METADATA"))) + with zf.open(metadata_path) as mfile: + txt = mfile.read() + license_fields = email.message.EmailMessage(txt).get_all("License", []) + if license_fields: + msg = f"Should not have anything in the License slot, got {license_fields}" + session.error(msg) + if not any(n.endswith("LICENSE") for n in names): + msg = f"license file missing from {backend} vcs={vcs}'s wheel. Found: {names}" + session.error(msg) + dist = DIR / "dist" dist.mkdir(exist_ok=True) sdist.rename(dist / sdist.stem) diff --git a/{{cookiecutter.project_name}}/pyproject.toml b/{{cookiecutter.project_name}}/pyproject.toml index 5c5cfa03..41175675 100644 --- a/{{cookiecutter.project_name}}/pyproject.toml +++ b/{{cookiecutter.project_name}}/pyproject.toml @@ -162,6 +162,7 @@ maintainers = [ {%- endif %} description = "{{ cookiecutter.project_short_description }}" readme = "README.md" +license.file = "LICENSE" requires-python = ">=3.8" classifiers = [ "Development Status :: 1 - Planning",