Skip to content

Commit c4af78a

Browse files
committed
Warn deprecated metadata fields in pyproject.toml
1 parent df3f236 commit c4af78a

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

Diff for: pytest.ini

+1
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,4 @@ filterwarnings=
9797

9898
# Suppress known config deprecations still used in tests
9999
ignore:Deprecated config in `setup.cfg`
100+
ignore:Deprecated usage of `tool.setuptools.(provides|obsoletes)`

Diff for: setuptools/config/_apply_pyprojecttoml.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from .._path import StrPath
2525
from ..errors import 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
@@ -98,6 +98,12 @@ def _apply_tool_table(dist: Distribution, config: dict, filename: StrPath):
9898
and has been removed from `pyproject.toml`.
9999
"""
100100
raise RemovedConfigError("\n".join([cleandoc(msg), suggestion]))
101+
elif norm_key in TOOL_TABLE_DEPRECATIONS:
102+
SetuptoolsDeprecationWarning.emit(
103+
f"Deprecated usage of `tool.setuptools.{field}` in `pyproject.toml`.",
104+
see_docs=f"references/keywords.html#keyword-{field}",
105+
due_date=(2027, 1, 25), # introduced in 20 Jan 2025
106+
)
101107

102108
norm_key = TOOL_TABLE_RENAMES.get(norm_key, norm_key)
103109
corresp = TOOL_TABLE_CORRESPONDENCE.get(norm_key, norm_key)
@@ -401,11 +407,13 @@ def _acessor(obj):
401407

402408
TOOL_TABLE_RENAMES = {"script_files": "scripts"}
403409
TOOL_TABLE_REMOVALS = {
410+
"requires": "Please use `[project] dependencies` for Python requirements.",
404411
"namespace_packages": """
405412
Please migrate to implicit native namespaces instead.
406413
See https://packaging.python.org/en/latest/guides/packaging-namespace-packages/.
407414
""",
408415
}
416+
TOOL_TABLE_DEPRECATIONS = ("obsoletes", "provides")
409417
TOOL_TABLE_CORRESPONDENCE = {
410418
# Fields with corresponding core metadata need to be marked as static:
411419
"obsoletes": partial(_set_static_list_metadata, "obsoletes"),

Diff for: setuptools/tests/config/test_apply_pyprojecttoml.py

+38-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from setuptools.config._apply_pyprojecttoml import _MissingDynamic, _some_attrgetter
2525
from setuptools.dist import Distribution
2626
from setuptools.errors import RemovedConfigError
27+
from setuptools.warnings import SetuptoolsDeprecationWarning
2728

2829
from .downloads import retrieve_file, urls_from_file
2930

@@ -347,18 +348,47 @@ def test_pyproject_sets_attribute(self, tmp_path, monkeypatch):
347348

348349

349350
class TestDeprecatedFields:
350-
def test_namespace_packages(self, tmp_path):
351+
@pytest.mark.parametrize(
352+
("field", "value"),
353+
[
354+
("provides", "['setuptools']"),
355+
("obsoletes", "['obsoletes']"),
356+
],
357+
)
358+
def test_still_valid(self, tmp_path, field, value):
359+
pyproject = tmp_path / "pyproject.toml"
360+
config = f"""
361+
[project]
362+
name = "myproj"
363+
version = "42"
364+
[tool.setuptools]
365+
{field} = {value}
366+
"""
367+
pyproject.write_text(cleandoc(config), encoding="utf-8")
368+
match = f"Deprecated usage of `tool.setuptools.{field}`"
369+
with pytest.warns(SetuptoolsDeprecationWarning, match=match):
370+
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
371+
372+
@pytest.mark.parametrize(
373+
("field", "value"),
374+
[
375+
("namespace-packages", "['myproj.pkg']"),
376+
("requires", "['setuptools']"),
377+
],
378+
)
379+
def test_removed(self, tmp_path, field, value):
351380
pyproject = tmp_path / "pyproject.toml"
352-
config = """
381+
config = f"""
353382
[project]
354383
name = "myproj"
355384
version = "42"
356385
[tool.setuptools]
357-
namespace-packages = ["myproj.pkg"]
386+
{field} = {value}
358387
"""
359388
pyproject.write_text(cleandoc(config), encoding="utf-8")
360-
with pytest.raises(RemovedConfigError, match="namespace-packages"):
389+
with pytest.raises((RemovedConfigError, ValueError)) as exc:
361390
pyprojecttoml.apply_configuration(makedist(tmp_path), pyproject)
391+
assert f"tool.setuptools.{field}" in str(exc.value)
362392

363393

364394
class TestPresetField:
@@ -498,7 +528,10 @@ def test_mark_static_fields(self, tmp_path, monkeypatch):
498528
"""
499529
pyproject = Path(tmp_path, "pyproject.toml")
500530
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
501-
dist = pyprojecttoml.apply_configuration(Distribution({}), pyproject)
531+
532+
with pytest.warns(SetuptoolsDeprecationWarning, match="Deprecated usage of"):
533+
dist = pyprojecttoml.apply_configuration(Distribution({}), pyproject)
534+
502535
assert is_static(dist.install_requires)
503536
assert is_static(dist.metadata.keywords)
504537
assert is_static(dist.metadata.classifiers)

0 commit comments

Comments
 (0)