Skip to content

Commit 7792fac

Browse files
committed
Refactor check for deprecations in 'setup.py'
1 parent eef853b commit 7792fac

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

setuptools/dist.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,6 @@ 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-
246234
if TYPE_CHECKING:
247235
# Work around a mypy issue where type[T] can't be used as a base: https://github.com/python/mypy/issues/10962
248236
from distutils.core import Distribution as _Distribution
@@ -338,9 +326,6 @@ def __init__(self, attrs: MutableMapping[str, Any] | None = None) -> None:
338326
dist_attrs = {k: v for k, v in attrs.items() if k not in metadata_only}
339327
_Distribution.__init__(self, dist_attrs)
340328

341-
for attr in self._DEPRECATED_FIELDS:
342-
_check_deprecated_metadata_field(self, attr, dist_attrs.get(attr))
343-
344329
# Private API (setuptools-use only, not restricted to Distribution)
345330
# Stores files that are referenced by the configuration and need to be in the
346331
# sdist (e.g. `version = file: VERSION.txt`)
@@ -349,9 +334,9 @@ def __init__(self, attrs: MutableMapping[str, Any] | None = None) -> None:
349334
self.set_defaults = ConfigDiscovery(self)
350335

351336
self._set_metadata_defaults(attrs)
352-
353337
self.metadata.version = self._normalize_version(self.metadata.version)
354338
self._finalize_requires()
339+
self._check_deprecated_metadata_fields()
355340

356341
def _validate_metadata(self):
357342
required = {"name"}
@@ -366,6 +351,16 @@ def _validate_metadata(self):
366351
msg = f"Required package metadata is missing: {missing}"
367352
raise DistutilsSetupError(msg)
368353

354+
def _check_deprecated_metadata_fields(self) -> None:
355+
for attr in self._DEPRECATED_FIELDS:
356+
if getattr(self.metadata, attr, None):
357+
anchor = f"keyword-{attr.replace('_', '-')}"
358+
SetuptoolsDeprecationWarning.emit(
359+
f"Deprecated usage of `{attr}` in setuptools configuration.",
360+
see_docs=f"references/keywords.html#{anchor}",
361+
due_date=(2027, 1, 25), # introduced in 20 Jan 2025
362+
)
363+
369364
def _set_metadata_defaults(self, attrs):
370365
"""
371366
Fill-in missing metadata fields not supported by distutils.
@@ -1016,8 +1011,9 @@ def handle_display_options(self, option_order):
10161011

10171012
def run_command(self, command) -> None:
10181013
self.set_defaults()
1019-
# Postpone defaults until all explicit configuration is considered
1020-
# (setup() args, config files, command line and plugins)
1014+
self._check_deprecated_metadata_fields()
1015+
# Postpone defaults and validations until all explicit configuration is
1016+
# considered (setup() args, config files, command line and plugins)
10211017

10221018
super().run_command(command)
10231019

0 commit comments

Comments
 (0)