summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2023-03-06 20:58:20 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2023-03-07 21:06:29 +0000
commitb776e31badf591abab9cc7110383e830fe40ba5d (patch)
treeb3c01e750f64ad29f46d1c57c5d6e016cbb2ed63
parent80af34e07dadaa2f43a21d6337af0d2e6f8fe143 (diff)
downloadpython-setuptools-git-b776e31badf591abab9cc7110383e830fe40ba5d.tar.gz
Use new warnings in setuptools/config/_apply_pyprojecttoml.py
-rw-r--r--setuptools/config/_apply_pyprojecttoml.py38
-rw-r--r--setuptools/tests/config/test_apply_pyprojecttoml.py2
2 files changed, 18 insertions, 22 deletions
diff --git a/setuptools/config/_apply_pyprojecttoml.py b/setuptools/config/_apply_pyprojecttoml.py
index f792521c..4556019e 100644
--- a/setuptools/config/_apply_pyprojecttoml.py
+++ b/setuptools/config/_apply_pyprojecttoml.py
@@ -9,7 +9,6 @@ need to be processed before being applied.
"""
import logging
import os
-import warnings
from collections.abc import Mapping
from email.headerregistry import Address
from functools import partial, reduce
@@ -18,7 +17,7 @@ from types import MappingProxyType
from typing import (TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Tuple,
Type, Union, cast)
-from setuptools.warnings import SetuptoolsDeprecationWarning
+from ..warnings import SetuptoolsWarning, SetuptoolsDeprecationWarning
if TYPE_CHECKING:
from setuptools._importlib import metadata # noqa
@@ -81,9 +80,11 @@ def _apply_tool_table(dist: "Distribution", config: dict, filename: _Path):
norm_key = json_compatible_key(field)
if norm_key in TOOL_TABLE_DEPRECATIONS:
- suggestion = TOOL_TABLE_DEPRECATIONS[norm_key]
+ suggestion, kwargs = TOOL_TABLE_DEPRECATIONS[norm_key]
msg = f"The parameter `{norm_key}` is deprecated, {suggestion}"
- warnings.warn(msg, SetuptoolsDeprecationWarning)
+ SetuptoolsDeprecationWarning.emit(
+ "Deprecated config", msg, **kwargs # type: ignore
+ )
norm_key = TOOL_TABLE_RENAMES.get(norm_key, norm_key)
_set_config(dist, norm_key, value)
@@ -99,8 +100,7 @@ def _handle_missing_dynamic(dist: "Distribution", project_table: dict):
if not (field in project_table or field in dynamic):
value = getter(dist)
if value:
- msg = _WouldIgnoreField.message(field, value)
- warnings.warn(msg, _WouldIgnoreField)
+ _WouldIgnoreField.emit(field=field, value=value)
def json_compatible_key(key: str) -> str:
@@ -200,7 +200,7 @@ def _python_requires(dist: "Distribution", val: dict, _root_dir):
def _dependencies(dist: "Distribution", val: list, _root_dir):
if getattr(dist, "install_requires", []):
msg = "`install_requires` overwritten in `pyproject.toml` (dependencies)"
- warnings.warn(msg)
+ SetuptoolsWarning.emit(msg)
_set_config(dist, "install_requires", val)
@@ -325,7 +325,10 @@ PYPROJECT_CORRESPONDENCE: Dict[str, _Correspondence] = {
TOOL_TABLE_RENAMES = {"script_files": "scripts"}
TOOL_TABLE_DEPRECATIONS = {
- "namespace_packages": "consider using implicit namespaces instead (PEP 420)."
+ "namespace_packages": (
+ "consider using implicit namespaces instead (PEP 420).",
+ {"due_date": (2023, 10, 15)}, # warning introduced in May 2022
+ )
}
SETUPTOOLS_PATCHES = {"long_description_content_type", "project_urls",
@@ -349,12 +352,10 @@ _PREVIOUSLY_DEFINED = {
}
-class _WouldIgnoreField(UserWarning):
- """Inform users that ``pyproject.toml`` would overwrite previous metadata."""
+class _WouldIgnoreField(SetuptoolsDeprecationWarning):
+ _SUMMARY = "`{field}` defined outside of `pyproject.toml` would be ignored."
- MESSAGE = """\
- {field!r} defined outside of `pyproject.toml` would be ignored.
- !!\n\n
+ _DETAILS = """
##########################################################################
# configuration would be ignored/result in error due to `pyproject.toml` #
##########################################################################
@@ -364,7 +365,7 @@ class _WouldIgnoreField(UserWarning):
`{field} = {value!r}`
According to the spec (see the link below), however, setuptools CANNOT
- consider this value unless {field!r} is listed as `dynamic`.
+ consider this value unless `{field}` is listed as `dynamic`.
https://packaging.python.org/en/latest/specifications/declaring-project-metadata/
@@ -372,13 +373,8 @@ class _WouldIgnoreField(UserWarning):
**transitional** measure), but please note that future releases of setuptools will
follow strictly the standard.
- To prevent this warning, you can list {field!r} under `dynamic` or alternatively
+ To prevent this warning, you can list `{field}` under `dynamic` or alternatively
remove the `[project]` table from your file and rely entirely on other means of
configuration.
- \n\n!!
"""
-
- @classmethod
- def message(cls, field, value):
- from inspect import cleandoc
- return cleandoc(cls.MESSAGE.format(field=field, value=value))
+ _DUE_DATE = (2023, 10, 27) # Initially introduced in 27 May 2022
diff --git a/setuptools/tests/config/test_apply_pyprojecttoml.py b/setuptools/tests/config/test_apply_pyprojecttoml.py
index 8f76f2c9..03a974d5 100644
--- a/setuptools/tests/config/test_apply_pyprojecttoml.py
+++ b/setuptools/tests/config/test_apply_pyprojecttoml.py
@@ -15,12 +15,12 @@ import pytest
from ini2toml.api import Translator
import setuptools # noqa ensure monkey patch to metadata
-from setuptools.warnings import SetuptoolsDeprecationWarning
from setuptools.dist import Distribution
from setuptools.config import setupcfg, pyprojecttoml
from setuptools.config import expand
from setuptools.config._apply_pyprojecttoml import _WouldIgnoreField, _some_attrgetter
from setuptools.command.egg_info import write_requirements
+from setuptools.warnings import SetuptoolsDeprecationWarning
from .downloads import retrieve_file, urls_from_file