Skip to content

Commit 6f0aee2

Browse files
authored
Deprecate tools.setuptools.license-files (pypa#4837)
2 parents eacde44 + d6abdce commit 6f0aee2

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

docs/userguide/miscellaneous.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ files are included in a source distribution by default:
2424
in ``pyproject.toml`` and/or equivalent in ``setup.cfg``/``setup.py``;
2525
note that if you don't explicitly set this parameter, ``setuptools``
2626
will include any files that match the following glob patterns:
27-
``LICENSE*``, ``LICENCE*``, ``COPYING*``, ``NOTICE*``, ``AUTHORS**``;
27+
``LICEN[CS]E*``, ``COPYING*``, ``NOTICE*``, ``AUTHORS**``;
2828
- ``pyproject.toml``;
2929
- ``setup.cfg``;
3030
- ``setup.py``;

docs/userguide/pyproject_config.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Key Value Type (TOML) Notes
9999
See :doc:`/userguide/datafiles`.
100100
``exclude-package-data`` table/inline-table Empty by default. See :doc:`/userguide/datafiles`.
101101
------------------------- --------------------------- -------------------------
102-
``license-files`` array of glob patterns **Provisional** - likely to change with :pep:`639`
102+
``license-files`` array of glob patterns **Deprecated** - use ``project.license-files`` instead. See :doc:`PyPUG:guides/writing-pyproject-toml`
103103
(by default: ``['LICEN[CS]E*', 'COPYING*', 'NOTICE*', 'AUTHORS*']``)
104104
``data-files`` table/inline-table **Discouraged** - check :doc:`/userguide/datafiles`.
105105
Whenever possible, consider using data files inside the package directories.

newsfragments/4837.feature.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Deprecated ``tools.setuptools.license-files`` in favor of ``project.license-files``
2+
and added exception if ``project.license-files`` and ``tools.setuptools.license-files``
3+
are used together. -- by :user:`cdce8p`

setuptools/config/_apply_pyprojecttoml.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
from .. import _static
2424
from .._path import StrPath
25-
from ..errors import RemovedConfigError
25+
from ..errors import InvalidConfigError, RemovedConfigError
2626
from ..extension import Extension
27-
from ..warnings import SetuptoolsWarning
27+
from ..warnings import SetuptoolsDeprecationWarning, SetuptoolsWarning
2828

2929
if TYPE_CHECKING:
3030
from typing_extensions import TypeAlias
@@ -89,6 +89,21 @@ def _apply_tool_table(dist: Distribution, config: dict, filename: StrPath):
8989
if not tool_table:
9090
return # short-circuit
9191

92+
if "license-files" in tool_table:
93+
if dist.metadata.license_files:
94+
raise InvalidConfigError(
95+
"'project.license-files' is defined already. "
96+
"Remove 'tool.setuptools.license-files'."
97+
)
98+
99+
pypa_guides = "guides/writing-pyproject-toml/#license-files"
100+
SetuptoolsDeprecationWarning.emit(
101+
"'tool.setuptools.license-files' is deprecated in favor of "
102+
"'project.license-files'",
103+
see_url=f"https://packaging.python.org/en/latest/{pypa_guides}",
104+
due_date=(2026, 2, 18), # Warning introduced on 2025-02-18
105+
)
106+
92107
for field, value in tool_table.items():
93108
norm_key = json_compatible_key(field)
94109

setuptools/tests/config/test_apply_pyprojecttoml.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def base_pyproject(self, tmp_path, additional_text):
375375
pyproject.write_text(text, encoding="utf-8")
376376
return pyproject
377377

378-
def base_pyproject_license_pep639(self, tmp_path):
378+
def base_pyproject_license_pep639(self, tmp_path, additional_text=""):
379379
pyproject = _pep621_example_project(tmp_path, "README")
380380
text = pyproject.read_text(encoding="utf-8")
381381

@@ -390,6 +390,8 @@ def base_pyproject_license_pep639(self, tmp_path):
390390
text,
391391
count=1,
392392
)
393+
if additional_text:
394+
text = f"{text}\n{additional_text}\n"
393395
pyproject.write_text(text, encoding="utf-8")
394396
return pyproject
395397

@@ -405,7 +407,9 @@ def test_both_license_and_license_files_defined(self, tmp_path):
405407
license = tmp_path / "LICENSE.txt"
406408
license.write_text("LicenseRef-Proprietary\n", encoding="utf-8")
407409

408-
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
410+
msg = "'tool.setuptools.license-files' is deprecated in favor of 'project.license-files'"
411+
with pytest.warns(SetuptoolsDeprecationWarning, match=msg):
412+
dist = pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
409413
assert set(dist.metadata.license_files) == {"_FILE.rst", "_FILE.txt"}
410414
assert dist.metadata.license == "LicenseRef-Proprietary\n"
411415

@@ -421,6 +425,15 @@ def test_both_license_and_license_files_defined_pep639(self, tmp_path):
421425
assert dist.metadata.license is None
422426
assert dist.metadata.license_expression == "LicenseRef-Proprietary"
423427

428+
def test_license_files_defined_twice(self, tmp_path):
429+
# Set project.license-files and tools.setuptools.license-files
430+
setuptools_config = '[tool.setuptools]\nlicense-files = ["_FILE*"]'
431+
pyproject = self.base_pyproject_license_pep639(tmp_path, setuptools_config)
432+
433+
msg = "'project.license-files' is defined already. Remove 'tool.setuptools.license-files'"
434+
with pytest.raises(InvalidConfigError, match=msg):
435+
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
436+
424437
def test_default_patterns(self, tmp_path):
425438
setuptools_config = '[tool.setuptools]\nzip-safe = false'
426439
# ^ used just to trigger section validation

setuptools/tests/test_build_meta.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import signal
77
import sys
88
import tarfile
9+
import warnings
910
from concurrent import futures
1011
from pathlib import Path
1112
from typing import Any, Callable
@@ -15,6 +16,8 @@
1516
from jaraco import path
1617
from packaging.requirements import Requirement
1718

19+
from setuptools.warnings import SetuptoolsDeprecationWarning
20+
1821
from .textwrap import DALS
1922

2023
SETUP_SCRIPT_STUB = "__import__('setuptools').setup()"
@@ -384,8 +387,11 @@ def test_build_with_pyproject_config(self, tmpdir, setup_script):
384387
build_backend = self.get_build_backend()
385388
with tmpdir.as_cwd():
386389
path.build(files)
387-
sdist_path = build_backend.build_sdist("temp")
388-
wheel_file = build_backend.build_wheel("temp")
390+
with warnings.catch_warnings():
391+
msg = "'tool.setuptools.license-files' is deprecated in favor of 'project.license-files'"
392+
warnings.filterwarnings("ignore", msg, SetuptoolsDeprecationWarning)
393+
sdist_path = build_backend.build_sdist("temp")
394+
wheel_file = build_backend.build_wheel("temp")
389395

390396
with tarfile.open(os.path.join(tmpdir, "temp", sdist_path)) as tar:
391397
sdist_contents = set(tar.getnames())

0 commit comments

Comments
 (0)