[BUG] License-Files entries are not checked for UTF-8 compliance, they just get copied directly into the licenses folder

Open
#4,936 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
build-system

Research direction

Trace how license-files from pyproject.toml are processed by the setuptools build backend and copied into the dist-info/licenses directory. Check the existing handling around these entries and add coverage for non-UTF-8 or binary files; done means invalid license files produce an error instead of being copied silently.

Written by the indexing model from the issue text.

Description

bug Needs Triage
setuptools version

78.1.0

Python version

3.11

OS

Windows

Additional environment information

No response

Description

Using a pyproject.toml like this:

[build-system]
requires = ["setuptools >= 78.1.0"]
build-backend = "setuptools.build_meta"

[project]
name = "repro"
version = "0.1"
license-files = ["BadLicense.*"]

Now I have two files BadLicense.doc and BadLicense.pdf in my project directory.

Setuptools copies both files into the dist-info/licenses directory, without warning or error.

This also happens, if a pyproject.toml has no 'license-files' declared and the default regexp patterns are applied, so you might even end up to include 'license.py', 'license.exe' or similar files that are clearly not text files.

Expected behavior

This should result in an error.

PEP639 clearly states, that the license files MUST be UTF-8 encoded. This is obviously not the case for a binary Word doc file and probably not for a PDF. So i would expect setuptools validate this and to raise an Exception if it is not a valid UTF-8 encoded text file.

Tools MUST assume that license file content is valid UTF-8 encoded text, and SHOULD validate this and raise an error if it is not.

How to Reproduce
  1. mkdir repro
  2. Unpack pyproject.zip into the folder
  3. cd repro
  4. python -m venv .venv
  5. ./venv/Scripts/pip install -e .
  6. dir ..venv\Lib\site-packages\repro-0.1.dist-info\licenses\

pyproject.zip

Output

PS C:\repro> dir .\.venv\Lib\site-packages\repro-0.1.dist-info\licenses\

    Directory: C:\repro\.venv\Lib\site-packages\repro-0.1.dist-info\licenses

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          03.04.2025    15:33          29184 BadLicense.doc
-a---          03.04.2025    15:33          30930 BadLicense.pdf

Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pypa/setuptools

All issues in pypa/setuptools

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.