Skip to content

Commit 9668f7b

Browse files
committed
Add warning for deprecated metadata fields
1 parent a443f76 commit 9668f7b

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

docs/references/keywords.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,21 @@ extensions).
8585
``url``
8686
A string specifying the URL for the package homepage.
8787

88+
.. warning::
89+
``url`` is deprecated as it generates the ``Home-page`` metadata.
90+
Please use ``project_urls`` instead, with the relevant labels.
91+
See :pep:`753`.
92+
8893
.. _keyword/download_url:
8994

9095
``download_url``
9196
A string specifying the URL to download the package.
9297

98+
.. warning::
99+
``download_url`` is deprecated as it generates the ``Download-URL`` metadata.
100+
Please use ``project_urls`` instead, with the relevant labels.
101+
See :pep:`753`.
102+
93103
.. _keyword/packages:
94104

95105
``packages``
@@ -257,14 +267,14 @@ extensions).
257267

258268
``requires``
259269
.. warning::
260-
``requires`` is superseded by ``install_requires`` and should not be used
261-
anymore.
270+
``requires`` is deprecated and superseded by ``install_requires``.
271+
It should not be used anymore.
262272

263273
.. _keyword/obsoletes:
264274

265275
``obsoletes``
266276
.. warning::
267-
``obsoletes`` is currently ignored by ``pip``.
277+
``obsoletes`` is deprecated and currently ignored by ``pip``.
268278

269279
List of strings describing packages which this package renders obsolete,
270280
meaning that the two projects should not be installed at the same time.
@@ -283,7 +293,7 @@ extensions).
283293

284294
``provides``
285295
.. warning::
286-
``provides`` is currently ignored by ``pip``.
296+
``provides`` is currently considered deprecated and is ignored by ``pip``.
287297

288298
List of strings describing package- and virtual package names contained
289299
within this package.

setuptools/dist.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ def check_packages(dist, attr, value):
231231
)
232232

233233

234+
def _check_deprecated_metadata_field(
235+
dist: Distribution, attr: str, value: object
236+
) -> None:
237+
if value:
238+
SetuptoolsDeprecationWarning.emit(
239+
f"Deprecated usage of `{attr}` in setuptools configuration.",
240+
see_docs=f"references/keywords.html#keyword-{attr.replace('_', '-')}",
241+
due_date=(2027, 1, 25),
242+
# Warning initially introduced in 14 Jan 2025
243+
)
244+
245+
234246
if TYPE_CHECKING:
235247
# Work around a mypy issue where type[T] can't be used as a base: https://github.com/python/mypy/issues/10962
236248
from distutils.core import Distribution as _Distribution
@@ -294,6 +306,14 @@ class Distribution(_Distribution):
294306
'extras_require': dict,
295307
}
296308

309+
_DEPRECATED_FIELDS = (
310+
"url",
311+
"download_url",
312+
"requires",
313+
"provides",
314+
"obsoletes",
315+
)
316+
297317
# Used by build_py, editable_wheel and install_lib commands for legacy namespaces
298318
namespace_packages: list[str] #: :meta private: DEPRECATED
299319

@@ -318,6 +338,9 @@ def __init__(self, attrs: MutableMapping[str, Any] | None = None) -> None:
318338
dist_attrs = {k: v for k, v in attrs.items() if k not in metadata_only}
319339
_Distribution.__init__(self, dist_attrs)
320340

341+
for attr in self._DEPRECATED_FIELDS:
342+
_check_deprecated_metadata_field(self, attr, dist_attrs.get(attr))
343+
321344
# Private API (setuptools-use only, not restricted to Distribution)
322345
# Stores files that are referenced by the configuration and need to be in the
323346
# sdist (e.g. `version = file: VERSION.txt`)

setuptools/tests/test_dist.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from setuptools import Distribution
8+
from setuptools import Distribution, SetuptoolsDeprecationWarning
99
from setuptools.dist import check_package_data, check_specifier
1010

1111
from .test_easy_install import make_nspkg_sdist
@@ -276,3 +276,22 @@ def test_dist_default_name(tmp_path, dist_name, package_dir, package_files):
276276
dist.set_defaults()
277277
assert dist.py_modules or dist.packages
278278
assert dist.get_name() == dist_name
279+
280+
281+
@pytest.mark.parametrize(
282+
("field", "value"),
283+
[
284+
("requires", ["setuptools"]),
285+
("provides", ["setuptools"]),
286+
("obsoletes", ["setuptools"]),
287+
("url", "www.setuptools.com.br"),
288+
("download_url", "www.setuptools.com.br/42"),
289+
],
290+
)
291+
def test_deprecated_fields(tmpdir_cwd, field, value):
292+
"""See discussion in https://github.com/pypa/setuptools/issues/4797"""
293+
attrs = {"name": "test", "version": "0.42", field: value}
294+
match = f"Deprecated usage of `{field}`"
295+
with pytest.warns(SetuptoolsDeprecationWarning, match=match):
296+
dist = Distribution(attrs)
297+
assert getattr(dist.metadata, field, None) == value

0 commit comments

Comments
 (0)