summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2023-03-06 21:00:40 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2023-03-07 21:06:29 +0000
commita05e81ae0cea8ed4b5bf1f43ea82c5af75e4f6e3 (patch)
tree85c577fe65414424fab19f621b59f80249f8f51d
parent27cfcd126e05b1e5c8413aa57d06df81cebfdeb5 (diff)
downloadpython-setuptools-git-a05e81ae0cea8ed4b5bf1f43ea82c5af75e4f6e3.tar.gz
Use new warnings in setuptools/config/pyprojecttoml.py
-rw-r--r--setuptools/config/pyprojecttoml.py42
1 files changed, 20 insertions, 22 deletions
diff --git a/setuptools/config/pyprojecttoml.py b/setuptools/config/pyprojecttoml.py
index 9ce55022..c340121c 100644
--- a/setuptools/config/pyprojecttoml.py
+++ b/setuptools/config/pyprojecttoml.py
@@ -2,19 +2,23 @@
Load setuptools configuration from ``pyproject.toml`` files.
**PRIVATE MODULE**: API reserved for setuptools internal usage only.
+
+To read project metadata, consider using
+``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
+For simple scenarios, you can also try parsing the file directly
+with the help of ``tomllib`` or ``tomli``.
"""
import logging
import os
-import warnings
from contextlib import contextmanager
from functools import partial
-from typing import TYPE_CHECKING, Callable, Dict, Optional, Mapping, Set, Union
-
-from setuptools.errors import FileError, OptionError
+from typing import TYPE_CHECKING, Callable, Dict, Mapping, Optional, Set, Union
+from ..errors import FileError, OptionError
+from ..warnings import SetuptoolsWarning
from . import expand as _expand
-from ._apply_pyprojecttoml import apply as _apply
from ._apply_pyprojecttoml import _PREVIOUSLY_DEFINED, _WouldIgnoreField
+from ._apply_pyprojecttoml import apply as _apply
if TYPE_CHECKING:
from setuptools.dist import Distribution # noqa
@@ -104,8 +108,7 @@ def read_configuration(
if setuptools_table:
# TODO: Remove the following once the feature stabilizes:
- msg = "Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*."
- warnings.warn(msg, _BetaConfiguration)
+ _BetaConfiguration.emit()
# There is an overall sense in the community that making include_package_data=True
# the default would be an improvement.
@@ -166,7 +169,7 @@ def _skip_bad_config(
# It seems that the docs in cibuildtool has been inadvertently encouraging users
# to create `pyproject.toml` files that are not compliant with the standards.
# Let's be forgiving for the time being.
- warnings.warn(_InvalidFile.message(), _InvalidFile, stacklevel=2)
+ _InvalidFile.emit()
return True
return False
@@ -369,8 +372,7 @@ class _ConfigExpander:
if group in groups:
value = groups.pop(group)
if field not in self.dynamic:
- msg = _WouldIgnoreField.message(field, value)
- warnings.warn(msg, _WouldIgnoreField)
+ _WouldIgnoreField.emit(field=field, value=value)
# TODO: Don't set field when support for pyproject.toml stabilizes
# instead raise an error as specified in PEP 621
expanded[field] = value
@@ -472,13 +474,13 @@ class _EnsurePackagesDiscovered(_expand.EnsurePackagesDiscovered):
return super().__exit__(exc_type, exc_value, traceback)
-class _BetaConfiguration(UserWarning):
- """Explicitly inform users that some `pyproject.toml` configuration is *beta*"""
+class _BetaConfiguration(SetuptoolsWarning):
+ _SUMMARY = "Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*."
-class _InvalidFile(UserWarning):
- """The given `pyproject.toml` file is invalid and would be ignored.
- !!\n\n
+class _InvalidFile(SetuptoolsWarning):
+ _SUMMARY = "The given `pyproject.toml` file is invalid and would be ignored."
+ _DETAILS = """
############################
# Invalid `pyproject.toml` #
############################
@@ -488,11 +490,7 @@ class _InvalidFile(UserWarning):
if an invalid file is given.
To prevent setuptools from considering `pyproject.toml` please
- DO NOT include the `[project]` or `[tool.setuptools]` tables in your file.
- \n\n!!
+ DO NOT include both `[project]` or `[tool.setuptools]` tables in your file.
"""
-
- @classmethod
- def message(cls):
- from inspect import cleandoc
- return cleandoc(cls.__doc__)
+ _DUE_DATE = (2023, 4, 26) # warning introduced in 2022-03-26
+ _SEE_DOCS = "userguide/pyproject_config.html"