Skip to content

Commit 01396db

Browse files
committed
Add comments and test about dynamic x license_files
1 parent 17dc3df commit 01396db

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

setuptools/config/_apply_pyprojecttoml.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,11 @@ def _acessor(obj):
479479

480480
_RESET_PREVIOUSLY_DEFINED: dict = {
481481
# Fix improper setting: given in `setup.py`, but not listed in `dynamic`
482-
# Use "immutable" data structures to avoid in-place modification
482+
# Use "immutable" data structures to avoid in-place modification.
483483
# dict: pyproject name => value to which reset
484484
"license": "",
485+
# XXX: `license-file` is currently not considered in the context of `dynamic`.
486+
# See TestPresetField.test_license_files_exempt_from_dynamic
485487
"authors": _static.EMPTY_LIST,
486488
"maintainers": _static.EMPTY_LIST,
487489
"keywords": _static.EMPTY_LIST,

setuptools/tests/config/test_apply_pyprojecttoml.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,26 @@ def test_listed_in_dynamic(self, tmp_path, attr, field, value):
598598
dist_value = _some_attrgetter(f"metadata.{attr}", attr)(dist)
599599
assert dist_value == value
600600

601+
def test_license_files_exempt_from_dynamic(self, monkeypatch, tmp_path):
602+
"""
603+
license-file is currently not considered in the context of dynamic.
604+
As per 2025-02-19, https://packaging.python.org/en/latest/specifications/pyproject-toml/#license-files
605+
allows setuptools to fill-in `license-files` the way it sees fit:
606+
607+
> If the license-files key is not defined, tools can decide how to handle license files.
608+
> For example they can choose not to include any files or use their own
609+
> logic to discover the appropriate files in the distribution.
610+
611+
Using license_files from setup.py to fill-in the value is in accordance
612+
with this rule.
613+
"""
614+
monkeypatch.chdir(tmp_path)
615+
pyproject = self.pyproject(tmp_path, [])
616+
dist = makedist(tmp_path, license_files=["LIC*"])
617+
(tmp_path / "LIC1").write_text("42", encoding="utf-8")
618+
dist = pyprojecttoml.apply_configuration(dist, pyproject)
619+
assert dist.metadata.license_files == ["LIC1"]
620+
601621
def test_warning_overwritten_dependencies(self, tmp_path):
602622
src = "[project]\nname='pkg'\nversion='0.1'\ndependencies=['click']\n"
603623
pyproject = tmp_path / "pyproject.toml"

0 commit comments

Comments
 (0)