Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add license file and test #320

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/_includes/pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" },
]
Expand Down
24 changes: 24 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down